summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-10-20 21:56:43 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-10-22 12:45:16 +0100
commit6ed98b263602d1f7db1324bed24690343c379750 (patch)
treed1557deddca1fa92938639178202e279ced7c756
parentPush some templated MP complex stuff down into HookCommon (diff)
downloadslicer-6ed98b263602d1f7db1324bed24690343c379750.tar.bz2
slicer-6ed98b263602d1f7db1324bed24690343c379750.tar.xz
slicer-6ed98b263602d1f7db1324bed24690343c379750.zip
Push some templated MP optional stuff into new non-template ModelPartForOptionalBase
-rw-r--r--slicer/slicer/modelPartsTypes.cpp52
-rw-r--r--slicer/slicer/modelPartsTypes.h26
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h58
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<typename T>
- class DLL_PUBLIC ModelPartForOptional : public ModelPart, protected ModelPartModel<IceUtil::Optional<typename T::element_type> > {
+
+ 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<typename T>
+ class DLL_PUBLIC ModelPartForOptional : public ModelPartForOptionalBase, protected ModelPartModel<IceUtil::Optional<typename T::element_type> > {
+ 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<typename T>
- void ModelPartForOptional<T>::OnEachChild(const ChildHandler & ch)
+ bool ModelPartForOptional<T>::hasModel() const
{
- if (this->Model) {
- modelPart->OnEachChild(ch);
- }
- }
-
- template<typename T>
- void ModelPartForOptional<T>::Complete()
- {
- if (this->Model) {
- modelPart->Complete();
- }
+ return this->Model;
}
template<typename T>
@@ -160,32 +150,6 @@ namespace Slicer {
}
template<typename T>
- ChildRefPtr ModelPartForOptional<T>::GetAnonChildRef(const HookFilter & flt)
- {
- if (this->Model) {
- return modelPart->GetAnonChildRef(flt);
- }
- return NULL;
- }
-
- template<typename T>
- ChildRefPtr ModelPartForOptional<T>::GetChildRef(const std::string & name, const HookFilter & flt)
- {
- if (this->Model) {
- return modelPart->GetChildRef(name, flt);
- }
- return NULL;
- }
-
- template<typename T>
- void ModelPartForOptional<T>::SetValue(ValueSourcePtr s)
- {
- if (this->Model) {
- modelPart->SetValue(s);
- }
- }
-
- template<typename T>
void ModelPartForOptional<T>::GetValue(ValueTargetPtr s)
{
if (!this->Model) {
@@ -196,29 +160,11 @@ namespace Slicer {
}
template<typename T>
- bool ModelPartForOptional<T>::HasValue() const
- {
- return this->Model && modelPart->HasValue();
- }
-
- template<typename T>
ModelPartType ModelPartForOptional<T>::GetType() const
{
return T::type;
}
- template<typename T>
- bool ModelPartForOptional<T>::IsOptional() const
- {
- return true;
- };
-
- template<typename T>
- const Metadata & ModelPartForOptional<T>::GetMetadata() const
- {
- return modelPart->GetMetadata();
- }
-
// ModelPartForComplex
template<typename T>
void ModelPartForComplex<T>::OnEachChild(const ChildHandler & ch)