diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-18 21:19:03 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-18 21:19:03 +0100 | 
| commit | 84c496d84b2f7e38635b8ba408cfbc619b9ba1e1 (patch) | |
| tree | 556eba086e58973ac512c667cf3675d0ced1c548 | |
| parent | Store hooks in a boost multi index with sequential name based access, includi... (diff) | |
| download | slicer-84c496d84b2f7e38635b8ba408cfbc619b9ba1e1.tar.bz2 slicer-84c496d84b2f7e38635b8ba408cfbc619b9ba1e1.tar.xz slicer-84c496d84b2f7e38635b8ba408cfbc619b9ba1e1.zip  | |
Dedupe the variants of GetChildRef which now all look alike
| -rw-r--r-- | slicer/slicer/modelPartsTypes.h | 4 | ||||
| -rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 31 | 
2 files changed, 19 insertions, 16 deletions
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 37bf824..f49fd13 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -180,6 +180,10 @@ namespace Slicer {  			virtual T * GetModel() = 0; +		protected: +			template<typename R> +			DLL_PRIVATE ChildRef GetChildRefFromRange(const R & range, const HookFilter & flt); +  			typedef boost::multi_index_container<  				HookPtr,  				boost::multi_index::indexed_by< diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 9409c33..a2f2c62 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -338,37 +338,36 @@ namespace Slicer {  		}  	} +	template<typename P> auto begin(const P & p) { return p.first; } +	template<typename P> auto end(const P & p) { return p.second; }  	template<typename T> -	ChildRef ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt) +	template<typename R> +	ChildRef ModelPartForComplex<T>::GetChildRefFromRange(const R & range, const HookFilter & flt)  	{ -		for (const auto & h : hooks.template get<0>()) { +		auto model = GetModel(); +		for (const auto & h : range) {  			if (h->filter(flt)) { -				return ChildRef(h->Get(GetModel()), h->GetMetadata()); +				return ChildRef(h->Get(model), h->GetMetadata());  			}  		}  		return ChildRef();  	} -	template<typename P> auto begin(const P & p) { return p.first; } -	template<typename P> auto end(const P & p) { return p.second; } +	template<typename T> +	ChildRef ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt) +	{ +		return GetChildRefFromRange(hooks.template get<0>(), flt); +	} +  	template<typename T>  	ChildRef ModelPartForComplex<T>::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase)  	{  		if (matchCase) { -			for (const auto & h : hooks.template get<1>().equal_range(name)) { -				if (h->filter(flt)) { -					return ChildRef(h->Get(GetModel()), h->GetMetadata()); -				} -			} +			return GetChildRefFromRange(hooks.template get<1>().equal_range(name), flt);  		}  		else { -			for (const auto & h : hooks.template get<2>().equal_range(boost::algorithm::to_lower_copy(name))) { -				if (h->filter(flt)) { -					return ChildRef(h->Get(GetModel()), h->GetMetadata()); -				} -			} +			return GetChildRefFromRange(hooks.template get<2>().equal_range(name), flt);  		} -		return ChildRef();  	}  	template<typename T>  | 
