From 6ed98b263602d1f7db1324bed24690343c379750 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 20 Oct 2016 21:56:43 +0100 Subject: Push some templated MP optional stuff into new non-template ModelPartForOptionalBase --- slicer/slicer/modelPartsTypes.cpp | 52 ++++++++++++++++++++++++++++++++ slicer/slicer/modelPartsTypes.h | 26 +++++++++------- slicer/slicer/modelPartsTypes.impl.h | 58 ++---------------------------------- 3 files changed, 69 insertions(+), 67 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index 05e30cd..b535b51 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -106,6 +106,58 @@ namespace Slicer { return ref->second(m); } + void ModelPartForOptionalBase::OnEachChild(const ChildHandler & ch) + { + if (this->hasModel()) { + modelPart->OnEachChild(ch); + } + } + + void ModelPartForOptionalBase::Complete() + { + if (this->hasModel()) { + modelPart->Complete(); + } + } + + ChildRefPtr ModelPartForOptionalBase::GetAnonChildRef(const HookFilter & flt) + { + if (this->hasModel()) { + return modelPart->GetAnonChildRef(flt); + } + return NULL; + } + + ChildRefPtr ModelPartForOptionalBase::GetChildRef(const std::string & name, const HookFilter & flt) + { + if (this->hasModel()) { + return modelPart->GetChildRef(name, flt); + } + return NULL; + } + + void ModelPartForOptionalBase::SetValue(ValueSourcePtr s) + { + if (this->hasModel()) { + modelPart->SetValue(s); + } + } + + bool ModelPartForOptionalBase::HasValue() const + { + return this->hasModel() && modelPart->HasValue(); + } + + bool ModelPartForOptionalBase::IsOptional() const + { + return true; + }; + + const Metadata & ModelPartForOptionalBase::GetMetadata() const + { + return modelPart->GetMetadata(); + } + void ModelPartForEnumBase::OnEachChild(const ChildHandler &) { } ChildRefPtr ModelPartForEnumBase::GetAnonChildRef(const HookFilter &) { return NULL; } ChildRefPtr ModelPartForEnumBase::GetChildRef(const std::string &, const HookFilter &) { return NULL; } diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 6a464e8..bbb257b 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -61,31 +61,35 @@ namespace Slicer { virtual void SetValue(ValueSourcePtr s) override; virtual void GetValue(ValueTargetPtr s) override; }; - - template - class DLL_PUBLIC ModelPartForOptional : public ModelPart, protected ModelPartModel > { + + class DLL_PUBLIC ModelPartForOptionalBase : public ModelPart { public: - ModelPartForOptional(IceUtil::Optional< typename T::element_type > & h); virtual void OnEachChild(const ChildHandler & ch) override; virtual void Complete() override; - virtual void Create() override; virtual ChildRefPtr GetAnonChildRef(const HookFilter & flt) override; virtual ChildRefPtr GetChildRef(const std::string & name, const HookFilter & flt) override; virtual void SetValue(ValueSourcePtr s) override; - virtual void GetValue(ValueTargetPtr s) override; - virtual bool HasValue() const override; - - virtual ModelPartType GetType() const override; - virtual bool IsOptional() const override; - virtual const Metadata & GetMetadata() const override; protected: + virtual bool hasModel() const = 0; ModelPartPtr modelPart; }; + template + class DLL_PUBLIC ModelPartForOptional : public ModelPartForOptionalBase, protected ModelPartModel > { + public: + ModelPartForOptional(IceUtil::Optional< typename T::element_type > & h); + virtual void Create() override; + virtual void GetValue(ValueTargetPtr s) override; + virtual ModelPartType GetType() const override; + + protected: + virtual bool hasModel() const override; + }; + class DLL_PUBLIC ModelPartForComplexBase : public ModelPart { public: virtual ModelPartType GetType() const override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 0a6d5de..443b96b 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -134,19 +134,9 @@ namespace Slicer { } template - void ModelPartForOptional::OnEachChild(const ChildHandler & ch) + bool ModelPartForOptional::hasModel() const { - if (this->Model) { - modelPart->OnEachChild(ch); - } - } - - template - void ModelPartForOptional::Complete() - { - if (this->Model) { - modelPart->Complete(); - } + return this->Model; } template @@ -159,32 +149,6 @@ namespace Slicer { } } - template - ChildRefPtr ModelPartForOptional::GetAnonChildRef(const HookFilter & flt) - { - if (this->Model) { - return modelPart->GetAnonChildRef(flt); - } - return NULL; - } - - template - ChildRefPtr ModelPartForOptional::GetChildRef(const std::string & name, const HookFilter & flt) - { - if (this->Model) { - return modelPart->GetChildRef(name, flt); - } - return NULL; - } - - template - void ModelPartForOptional::SetValue(ValueSourcePtr s) - { - if (this->Model) { - modelPart->SetValue(s); - } - } - template void ModelPartForOptional::GetValue(ValueTargetPtr s) { @@ -195,30 +159,12 @@ namespace Slicer { modelPart->GetValue(s); } - template - bool ModelPartForOptional::HasValue() const - { - return this->Model && modelPart->HasValue(); - } - template ModelPartType ModelPartForOptional::GetType() const { return T::type; } - template - bool ModelPartForOptional::IsOptional() const - { - return true; - }; - - template - const Metadata & ModelPartForOptional::GetMetadata() const - { - return modelPart->GetMetadata(); - } - // ModelPartForComplex template void ModelPartForComplex::OnEachChild(const ChildHandler & ch) -- cgit v1.2.3