From 84c496d84b2f7e38635b8ba408cfbc619b9ba1e1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 18 Oct 2017 21:19:03 +0100 Subject: Dedupe the variants of GetChildRef which now all look alike --- slicer/slicer/modelPartsTypes.h | 4 ++++ 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 + 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 auto begin(const P & p) { return p.first; } + template auto end(const P & p) { return p.second; } template - ChildRef ModelPartForComplex::GetAnonChildRef(const HookFilter & flt) + template + ChildRef ModelPartForComplex::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 auto begin(const P & p) { return p.first; } - template auto end(const P & p) { return p.second; } + template + ChildRef ModelPartForComplex::GetAnonChildRef(const HookFilter & flt) + { + return GetChildRefFromRange(hooks.template get<0>(), flt); + } + template ChildRef ModelPartForComplex::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 -- cgit v1.2.3