From 95fb813f23230fa16fa93aa1a6258222444f11b5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Feb 2016 02:06:45 +0000 Subject: Remove the need for ModelPartForDictionaryElement, ModelPartForStruct works just as well --- slicer/slicer/modelPartsTypes.h | 20 +++----------------- slicer/slicer/modelPartsTypes.impl.h | 26 +++----------------------- slicer/slicer/parser.cpp | 14 +++++++------- 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::type &>(t->*M)) : NULL; } std::string PartName() const override @@ -252,27 +252,13 @@ namespace Slicer { }; template - class ModelPartForDictionaryElement : public ModelPartForComplex > { - public: - ModelPartForDictionaryElement(typename T::key_type * k, typename T::mapped_type * v); - - ModelPartForDictionaryElement * GetModel() override; - - virtual bool HasValue() const override; - - typename T::key_type * key; - typename T::mapped_type * value; - }; - - template - class ModelPartForDictionaryElementInserter : public ModelPartForDictionaryElement { + class ModelPartForDictionaryElementInserter : public ModelPartForStruct { 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 - ModelPartForDictionaryElement::ModelPartForDictionaryElement(typename T::key_type * k, typename T::mapped_type * v) : - key(k), - value(v) - { - } - - template - ModelPartForDictionaryElement * ModelPartForDictionaryElement::GetModel() - { - return this; - } - - template - bool ModelPartForDictionaryElement::HasValue() const - { - return true; - } - // ModelPartForDictionaryElementInserter template ModelPartForDictionaryElementInserter::ModelPartForDictionaryElementInserter(T & d) : - ModelPartForDictionaryElement(&key, &value), + ModelPartForStruct(value), dictionary(d) { } @@ -396,7 +376,7 @@ namespace Slicer { template void ModelPartForDictionaryElementInserter::Complete() { - dictionary.insert(typename T::value_type(key, value)); + dictionary.insert(value); } // ModelPartForDictionary @@ -416,7 +396,7 @@ namespace Slicer { void ModelPartForDictionary::OnEachChild(const ChildHandler & ch) { for (auto & pair : dictionary) { - ch(pairName, new ModelPartForDictionaryElement(const_cast(&pair.first), &pair.second), NULL); + ch(pairName, new ModelPartForStruct(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 >::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(), -- cgit v1.2.3