summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-08-31 23:27:41 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-08-31 23:27:41 +0100
commitacc9fee883103466fc1277926772e0f5dbd79c8a (patch)
tree6e6238ca3c22f874ae368eb1177f594531afd80a
parentMake lots of build stuff public const, as opposed to private non-const, cos h... (diff)
downloadslicer-acc9fee883103466fc1277926772e0f5dbd79c8a.tar.bz2
slicer-acc9fee883103466fc1277926772e0f5dbd79c8a.tar.xz
slicer-acc9fee883103466fc1277926772e0f5dbd79c8a.zip
Centralize and publicly expose string/enum lookup functions as helpersslicer-1.3.3
-rw-r--r--slicer/slicer/modelPartsTypes.h2
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h20
-rw-r--r--slicer/slicer/parser.cpp14
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