From 3aeb67549e7055ed525ef6d540e169b94fa1d238 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 28 Sep 2016 20:30:20 +0100 Subject: Lots of functionality move to non-template base --- slicer/slicer/modelParts.h | 13 ++---------- slicer/slicer/modelPartsTypes.cpp | 39 ++++++++++++++++++++++++++++++++++++ slicer/slicer/modelPartsTypes.h | 14 +++++++++++++ slicer/slicer/modelPartsTypes.impl.h | 37 ++++------------------------------ 4 files changed, 59 insertions(+), 44 deletions(-) diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 733e441..8cf3bc5 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -181,24 +181,15 @@ namespace Slicer { class DLL_PUBLIC ModelPartForRootBase : public ModelPart { public: - }; - - template - class ModelPartForRoot : public ModelPartForRootBase { - public: - ModelPartForRoot(T & o); + 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 void OnEachChild(const ChildHandler & ch) override; - virtual bool HasValue() const override; virtual ModelPartType GetType() const override; virtual bool IsOptional() const override; - static const std::string rootName; - - private: - T * ModelObject; ModelPartPtr mp; }; } diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index f518f61..bc3810c 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -46,6 +46,45 @@ namespace Slicer { template class Slicer::ModelPartForRoot>; template class Slicer::ModelPartForRoot>; + // ModelPartForRootBase + ModelPartForRootBase::ModelPartForRootBase(ModelPartPtr m) : + mp(m) + { + } + + ChildRefPtr + ModelPartForRootBase::GetAnonChildRef(const HookFilter &) + { + mp->Create(); + return new ImplicitChildRef(mp); + } + + ChildRefPtr + ModelPartForRootBase::GetChildRef(const std::string & name, const HookFilter & hf) + { + if (name != GetRootName()) { + throw IncorrectElementName(name); + } + return GetAnonChildRef(hf); + } + + void ModelPartForRootBase::OnEachChild(const ChildHandler & ch) + { + ch(GetRootName(), mp, NULL); + } + + ModelPartType + ModelPartForRootBase::GetType() const + { + return mp->GetType(); + } + + bool + ModelPartForRootBase::IsOptional() const + { + return mp->IsOptional(); + } + void ModelPartForSimpleBase::OnEachChild(const ChildHandler &) { } ChildRefPtr ModelPartForSimpleBase::GetAnonChildRef(const HookFilter &) { return NULL; } ChildRefPtr ModelPartForSimpleBase::GetChildRef(const std::string &, const HookFilter &) { return NULL; } diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index ac6ed73..88ee0bd 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -4,6 +4,20 @@ #include "modelParts.h" namespace Slicer { + template + class DLL_PUBLIC ModelPartForRoot : public ModelPartForRootBase { + public: + ModelPartForRoot(T & o); + + const std::string & GetRootName() const override; + virtual bool HasValue() const override; + + static const std::string rootName; + + private: + T * ModelObject; + }; + class DLL_PUBLIC ModelPartForSimpleBase : public ModelPart { public: virtual void OnEachChild(const ChildHandler &) override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 071efcf..2de1780 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -15,32 +15,15 @@ namespace Slicer { // ModelPartForRoot template ModelPartForRoot::ModelPartForRoot(T & o) : - ModelObject(&o), - mp(ModelPart::CreateFor(o)) + ModelPartForRootBase(ModelPart::CreateFor(o)), + ModelObject(&o) { } template - ChildRefPtr ModelPartForRoot::GetAnonChildRef(const HookFilter &) + const std::string & ModelPartForRoot::GetRootName() const { - mp->Create(); - return new ImplicitChildRef(mp); - } - - template - ChildRefPtr ModelPartForRoot::GetChildRef(const std::string & name, const HookFilter &) - { - if (name != rootName) { - throw IncorrectElementName(name); - } - mp->Create(); - return new ImplicitChildRef(mp); - } - - template - void ModelPartForRoot::OnEachChild(const ChildHandler & ch) - { - ch(rootName, mp, NULL); + return rootName; } template @@ -49,18 +32,6 @@ namespace Slicer { return ModelObject && mp->HasValue(); } - template - ModelPartType ModelPartForRoot::GetType() const - { - return mp->GetType(); - } - - template - bool ModelPartForRoot::IsOptional() const - { - return mp->IsOptional(); - } - // ModelPartForSimple template ModelPartForSimple::ModelPartForSimple(T & h) : -- cgit v1.2.3