summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-01-26 01:16:21 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-01-26 01:16:21 +0000
commitf92d61814158825e7cbf71eefaac6d79373167fb (patch)
tree221893de1156d59ca86149c7878bb5c88ef5e0f1
parentIgnore Vim swap files (diff)
downloadslicer-f92d61814158825e7cbf71eefaac6d79373167fb.tar.bz2
slicer-f92d61814158825e7cbf71eefaac6d79373167fb.tar.xz
slicer-f92d61814158825e7cbf71eefaac6d79373167fb.zip
Explicitly implement the auto modelpart deduction templates
-rw-r--r--slicer/slicer/modelParts.h13
-rw-r--r--slicer/slicer/parser.cpp15
2 files changed, 15 insertions, 13 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index a28de0c..5b1e634 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -664,19 +664,6 @@ namespace Slicer {
static std::string pairName;
static Metadata metadata;
};
-
- // Templates for automatically determining a model part implementation
-#define templateMODELPARTFOR(Type, ModelPart) \
- template <class T> ModelPartPtr ModelPartFor(Type & t) { return new ModelPart< Type >(t); } \
- template <class T> ModelPartPtr ModelPartFor(Type * t) { return new ModelPart< Type >(t); }
- templateMODELPARTFOR(IceInternal::Handle<T>, ModelPartForClass);
- templateMODELPARTFOR(std::vector<T>, ModelPartForSequence);
- templateMODELPARTFOR(std::list<T>, ModelPartForSequence);
- template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> & t) { return new ModelPartForDictionary< std::map<K, V> >(t); } \
- template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> * t) { return new ModelPartForDictionary< std::map<K, V> >(t); } \
- // Everything else is a struct?
- templateMODELPARTFOR(T, ModelPartForStruct);
-#undef templateMODELPARTFOR
}
#endif
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp
index d2d05a2..a4ee2dd 100644
--- a/slicer/slicer/parser.cpp
+++ b/slicer/slicer/parser.cpp
@@ -89,6 +89,9 @@ namespace Slicer {
fprintf(cpp, "// Begin Slicer code\n\n");
fprintf(cpp, "#include <%s>\n\n", fs::change_extension(topLevelFile.filename(), ".h").string().c_str());
fprintf(cpp, "#include <slicer/modelParts.h>\n\n");
+ fprintf(cpp, "#define templateMODELPARTFOR(Type, ModelPart) \\\n");
+ fprintf(cpp, "template <> ModelPartPtr ModelPartFor(Type & t) { return new ModelPart< Type >(t); } \\\n");
+ fprintf(cpp, "template <> ModelPartPtr ModelPartFor(Type * t) { return new ModelPart< Type >(t); }\n\n");
fprintf(cpp, "namespace Slicer {\n");
return true;
}
@@ -188,6 +191,9 @@ namespace Slicer {
c->scoped().c_str());
copyMetadata(c->getMetaData());
+ fprintf(cpp, "templateMODELPARTFOR(::IceInternal::Handle< %s >, ModelPartForClass);\n\n",
+ c->scoped().c_str());
+
classNo += 1;
return true;
@@ -212,6 +218,9 @@ namespace Slicer {
c->scoped().c_str());
copyMetadata(c->getMetaData());
+ fprintf(cpp, "templateMODELPARTFOR(%s, ModelPartForStruct);\n\n",
+ c->scoped().c_str());
+
return true;
}
@@ -325,6 +334,9 @@ namespace Slicer {
fprintf(cpp, "template<>\nMetadata ModelPartForSequence< %s >::metadata ",
s->scoped().c_str());
copyMetadata(s->getMetaData());
+
+ fprintf(cpp, "templateMODELPARTFOR(%s, ModelPartForSequence);\n\n",
+ s->scoped().c_str());
}
void
@@ -392,6 +404,9 @@ namespace Slicer {
Slice::typeToString(vtype).c_str(),
d->scoped().c_str(),
d->scoped().c_str());
+
+ fprintf(cpp, "templateMODELPARTFOR(%s, ModelPartForDictionary);\n\n",
+ d->scoped().c_str());
}
void