diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-17 23:19:08 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-17 23:19:08 +0100 |
commit | d305631ad21c584e87d1cb2d9dbb7b0d2b851d92 (patch) | |
tree | 1320327012fbc711e38a03307b70338f28fe6bc4 | |
parent | Remove unnecessary subclassing of ChildRef (diff) | |
download | slicer-d305631ad21c584e87d1cb2d9dbb7b0d2b851d92.tar.bz2 slicer-d305631ad21c584e87d1cb2d9dbb7b0d2b851d92.tar.xz slicer-d305631ad21c584e87d1cb2d9dbb7b0d2b851d92.zip |
Remove need to create ChildRefs on heap
-rw-r--r-- | slicer/db/sqlSelectDeserializer.cpp | 2 | ||||
-rw-r--r-- | slicer/slicer/modelParts.cpp | 4 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 14 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.cpp | 30 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 32 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 24 | ||||
-rw-r--r-- | slicer/slicer/slicer.cpp | 17 | ||||
-rw-r--r-- | slicer/tool/parser.cpp | 2 | ||||
-rw-r--r-- | slicer/xml/serializer.cpp | 12 | ||||
-rw-r--r-- | slicer/xml/serializer.h | 2 |
10 files changed, 75 insertions, 64 deletions
diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp index a2d5619..366c4f7 100644 --- a/slicer/db/sqlSelectDeserializer.cpp +++ b/slicer/db/sqlSelectDeserializer.cpp @@ -100,7 +100,7 @@ namespace Slicer { return boost::iequals(c.name, h->name); }); if (fmpr) { - auto fmp = fmpr->Child(); + auto fmp = fmpr.Child(); fmp->Create(); fmp->SetValue(SqlSource(c)); fmp->Complete(); diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index cc0ee13..e227c07 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -103,14 +103,14 @@ namespace Slicer { ModelPart::GetAnonChild(const HookFilter & flt) { auto ref = GetAnonChildRef(flt); - return ref ? ref->Child() : ModelPartPtr(NULL); + return ref ? ref.Child() : ModelPartPtr(NULL); } ModelPartPtr ModelPart::GetChild(const std::string & memberName, const HookFilter & flt) { auto ref = GetChildRef(memberName, flt); - return ref ? ref->Child() : ModelPartPtr(NULL); + return ref ? ref.Child() : ModelPartPtr(NULL); } bool diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index d65ec7c..e659a54 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -107,21 +107,21 @@ namespace Slicer { tcr_Value, }; - class DLL_PUBLIC ChildRef : virtual public IceUtil::Shared { + class DLL_PUBLIC ChildRef { public: + ChildRef(); ChildRef(ModelPartPtr); ChildRef(ModelPartPtr, const Metadata &); ModelPartPtr Child() const; const Metadata & ChildMetaData() const; + operator bool() const; private: ModelPartPtr mpp; const Metadata & mdr; }; - typedef IceUtil::Handle<ChildRef> ChildRefPtr; - class DLL_PUBLIC HookCommon : virtual public IceUtil::Shared { public: HookCommon(const std::string &); @@ -149,8 +149,8 @@ namespace Slicer { virtual void OnEachChild(const ChildHandler &) = 0; ModelPartPtr GetAnonChild(const HookFilter & = HookFilter()); ModelPartPtr GetChild(const std::string & memberName, const HookFilter & = HookFilter()); - virtual ChildRefPtr GetAnonChildRef(const HookFilter & = HookFilter()) = 0; - virtual ChildRefPtr GetChildRef(const std::string & memberName, const HookFilter & = HookFilter()) = 0; + virtual ChildRef GetAnonChildRef(const HookFilter & = HookFilter()) = 0; + virtual ChildRef GetChildRef(const std::string & memberName, const HookFilter & = HookFilter()) = 0; virtual ModelPartPtr GetSubclassModelPart(const std::string &); virtual TypeId GetTypeId() const; virtual IceUtil::Optional<std::string> GetTypeIdProperty() const; @@ -181,8 +181,8 @@ namespace Slicer { ModelPartForRootBase(ModelPartPtr mp); virtual const std::string & GetRootName() const = 0; - virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override; - virtual ChildRefPtr GetChildRef(const std::string & name, const HookFilter &) override; + virtual ChildRef GetAnonChildRef(const HookFilter &) override; + virtual ChildRef GetChildRef(const std::string & name, const HookFilter &) override; virtual void OnEachChild(const ChildHandler & ch) override; virtual ModelPartType GetType() const override; virtual bool IsOptional() const override; diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index 1bf7939..5bf7f50 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -34,14 +34,14 @@ namespace Slicer { { } - ChildRefPtr + ChildRef ModelPartForRootBase::GetAnonChildRef(const HookFilter &) { mp->Create(); - return new ChildRef(mp); + return ChildRef(mp); } - ChildRefPtr + ChildRef ModelPartForRootBase::GetChildRef(const std::string & name, const HookFilter & hf) { if (name != GetRootName()) { @@ -74,15 +74,15 @@ namespace Slicer { } void ModelPartForSimpleBase::OnEachChild(const ChildHandler &) { } - ChildRefPtr ModelPartForSimpleBase::GetAnonChildRef(const HookFilter &) { return NULL; } - ChildRefPtr ModelPartForSimpleBase::GetChildRef(const std::string &, const HookFilter &) { return NULL; } + ChildRef ModelPartForSimpleBase::GetAnonChildRef(const HookFilter &) { return ChildRef(); } + ChildRef ModelPartForSimpleBase::GetChildRef(const std::string &, const HookFilter &) { return ChildRef(); } bool ModelPartForSimpleBase::HasValue() const { return true; } ModelPartType ModelPartForSimpleBase::GetType() const { return type; } const ModelPartType ModelPartForSimpleBase::type = mpt_Simple; void ModelPartForConvertedBase::OnEachChild(const ChildHandler &) { } - ChildRefPtr ModelPartForConvertedBase::GetAnonChildRef(const HookFilter &) { return NULL; } - ChildRefPtr ModelPartForConvertedBase::GetChildRef(const std::string &, const HookFilter &) { return NULL; } + ChildRef ModelPartForConvertedBase::GetAnonChildRef(const HookFilter &) { return ChildRef(); } + ChildRef ModelPartForConvertedBase::GetChildRef(const std::string &, const HookFilter &) { return ChildRef(); } bool ModelPartForConvertedBase::HasValue() const { return true; } ModelPartType ModelPartForConvertedBase::GetType() const { return type; } const ModelPartType ModelPartForConvertedBase::type = mpt_Simple; @@ -136,20 +136,20 @@ namespace Slicer { } } - ChildRefPtr ModelPartForOptionalBase::GetAnonChildRef(const HookFilter & flt) + ChildRef ModelPartForOptionalBase::GetAnonChildRef(const HookFilter & flt) { if (this->hasModel()) { return modelPart->GetAnonChildRef(flt); } - return NULL; + return ChildRef(); } - ChildRefPtr ModelPartForOptionalBase::GetChildRef(const std::string & name, const HookFilter & flt) + ChildRef ModelPartForOptionalBase::GetChildRef(const std::string & name, const HookFilter & flt) { if (this->hasModel()) { return modelPart->GetChildRef(name, flt); } - return NULL; + return ChildRef(); } void ModelPartForOptionalBase::SetValue(ValueSource && s) @@ -175,8 +175,8 @@ namespace Slicer { } void ModelPartForEnumBase::OnEachChild(const ChildHandler &) { } - ChildRefPtr ModelPartForEnumBase::GetAnonChildRef(const HookFilter &) { return NULL; } - ChildRefPtr ModelPartForEnumBase::GetChildRef(const std::string &, const HookFilter &) { return NULL; } + ChildRef ModelPartForEnumBase::GetAnonChildRef(const HookFilter &) { return ChildRef(); } + ChildRef ModelPartForEnumBase::GetChildRef(const std::string &, const HookFilter &) { return ChildRef(); } bool ModelPartForEnumBase::HasValue() const { return true; } ModelPartType ModelPartForEnumBase::GetType() const { return type; } const ModelPartType ModelPartForEnumBase::type = mpt_Simple; @@ -190,8 +190,8 @@ namespace Slicer { const ModelPartType ModelPartForDictionaryBase::type = mpt_Dictionary; // Streams - ChildRefPtr ModelPartForStreamBase::GetAnonChildRef(const Slicer::HookFilter &) { throw InvalidStreamOperation(__FUNCTION__); } - ChildRefPtr ModelPartForStreamBase::GetChildRef(const std::string &, const Slicer::HookFilter &) { throw InvalidStreamOperation(__FUNCTION__); } + ChildRef ModelPartForStreamBase::GetAnonChildRef(const Slicer::HookFilter &) { throw InvalidStreamOperation(__FUNCTION__); } + ChildRef ModelPartForStreamBase::GetChildRef(const std::string &, const Slicer::HookFilter &) { throw InvalidStreamOperation(__FUNCTION__); } ModelPartType ModelPartForStreamBase::GetType() const { return mpt_Sequence; } bool ModelPartForStreamBase::HasValue() const { return true; } // Stream Roots diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 7392bbe..a1c4409 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -29,8 +29,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForSimpleBase : public ModelPart { public: virtual void OnEachChild(const ChildHandler &) override; - virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override; - virtual ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override; + virtual ChildRef GetAnonChildRef(const HookFilter &) override; + virtual ChildRef GetChildRef(const std::string &, const HookFilter &) override; virtual bool HasValue() const override; virtual ModelPartType GetType() const override; static const ModelPartType type; @@ -50,8 +50,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForConvertedBase : public ModelPart { public: virtual void OnEachChild(const ChildHandler &) override; - virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override; - virtual ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override; + virtual ChildRef GetAnonChildRef(const HookFilter &) override; + virtual ChildRef GetChildRef(const std::string &, const HookFilter &) override; virtual bool HasValue() const override; virtual ModelPartType GetType() const override; static const ModelPartType type; @@ -94,8 +94,8 @@ namespace Slicer { public: virtual void OnEachChild(const ChildHandler & ch) override; virtual void Complete() override; - virtual ChildRefPtr GetAnonChildRef(const HookFilter & flt) override; - virtual ChildRefPtr GetChildRef(const std::string & name, const HookFilter & flt) override; + virtual ChildRef GetAnonChildRef(const HookFilter & flt) override; + virtual ChildRef GetChildRef(const std::string & name, const HookFilter & flt) override; virtual void SetValue(ValueSource && s) override; virtual bool HasValue() const override; virtual bool IsOptional() const override; @@ -167,8 +167,8 @@ namespace Slicer { virtual void OnEachChild(const ChildHandler & ch) override; - virtual ChildRefPtr GetAnonChildRef(const HookFilter & flt) override; - ChildRefPtr GetChildRef(const std::string & name, const HookFilter & flt) override; + virtual ChildRef GetAnonChildRef(const HookFilter & flt) override; + ChildRef GetChildRef(const std::string & name, const HookFilter & flt) override; virtual const Metadata & GetMetadata() const override; @@ -229,8 +229,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForEnumBase : public ModelPart { public: virtual void OnEachChild(const ChildHandler &) override; - ChildRefPtr GetAnonChildRef(const HookFilter &) override; - ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override; + ChildRef GetAnonChildRef(const HookFilter &) override; + ChildRef GetChildRef(const std::string &, const HookFilter &) override; virtual bool HasValue() const override; virtual ModelPartType GetType() const override; static const ModelPartType type; @@ -272,9 +272,9 @@ namespace Slicer { virtual void OnEachChild(const ChildHandler & ch) override; - ChildRefPtr GetAnonChildRef(const HookFilter &) override; + ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override; + ChildRef GetChildRef(const std::string &, const HookFilter &) override; virtual const Metadata & GetMetadata() const override; @@ -316,9 +316,9 @@ namespace Slicer { virtual void OnEachChild(const ChildHandler & ch) override; - ChildRefPtr GetAnonChildRef(const HookFilter &) override; + ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRefPtr GetChildRef(const std::string & name, const HookFilter &) override; + ChildRef GetChildRef(const std::string & name, const HookFilter &) override; virtual const Metadata & GetMetadata() const override; @@ -341,8 +341,8 @@ namespace Slicer { public: virtual ModelPartType GetType() const override; virtual bool HasValue() const override; - virtual ChildRefPtr GetAnonChildRef(const HookFilter &) override; - virtual ChildRefPtr GetChildRef(const std::string &, const HookFilter &) override; + virtual ChildRef GetAnonChildRef(const HookFilter &) override; + virtual ChildRef GetChildRef(const std::string &, const HookFilter &) override; virtual ModelPartPtr GetContainedModelPart() override = 0; virtual void OnEachChild(const ChildHandler & ch) override = 0; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index fc8718e..282418c 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -335,25 +335,25 @@ namespace Slicer { } template<typename T> - ChildRefPtr ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt) + ChildRef ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt) { for (const auto & h : hooks) { if (h->filter(flt)) { - return new ChildRef(h->Get(GetModel()), h->GetMetadata()); + return ChildRef(h->Get(GetModel()), h->GetMetadata()); } } - return NULL; + return ChildRef(); } template<typename T> - ChildRefPtr ModelPartForComplex<T>::GetChildRef(const std::string & name, const HookFilter & flt) + ChildRef ModelPartForComplex<T>::GetChildRef(const std::string & name, const HookFilter & flt) { for (const auto & h : hooks) { if (h->filter(flt, name)) { - return new ChildRef(h->Get(GetModel()), h->GetMetadata()); + return ChildRef(h->Get(GetModel()), h->GetMetadata()); } } - return NULL; + return ChildRef(); } template<typename T> @@ -579,11 +579,11 @@ namespace Slicer { } template<typename T> - ChildRefPtr ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &) + ChildRef ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &) { BOOST_ASSERT(this->Model); this->Model->push_back(typename element_type::value_type()); - return new ChildRef(ModelPart::CreateFor(this->Model->back())); + return ChildRef(ModelPart::CreateFor(this->Model->back())); } template<typename T> @@ -635,20 +635,20 @@ namespace Slicer { } template<typename T> - ChildRefPtr ModelPartForDictionary<T>::GetAnonChildRef(const HookFilter &) + ChildRef ModelPartForDictionary<T>::GetAnonChildRef(const HookFilter &) { BOOST_ASSERT(this->Model); - return new ChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model)); + return ChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model)); } template<typename T> - ChildRefPtr ModelPartForDictionary<T>::GetChildRef(const std::string & name, const HookFilter &) + ChildRef ModelPartForDictionary<T>::GetChildRef(const std::string & name, const HookFilter &) { BOOST_ASSERT(this->Model); if (name != pairName) { throw IncorrectElementName(name); } - return new ChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model)); + return ChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model)); } template<typename T> diff --git a/slicer/slicer/slicer.cpp b/slicer/slicer/slicer.cpp index e55a8ab..e132281 100644 --- a/slicer/slicer/slicer.cpp +++ b/slicer/slicer/slicer.cpp @@ -3,9 +3,9 @@ #include <compileTimeFormatter.h> namespace Slicer { - Slicer::ChildRef::ChildRef(Slicer::ModelPartPtr mp, const Slicer::Metadata & md) : - mpp(mp), - mdr(md) + Slicer::ChildRef::ChildRef() : + mpp(), + mdr(emptyMetadata) { } @@ -15,12 +15,23 @@ namespace Slicer { { } + Slicer::ChildRef::ChildRef(Slicer::ModelPartPtr mp, const Slicer::Metadata & md) : + mpp(mp), + mdr(md) + { + } + ModelPartPtr Slicer::ChildRef::Child() const { return mpp; } + Slicer::ChildRef::operator bool() const + { + return mpp; + } + const Metadata & Slicer::ChildRef::ChildMetaData() const { diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 2e27ca1..49834c0 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -325,7 +325,7 @@ namespace Slicer { fprintbf(cpp, "// Sequence %s\n", s->name()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); - fprintbf(cpp, "ChildRefPtr ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt)\n{\n", + fprintbf(cpp, "ChildRef ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt)\n{\n", s->scoped()); auto iname = metaDataValue("slicer:item:", s->getMetaData()); if (iname) { diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index 66e8b71..978c489 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -207,7 +207,7 @@ namespace Slicer { auto value = emp->GetChildRef(valueName); key->SetValue(XmlValueSource(element->get_name())); key->Complete(); - DocumentTreeIterateElement(element, value->Child(), value); + DocumentTreeIterateElement(element, value.Child(), value); emp->Complete(); } node = node->get_next_sibling(); @@ -215,7 +215,7 @@ namespace Slicer { } void - XmlDeserializer::DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr smp, ChildRefPtr smpr) + XmlDeserializer::DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr smp, const ChildRef & smpr) { if (auto typeIdPropName = smp->GetTypeIdProperty()) { if (auto typeAttr = element->get_attribute(*typeIdPropName)) { @@ -223,13 +223,13 @@ namespace Slicer { } } smp->Create(); - if (metaDataFlagSet(smpr->ChildMetaData(), md_attributes)) { + if (metaDataFlagSet(smpr.ChildMetaData(), md_attributes)) { auto attrs(element->get_attributes()); if (!attrs.empty()) { DocumentTreeIterateDictAttrs(attrs, smp); } } - else if (metaDataFlagSet(smpr->ChildMetaData(), md_elements)) { + else if (metaDataFlagSet(smpr.ChildMetaData(), md_elements)) { DocumentTreeIterateDictElements(element, smp); } else { @@ -256,8 +256,8 @@ namespace Slicer { auto smpr = mp->GetChildRef(element->get_name(), boost::bind(metaDataFlagNotSet, boost::bind(&Slicer::HookCommon::GetMetadata, _1), md_attribute)); if (smpr) { - auto smp = smpr->Child(); - if (metaDataFlagSet(smpr->ChildMetaData(), md_bare)) { + auto smp = smpr.Child(); + if (metaDataFlagSet(smpr.ChildMetaData(), md_bare)) { smp = smp->GetAnonChild(); } if (smp) { diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index e13b5b5..d41a994 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -55,7 +55,7 @@ namespace Slicer { class DLL_PUBLIC XmlDeserializer : public Deserializer { protected: static void DocumentTreeIterate(const xmlpp::Node * node, ModelPartPtr mp); - static void DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr mp, ChildRefPtr c); + static void DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr mp, const ChildRef & c); static void DocumentTreeIterate(const xmlpp::Document * doc, ModelPartPtr mp); static void DocumentTreeIterateDictAttrs(const xmlpp::Element::const_AttributeList & attrs, ModelPartPtr dict); static void DocumentTreeIterateDictElements(const xmlpp::Element * parent, ModelPartPtr dict); |