diff --git a/src/lib/diff/tree-mutator-collection-binding.hpp b/src/lib/diff/tree-mutator-collection-binding.hpp index b9f85ebc4..f1f0a65a2 100644 --- a/src/lib/diff/tree-mutator-collection-binding.hpp +++ b/src/lib/diff/tree-mutator-collection-binding.hpp @@ -294,7 +294,7 @@ namespace diff{ /** repeatedly accept, until after the designated location */ virtual bool - accept_until (GenNode const& spec) + accept_until (GenNode const& spec) override { if (spec.matches (Ref::END) or @@ -329,7 +329,7 @@ namespace diff{ /** locate element already accepted into the target sequence * and assign the designated payload value to it. */ virtual bool - assignElm (GenNode const& spec) + assignElm (GenNode const& spec) override { if (binding_.isApplicable(spec)) { @@ -343,7 +343,7 @@ namespace diff{ /** locate the designated target element and build a suitable * sub-mutator for this element into the provided target buffer */ virtual bool - mutateChild (GenNode const& spec, TreeMutator::Handle targetBuff) + mutateChild (GenNode const& spec, TreeMutator::Handle targetBuff) override { if (binding_.isApplicable(spec)) { @@ -357,7 +357,7 @@ namespace diff{ /** verify all our pending (old) source elements where mentioned. * @note allows chained "onion-layers" to clean-up and verify.*/ virtual bool - completeScope() + completeScope() override { return PAR::completeScope() and isnil(this->pos_); diff --git a/src/lib/diff/tree-mutator-gen-node-binding.hpp b/src/lib/diff/tree-mutator-gen-node-binding.hpp index 64d40df29..b42d24e4a 100644 --- a/src/lib/diff/tree-mutator-gen-node-binding.hpp +++ b/src/lib/diff/tree-mutator-gen-node-binding.hpp @@ -85,6 +85,49 @@ namespace diff{ return std::get<1> (targetTree.exposeToDiff()); } + template + class ObjectTypeHandler + : public PAR + { + Rec::Mutator& targetObj_; + + public: + ObjectTypeHandler(Rec::Mutator& targetObj, PAR&& chain) + : PAR(std::forward(chain)) + , targetObj_(targetObj) + { } + + virtual bool + injectNew (GenNode const& n) override + { + if (n.isNamed() and n.isTypeID()) + { + targetObj_.setType(n.data.get()); + return true; + } + else + return PAR::injectNew (n); + } + + virtual bool + assignElm (GenNode const& n) override + { + if (n.isNamed() and n.isTypeID()) + { + targetObj_.setType(n.data.get()); + return true; + } + else + return PAR::assignElm (n); + } + }; + + template + inline Builder> + filterObjectType (Rec::Mutator& targetTree, Builder&& baseBuilder) + { + return ObjectTypeHandler {targetTree, move(baseBuilder)}; + } /** Entry point for DSL builder */ @@ -92,12 +135,13 @@ namespace diff{ inline auto Builder::attach (Rec::Mutator& targetTree) { - return this->attach (collection (accessChildren(targetTree))) + return filterObjectType(targetTree, + this->attach (collection (accessChildren(targetTree))) .attach (collection (accessAttribs(targetTree)) .isApplicableIf ([](GenNode const& spec) -> bool { return spec.isNamed(); // »Selector« : treat key-value elements here - })); + }))); } inline void diff --git a/tests/library/diff/tree-mutator-binding-test.cpp b/tests/library/diff/tree-mutator-binding-test.cpp index 94cd4695c..5c80f204d 100644 --- a/tests/library/diff/tree-mutator-binding-test.cpp +++ b/tests/library/diff/tree-mutator-binding-test.cpp @@ -1128,12 +1128,9 @@ namespace test{ cout << "Sub-" << renderNode(subNode) <injectNew (TYPE_Z); + subMutatorBuffer->injectNew (TYPE_X); subMutatorBuffer->injectNew (CHILD_A); subMutatorBuffer->injectNew (CHILD_A); subMutatorBuffer->injectNew (CHILD_A); + subMutatorBuffer->assignElm (TYPE_Z); // NOTE use assignment to *change* the type field CHECK (subMutatorBuffer->completeScope()); // no pending "open ends" left in sub-scope CHECK (mutator3.completeScope()); // and likewise in the enclosing main scope @@ -1158,9 +1156,8 @@ namespace test{ // verify contents of this second nested scope CHECK (not isnil (attrRec)); - cout <<"Type=="< - + + @@ -4401,6 +4402,47 @@ + + + + + + + + +

+ ...mit den Lambdas kann ich nur die Sicht auf die Werte steuern, +

+

+ nicht aber das eigentliche Verhalten des Bindings. +

+

+ +

+

+ Denn die Lambdas haben keinen Zugriff auf die Ziel-Datenstruktur! +

+ + +
+ +
+ + + + + + + + + + + + + + + +