diff options
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 2 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 20 | ||||
-rw-r--r-- | slicer/slicer/parser.cpp | 14 |
3 files changed, 28 insertions, 8 deletions
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index c2e8cfe..0886ed6 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -205,6 +205,8 @@ namespace Slicer { static const Metadata metadata; static const Enumerations enumerations; + DLL_PUBLIC static const std::string & lookup(T); + DLL_PUBLIC static T lookup(const std::string &); private: T & modelPart; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 7f91508..d598bbf 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -320,6 +320,26 @@ namespace Slicer { return metadata; } + template<typename T> + T ModelPartForEnum<T>::lookup(const std::string & val) + { + auto i = enumerations.right.find(val); + if (i == enumerations.right.end()) { + throw InvalidEnumerationValue(val, typeid(T).name()); + } + return i->second; + } + + template<typename T> + const std::string & ModelPartForEnum<T>::lookup(T val) + { + auto i = enumerations.left.find(val); + if (i == enumerations.left.end()) { + throw InvalidEnumerationValue((::Ice::Int)val, typeid(T).name()); + } + return i->second; + } + // ModelPartForDictionaryElementInserter template<typename T> ModelPartForDictionaryElementInserter<T>::ModelPartForDictionaryElementInserter(T & d) : diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 6a5019b..efe53dd 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -358,18 +358,12 @@ namespace Slicer { fprintbf(cpp, "template<>\nvoid ModelPartForEnum< %s >::SetValue(ValueSourcePtr s) {\n\ std::string val;\n\ s->set(val);\n\ - auto i = enumerations.right.find(val);\n\ - if (i == enumerations.right.end()) throw InvalidEnumerationValue(val, \"%s\");\n\ - modelPart = i->second;\n\ + modelPart = lookup(val);\n\ }\n\n", - e->scoped(), e->scoped()); fprintbf(cpp, "template<>\nvoid ModelPartForEnum< %s >::GetValue(ValueTargetPtr s) {\n\ - auto i = enumerations.left.find(modelPart);\n\ - if (i == enumerations.left.end()) throw InvalidEnumerationValue((::Ice::Int)modelPart, \"%s\");\n\ - s->get(i->second);\n\ + s->get(lookup(modelPart));\n\ }\n\n", - e->scoped(), e->scoped()); auto name = metaDataValue("slicer:root:", e->getMetaData()); @@ -377,6 +371,10 @@ namespace Slicer { fprintbf(cpp, "MODELPARTFOR(%s, ModelPartForEnum);\n\n", e->scoped()); + fprintbf(cpp, "template %s ModelPartForEnum< %s >::lookup(const std::string &);\n\n", + e->scoped(), e->scoped()); + fprintbf(cpp, "template const std::string & ModelPartForEnum< %s >::lookup(%s);\n\n", + e->scoped(), e->scoped()); } void |