diff --git a/src/lib/diff/tree-mutator.hpp b/src/lib/diff/tree-mutator.hpp index 2a13bdbc3..aae3cbd0b 100644 --- a/src/lib/diff/tree-mutator.hpp +++ b/src/lib/diff/tree-mutator.hpp @@ -73,15 +73,8 @@ namespace diff{ using std::string; namespace { - class ChangeOperationBinder - { - public: - void - operator= (function closure) - { - UNIMPLEMENTED("install closure"); - } - }; + template + class Builder; ////////TODO only preliminary.... typedef Literal ID; @@ -106,59 +99,94 @@ namespace diff{ /* ==== operation API ==== */ - void - reiterate() - { - UNIMPLEMENTED("reset point of reference"); - } - - void + virtual void insertChild (ID id) { UNIMPLEMENTED("establish new child node at current position"); } - void + virtual void deleteChild (ID id) { UNIMPLEMENTED("destroy child node at current position"); } - void - acceptChild (ID id) - { - UNIMPLEMENTED("acknowledge existence of child at current pos and move ahead"); - } - - void + virtual void findChild (ID id) { UNIMPLEMENTED("look ahead, find and retrieve denoted child to be relocated at current position"); } - TreeMutator& + virtual TreeMutator& mutateChild (ID id) { UNIMPLEMENTED("expose a recursive TreeMutator to transform the denoted child"); } - void + virtual void setAttribute (ID id, Attribute newValue) { - UNIMPLEMENTED("apply a value change to the named attribute"); + std::cout << "Empty Base Impl: apply a value change to the named attribute"< build(); }; + namespace { + + template + struct ChangeOperation + : PAR + { + function change_; + + virtual void + setAttribute (ID id, Attribute newValue) + { + PAR::setAttribute(id, newValue); ////////////////////TODO only as a check to verify the class chaining. Of course we do *not* want to call the inherited implementeation + + string dummy("blubb"); + change_(dummy); + } + + ChangeOperation(function clo, PAR const& chain) + : PAR(chain) + , change_(clo) + { } + }; + + template + struct Builder + : PAR + { + using Chain = ChangeOperation; + + Builder(PAR par) + : PAR(par) + { } + + + /* ==== binding API ==== */ + + Builder + change (Literal attributeID, function closure) + { + return Builder (Chain (closure, *this)); + } + }; + + } + Builder + TreeMutator::build () + { + return Builder(TreeMutator()); + } }} // namespace lib::diff diff --git a/tests/library/diff/generic-tree-mutator-test.cpp b/tests/library/diff/generic-tree-mutator-test.cpp index 2a75f7832..1cef76642 100644 --- a/tests/library/diff/generic-tree-mutator-test.cpp +++ b/tests/library/diff/generic-tree-mutator-test.cpp @@ -38,6 +38,9 @@ using std::string; using std::cout; using std::endl; +using lib::test::showType; +using lib::test::demangleCxx; + namespace lib { namespace diff{ @@ -87,15 +90,25 @@ namespace test{ simpleAttributeBinding() { string localData; - TreeMutator mutator; + auto mutator = + TreeMutator::build() + .change("something", [&](string val) + { + cout << "Oink-Oink"<