From fb1857423eddbc7601ea44b13b2426f178050aee Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 25 Mar 2016 20:46:48 +0100 Subject: [PATCH] implement mutation start and lifecycle the whole implementation will very much be based on my experiences with the TestMutationTarget and TestWireTap. Insofar it was a good idea to implement this test dummy first, as a prototype. Basically what emerges here is a standard pattern how to implement a tree mutator: - the TreeMutator will be a one-way-off "throwaway" object. - its lifecylce starts with sucking away the previous contents - consuming the diff moves contents back in place - thus the mutator always attaches onto a target by reference and needs the ability to manipulate the target --- src/lib/diff/test-mutation-target.hpp | 11 +++----- .../diff/tree-mutator-collection-binding.hpp | 26 ++++++++++++++----- src/lib/diff/tree-mutator.hpp | 1 + wiki/thinkPad.ichthyo.mm | 8 ++++++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/lib/diff/test-mutation-target.hpp b/src/lib/diff/test-mutation-target.hpp index 004eb94f7..f715a3cf6 100644 --- a/src/lib/diff/test-mutation-target.hpp +++ b/src/lib/diff/test-mutation-target.hpp @@ -47,7 +47,6 @@ #include "lib/error.hpp" #include "lib/symbol.hpp" -#include "lib/iter-adapter-stl.hpp" #include "lib/diff/record.hpp" #include "lib/diff/tree-mutator.hpp" #include "lib/idi/genfunc.hpp" @@ -227,12 +226,13 @@ namespace diff{ /* === Operation / Mutation API === */ - void + iterator initMutation (string mutatorID) { prev_content_.clear(); swap (content_, prev_content_); log_.event ("attachMutator "+mutatorID); + return srcIter(); } void @@ -366,11 +366,8 @@ namespace diff{ TestWireTap(Target& dummy, PAR const& chain) : PAR(chain) , target_(dummy) - , pos_() - { - target_.initMutation (identify(this)); - pos_ = target_.srcIter(); - } + , pos_(target_.initMutation (identify(this))) + { } diff --git a/src/lib/diff/tree-mutator-collection-binding.hpp b/src/lib/diff/tree-mutator-collection-binding.hpp index e84f66b4f..12c705d4a 100644 --- a/src/lib/diff/tree-mutator-collection-binding.hpp +++ b/src/lib/diff/tree-mutator-collection-binding.hpp @@ -59,6 +59,8 @@ using lib::meta::Strip; using lib::diff::GenNode; + using lib::iter_stl::eachElm; + /** verify the installed functors or lambdas expose the expected signature */ @@ -88,13 +90,18 @@ { using Coll = typename Strip::TypeReferred; using Elm = typename Coll::value_type; - + + using iterator = typename lib::iter_stl::_SeqT::Range; + using const_iterator = typename lib::iter_stl::_SeqT::Range; + + ASSERT_VALID_SIGNATURE (MAT, bool(GenNode const& spec, Elm const& elm)) ASSERT_VALID_SIGNATURE (CTR, Elm (GenNode const&)) ASSERT_VALID_SIGNATURE (SEL, bool(GenNode const&)) ASSERT_VALID_SIGNATURE (ASS, bool(Elm&, GenNode const&)) ASSERT_VALID_SIGNATURE (MUT, bool(Elm&, TreeMutator::MutatorBuffer)) + Coll& collection; MAT matches; @@ -117,15 +124,15 @@ Coll contentBuffer; -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992 - void - initMutation (string mutatorID) + iterator + initMutation () { - prev_content_.clear(); - swap (content_, prev_content_); - log_.event ("attachMutator "+mutatorID); + contentBuffer.clear(); + swap (collection, contentBuffer); + return eachElm (contentBuffer); } +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992 void inject (GenNode&& elm, string operationID) { @@ -165,12 +172,17 @@ class ChildCollectionMutator : public PAR { + using Iter = typename BIN::iterator; + BIN binding_; + Iter pos_; + public: ChildCollectionMutator(BIN wiringClosures, PAR const& chain) : PAR(chain) , binding_(wiringClosures) + , pos_(binding_.initMutation()) { } diff --git a/src/lib/diff/tree-mutator.hpp b/src/lib/diff/tree-mutator.hpp index 3399ea019..3b6ca52a1 100644 --- a/src/lib/diff/tree-mutator.hpp +++ b/src/lib/diff/tree-mutator.hpp @@ -77,6 +77,7 @@ #include "lib/meta/trait.hpp" #include "lib/diff/gen-node.hpp" #include "lib/opaque-holder.hpp" +#include "lib/iter-adapter-stl.hpp" //#include "lib/util.hpp" //#include "lib/format-string.hpp" diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 50b723978..87df08862 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -2443,6 +2443,14 @@ + + + + + + + +