summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelParts.cpp18
-rw-r--r--slicer/slicer/modelParts.h18
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h7
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());
}
}