diff options
-rw-r--r-- | slicer/slicer/modelParts.h | 2 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 5 | ||||
-rw-r--r-- | slicer/slicer/parser.cpp | 32 | ||||
-rw-r--r-- | slicer/slicer/parser.h | 1 | ||||
-rw-r--r-- | slicer/slicer/slicer.cpp | 2 |
5 files changed, 25 insertions, 17 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 6f9338d..6e87fe6 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -106,6 +106,8 @@ namespace Slicer { typedef boost::bimap<std::string, std::string> ClassNameMap; DLL_PUBLIC ClassNameMap * & classNameMap(); typedef std::list<std::string> Metadata; + DLL_PUBLIC extern const Metadata emptyMetadata; + enum ModelPartType { mpt_Null, mpt_Simple, diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index dad6215..b024d64 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -89,6 +89,7 @@ namespace Slicer { class HookBase : public HookCommon { public: virtual ModelPartPtr Get(T * t) const = 0; + virtual const Metadata & GetMetadata() const override { return emptyMetadata; } }; typedef IceUtil::Handle<HookBase> HookPtr; @@ -101,8 +102,8 @@ namespace Slicer { static Metadata metadata; }; - template <typename MT, typename CT, MT CT::*M, typename MP> - class Hook : public HookMetadata<MT, CT, M> { + template <typename MT, typename CT, MT CT::*M, typename MP, typename Base = HookMetadata<MT, CT, M>> + class Hook : public Base { public: Hook(const std::string & n) : name(n) diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 7da9b71..787f9e7 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -278,12 +278,18 @@ namespace Slicer { if (dm->optional()) { fprintbf(cpp, " > "); } + if (!hasMetadata(dm->getMetaData())) { + fprintbf(cpp, ", HookBase"); + } fprintbf(cpp, " >(\"%s\"),\n", name ? *name : dm->name()); } fprintbf(cpp, "\t};\n\n"); for (const auto & dm : dataMembers) { + if (!hasMetadata(dm->getMetaData())) { + continue; + } auto c = Slice::ContainedPtr::dynamicCast(dm->container()); auto t = Slice::TypePtr::dynamicCast(dm->container()); if (!t) { @@ -429,7 +435,7 @@ namespace Slicer { d->scoped(), d->scoped()); createNewModelPartPtrFor(ktype); - fprintbf(cpp, "< %s > >(\"%s\"),\n\t\t", + fprintbf(cpp, "< %s >, HookBase >(\"%s\"),\n\t\t", Slice::typeToString(ktype), kname ? *kname : "key"); auto vtype = d->valueType(); @@ -439,7 +445,7 @@ namespace Slicer { d->scoped(), d->scoped()); createNewModelPartPtrFor(vtype); - fprintbf(cpp, "< %s > >(\"%s\"),\n", + fprintbf(cpp, "< %s >, HookBase >(\"%s\"),\n", Slice::typeToString(vtype), vname ? *vname : "value"); fprintbf(cpp, "\t};\n"); @@ -456,17 +462,6 @@ namespace Slicer { d->scoped()); copyMetadata(d->getMetaData()); - 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\nModelPartForComplex< %s::value_type >::HookMetadata< %s, %s::value_type, &%s::value_type::second >::metadata { };\n\n", - d->scoped(), - Slice::typeToString(vtype), - d->scoped(), - d->scoped()); - fprintbf(cpp, "MODELPARTFOR(%s, ModelPartForDictionary);\n\n", d->scoped()); } @@ -502,6 +497,17 @@ namespace Slicer { } } + bool + Slicer::hasMetadata(const std::list<std::string> & metadata) const + { + for (const auto & md : metadata) { + if (boost::algorithm::starts_with(md, "slicer:")) { + return true; + } + } + return false; + } + void Slicer::copyMetadata(const std::list<std::string> & metadata) const { diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h index 322476f..f6a7809 100644 --- a/slicer/slicer/parser.h +++ b/slicer/slicer/parser.h @@ -59,6 +59,7 @@ namespace Slicer { void defineConversions(Slice::DataMemberPtr dm) const; void defineRootName(const std::string & type, const std::string & name) const; + bool hasMetadata(const std::list<std::string> & metadata) const; void copyMetadata(const std::list<std::string> & metadata) const; static Conversions getAllConversions(Slice::DataMemberPtr dm); static Conversions getConversions(const std::list<std::string> & metadata); diff --git a/slicer/slicer/slicer.cpp b/slicer/slicer/slicer.cpp index c2b6065..c895a38 100644 --- a/slicer/slicer/slicer.cpp +++ b/slicer/slicer/slicer.cpp @@ -1,8 +1,6 @@ #include "slicer.h" namespace Slicer { - const Metadata emptyMetadata; - Slicer::MemberChildRef::MemberChildRef(Slicer::ModelPartPtr mp, const Slicer::Metadata & md) : mpp(mp), mdr(md) |