diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-10-20 21:55:25 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-10-22 12:45:16 +0100 | 
| commit | e8b56333c407807e847a9736dea96bd92d32cb1c (patch) | |
| tree | 003aa8c048cdfbb5a90bc705dbe4ada6dab78bdc | |
| parent | Make hook parts dll private (diff) | |
| download | slicer-e8b56333c407807e847a9736dea96bd92d32cb1c.tar.bz2 slicer-e8b56333c407807e847a9736dea96bd92d32cb1c.tar.xz slicer-e8b56333c407807e847a9736dea96bd92d32cb1c.zip  | |
Push some templated MP complex stuff down into HookCommon
| -rw-r--r-- | slicer/slicer/modelParts.cpp | 18 | ||||
| -rw-r--r-- | slicer/slicer/modelParts.h | 18 | ||||
| -rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 7 | 
3 files changed, 32 insertions, 11 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 9c2c6e9..8dee564 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -101,5 +101,23 @@ namespace Slicer {  	{  		return false;  	} + +	bool +	HookCommon::filter(const HookFilter & flt, const std::string & name) +	{ +		return (PartName() == name && (!flt || flt(this))); +	} + +	bool +	HookCommon::filter(const HookFilter & flt) +	{ +		return (!flt || flt(this)); +	} + +	void +	HookCommon::apply(const ChildHandler & ch, const ModelPartPtr & modelPart) +	{ +		ch(PartName(), modelPart && modelPart->HasValue() ? modelPart : ModelPartPtr(), this); +	}  } diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 6801e87..4d4e100 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -103,13 +103,6 @@ namespace Slicer {  		mpt_Dictionary,  	}; -	class HookCommon : public IceUtil::Shared { -		public: -			virtual std::string PartName() const = 0; - -			virtual const Metadata & GetMetadata() const = 0; -	}; -  	class ChildRef : public IceUtil::Shared {  		public:  			virtual ModelPartPtr Child() const = 0; @@ -117,6 +110,17 @@ namespace Slicer {  	};  	typedef IceUtil::Handle<ChildRef> ChildRefPtr; +	class DLL_PUBLIC HookCommon : public IceUtil::Shared { +		public: +			bool filter(const HookFilter & flt); +			bool filter(const HookFilter & flt, const std::string &); +			void apply(const ChildHandler & ch, const ModelPartPtr & modelPart); + +			virtual std::string PartName() const = 0; + +			virtual const Metadata & GetMetadata() const = 0; +	}; +  	class DLL_PUBLIC ImplicitChildRef : public ChildRef {  		public:  			ImplicitChildRef(ModelPartPtr); diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 401c3ed..0a6d5de 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -224,8 +224,7 @@ namespace Slicer {  	void ModelPartForComplex<T>::OnEachChild(const ChildHandler & ch)  	{  		for (const auto & h : hooks) { -			auto modelPart = h->Get(GetModel()); -			ch(h->PartName(), modelPart && modelPart->HasValue() ? modelPart : ModelPartPtr(), h); +			h->apply(ch, h->Get(GetModel()));  		}  	} @@ -233,7 +232,7 @@ namespace Slicer {  	ChildRefPtr ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt)  	{  		for (const auto & h : hooks) { -			if (!flt || flt(h)) { +			if (h->filter(flt)) {  				return new MemberChildRef(h->Get(GetModel()), h->GetMetadata());  			}  		} @@ -244,7 +243,7 @@ namespace Slicer {  	ChildRefPtr ModelPartForComplex<T>::GetChildRef(const std::string & name, const HookFilter & flt)  	{  		for (const auto & h : hooks) { -			if (h->PartName() == name && (!flt || flt(h))) { +			if (h->filter(flt, name)) {  				return new MemberChildRef(h->Get(GetModel()), h->GetMetadata());  			}  		}  | 
