summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelPartsTypes.h20
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h26
-rw-r--r--slicer/slicer/parser.cpp14
3 files changed, 13 insertions, 47 deletions
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index 02ef8c8..545f4cb 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -115,7 +115,7 @@ namespace Slicer {
ModelPartPtr Get(T * t) const override
{
- return t ? new MP(t->*M) : NULL;
+ return t ? new MP(const_cast<typename std::remove_const<MT>::type &>(t->*M)) : NULL;
}
std::string PartName() const override
@@ -252,27 +252,13 @@ namespace Slicer {
};
template<typename T>
- class ModelPartForDictionaryElement : public ModelPartForComplex<ModelPartForDictionaryElement<T> > {
- public:
- ModelPartForDictionaryElement(typename T::key_type * k, typename T::mapped_type * v);
-
- ModelPartForDictionaryElement<T> * GetModel() override;
-
- virtual bool HasValue() const override;
-
- typename T::key_type * key;
- typename T::mapped_type * value;
- };
-
- template<typename T>
- class ModelPartForDictionaryElementInserter : public ModelPartForDictionaryElement<T> {
+ class ModelPartForDictionaryElementInserter : public ModelPartForStruct<typename T::value_type> {
public:
ModelPartForDictionaryElementInserter(T & d);
virtual void Complete() override;
- mutable typename T::key_type key;
- mutable typename T::mapped_type value;
+ typename T::value_type value;
private:
T & dictionary;
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index 2f34fa1..71b6608 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -365,30 +365,10 @@ namespace Slicer {
return metadata;
}
- // ModelPartForDictionaryElement
- template<typename T>
- ModelPartForDictionaryElement<T>::ModelPartForDictionaryElement(typename T::key_type * k, typename T::mapped_type * v) :
- key(k),
- value(v)
- {
- }
-
- template<typename T>
- ModelPartForDictionaryElement<T> * ModelPartForDictionaryElement<T>::GetModel()
- {
- return this;
- }
-
- template<typename T>
- bool ModelPartForDictionaryElement<T>::HasValue() const
- {
- return true;
- }
-
// ModelPartForDictionaryElementInserter
template<typename T>
ModelPartForDictionaryElementInserter<T>::ModelPartForDictionaryElementInserter(T & d) :
- ModelPartForDictionaryElement<T>(&key, &value),
+ ModelPartForStruct<typename T::value_type>(value),
dictionary(d)
{
}
@@ -396,7 +376,7 @@ namespace Slicer {
template<typename T>
void ModelPartForDictionaryElementInserter<T>::Complete()
{
- dictionary.insert(typename T::value_type(key, value));
+ dictionary.insert(value);
}
// ModelPartForDictionary
@@ -416,7 +396,7 @@ namespace Slicer {
void ModelPartForDictionary<T>::OnEachChild(const ChildHandler & ch)
{
for (auto & pair : dictionary) {
- ch(pairName, new ModelPartForDictionaryElement<T>(const_cast<typename T::key_type *>(&pair.first), &pair.second), NULL);
+ ch(pairName, new ModelPartForStruct<typename T::value_type>(pair), NULL);
}
}
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp
index 813d134..7da9b71 100644
--- a/slicer/slicer/parser.cpp
+++ b/slicer/slicer/parser.cpp
@@ -415,15 +415,15 @@ namespace Slicer {
iname ? *iname : "element");
fprintbf(cpp, "template<>\n");
- fprintbf(cpp, "ModelPartForComplex< ModelPartForDictionaryElement< %s > >::Hooks ",
+ fprintbf(cpp, "ModelPartForComplex< %s::value_type >::Hooks ",
d->scoped());
- fprintbf(cpp, "ModelPartForComplex< ModelPartForDictionaryElement< %s > >::hooks {\n",
+ fprintbf(cpp, "ModelPartForComplex< %s::value_type >::hooks {\n",
d->scoped());
auto kname = metaDataValue("slicer:key:", d->getMetaData());
auto vname = metaDataValue("slicer:value:", d->getMetaData());
fprintbf(cpp, "\t\t");
auto ktype = d->keyType();
- fprintbf(cpp, "new ModelPartForDictionaryElement< %s >::Hook< %s*, ModelPartForDictionaryElement< %s >, &ModelPartForDictionaryElement< %s >::key, ",
+ fprintbf(cpp, "new ModelPartForComplex< %s::value_type >::Hook< const %s, %s::value_type, &%s::value_type::first, ",
d->scoped(),
Slice::typeToString(ktype),
d->scoped(),
@@ -433,7 +433,7 @@ namespace Slicer {
Slice::typeToString(ktype),
kname ? *kname : "key");
auto vtype = d->valueType();
- fprintbf(cpp, "new ModelPartForDictionaryElement< %s >::Hook< %s*, ModelPartForDictionaryElement< %s >, &ModelPartForDictionaryElement< %s >::value, ",
+ fprintbf(cpp, "new ModelPartForComplex< %s::value_type >::Hook< %s, %s::value_type, &%s::value_type::second, ",
d->scoped(),
Slice::typeToString(vtype),
d->scoped(),
@@ -452,16 +452,16 @@ namespace Slicer {
d->scoped());
copyMetadata(d->getMetaData());
- fprintbf(cpp, "template<>\nMetadata ModelPartForComplex<ModelPartForDictionaryElement< %s > >::metadata ",
+ fprintbf(cpp, "template<>\nMetadata ModelPartForComplex<%s::value_type>::metadata ",
d->scoped());
copyMetadata(d->getMetaData());
- fprintbf(cpp, "template<>\ntemplate<>\nMetadata\nModelPartForDictionaryElement< %s >::HookMetadata< %s*, ModelPartForDictionaryElement< %s >, &ModelPartForDictionaryElement< %s >::key >::metadata { };\n\n",
+ fprintbf(cpp, "template<>\ntemplate<>\nMetadata\nModelPartForComplex< %s::value_type >::HookMetadata< const %s, %s::value_type, &%s::value_type::first >::metadata { };\n\n",
d->scoped(),
Slice::typeToString(ktype),
d->scoped(),
d->scoped());
- fprintbf(cpp, "template<>\ntemplate<>\nMetadata\nModelPartForDictionaryElement< %s >::HookMetadata< %s*, ModelPartForDictionaryElement< %s >, &ModelPartForDictionaryElement< %s >::value >::metadata { };\n\n",
+ fprintbf(cpp, "template<>\ntemplate<>\nMetadata\nModelPartForComplex< %s::value_type >::HookMetadata< %s, %s::value_type, &%s::value_type::second >::metadata { };\n\n",
d->scoped(),
Slice::typeToString(vtype),
d->scoped(),