From 2ce85a14493e630f22e81d9505f57f4f48c444bc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 2 May 2015 01:39:58 +0200 Subject: [PATCH] use the attributeID to activate the right closure ...under the assumption that the number of attributes is small, using just a chained sequence of inlined if-statements "would be acceptable" --- src/lib/diff/tree-mutator.hpp | 20 ++++++++--------- tests/15library.tests | 5 ++++- .../diff/generic-tree-mutator-test.cpp | 22 +++++++++---------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/lib/diff/tree-mutator.hpp b/src/lib/diff/tree-mutator.hpp index 072c7409b..f0bb4713c 100644 --- a/src/lib/diff/tree-mutator.hpp +++ b/src/lib/diff/tree-mutator.hpp @@ -77,7 +77,6 @@ namespace diff{ template class Builder; - ////////TODO only preliminary.... typedef Literal ID; using Attribute = DataCap; } @@ -124,11 +123,7 @@ namespace diff{ UNIMPLEMENTED("expose a recursive TreeMutator to transform the denoted child"); } - virtual void - setAttribute (ID id, Attribute& newValue) - { - std::cout << "Empty Base Impl: apply a value change to the named attribute"< change_; virtual void setAttribute (ID id, Attribute& newValue) { - // Decorator-style chained invocation of inherited implementation - PAR::setAttribute(id, newValue); + if (id == attribID_) + change_(newValue.get()); - change_(newValue.get()); + else // delegate to other closures (Decorator-style) + PAR::setAttribute(id, newValue); } - ChangeOperation(function clo, PAR const& chain) + ChangeOperation(ID id, function clo, PAR const& chain) : PAR(chain) + , attribID_(id) , change_(clo) { } }; @@ -177,7 +175,7 @@ namespace diff{ Builder change (Literal attributeID, function closure) { - return Change (closure, *this); + return Change (attributeID, closure, *this); } }; diff --git a/tests/15library.tests b/tests/15library.tests index ec70b550a..d9720dd6b 100644 --- a/tests/15library.tests +++ b/tests/15library.tests @@ -222,7 +222,10 @@ return: 0 END -PLANNED "GenericTreeMutator_test" GenericTreeMutator_test <