From cfd504a6a650de35d93ad9400e9da23e506422ce Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Feb 2016 00:06:01 +0000 Subject: Don't generate so much empty metadata --- slicer/slicer/modelParts.h | 2 ++ slicer/slicer/modelPartsTypes.h | 5 +++-- slicer/slicer/parser.cpp | 32 +++++++++++++++++++------------- slicer/slicer/parser.h | 1 + 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 ClassNameMap; DLL_PUBLIC ClassNameMap * & classNameMap(); typedef std::list 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 HookPtr; @@ -101,8 +102,8 @@ namespace Slicer { static Metadata metadata; }; - template - class Hook : public HookMetadata { + template > + 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 & metadata) const + { + for (const auto & md : metadata) { + if (boost::algorithm::starts_with(md, "slicer:")) { + return true; + } + } + return false; + } + void Slicer::copyMetadata(const std::list & 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 & metadata) const; void copyMetadata(const std::list & metadata) const; static Conversions getAllConversions(Slice::DataMemberPtr dm); static Conversions getConversions(const std::list & 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) -- cgit v1.2.3