diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-01-06 21:47:44 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-01-06 21:47:44 +0000 |
commit | 7f0c417d30bee53d238b06a7d8a048197f40a8d0 (patch) | |
tree | 1321d5039e00c616105da9a76d56a11f3c34372e | |
parent | Fix JSON serializer's root iterate for sequences (diff) | |
download | slicer-7f0c417d30bee53d238b06a7d8a048197f40a8d0.tar.bz2 slicer-7f0c417d30bee53d238b06a7d8a048197f40a8d0.tar.xz slicer-7f0c417d30bee53d238b06a7d8a048197f40a8d0.zip |
Write out rootName for sequences
-rw-r--r-- | slicer/slicer/parser.cpp | 17 | ||||
-rw-r--r-- | slicer/slicer/parser.h | 1 |
2 files changed, 14 insertions, 4 deletions
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index b8f3f89..7cd45f1 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -123,6 +123,15 @@ namespace Slicer { return true; } + + void + Slicer::defineRootName(const std::string & type, const std::string & name) const + { + fprintf(cpp, "template<>\n"); + fprintf(cpp, "std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n", + type.c_str(), name.c_str()); + } + bool Slicer::visitClassDefStart(const Slice::ClassDefPtr & c) { @@ -143,11 +152,8 @@ namespace Slicer { typeToString(decl).c_str(), typeId ? typeId->c_str() : "slicer-typeid"); - fprintf(cpp, "template<>\n"); auto name = metaDataValue("slicer:root:", c->getMetaData()); - fprintf(cpp, "std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n", - typeToString(decl).c_str(), - name ? name->c_str() : c->name().c_str()); + defineRootName(typeToString(decl), name ? *name : c->name()); auto typeName = metaDataValue("slicer:typename:", c->getMetaData()); fprintf(cpp, "static void registerClass_%u() __attribute__ ((constructor(210)));\n", classNo); @@ -314,6 +320,9 @@ namespace Slicer { s->scoped().c_str(), ename ? ename->c_str() : "element"); + auto name = metaDataValue("slicer:root:", s->getMetaData()); + defineRootName(s->scoped(), name ? *name : s->name()); + fprintf(cpp, "template<>\nMetadata ModelPartForSequence< %s >::metadata ", s->scoped().c_str()); copyMetadata(s->getMetaData()); diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h index 7965b4b..6253cf5 100644 --- a/slicer/slicer/parser.h +++ b/slicer/slicer/parser.h @@ -47,6 +47,7 @@ namespace Slicer { void visitComplexDataMembers(Slice::ConstructedPtr t, const Slice::DataMemberList &) const; void defineConversions(Slice::DataMemberPtr dm) const; + void defineRootName(const std::string & type, const std::string & name) const; void copyMetadata(const std::list<std::string> & metadata) const; static Conversions getAllConversions(Slice::DataMemberPtr dm); |