From e8b56333c407807e847a9736dea96bd92d32cb1c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 20 Oct 2016 21:55:25 +0100 Subject: Push some templated MP complex stuff down into HookCommon --- slicer/slicer/modelParts.cpp | 18 ++++++++++++++++++ slicer/slicer/modelParts.h | 18 +++++++++++------- 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 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::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::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::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()); } } -- cgit v1.2.3