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
This commit is contained in:
Fischlurch 2016-03-25 20:46:48 +01:00
parent 1bf0753854
commit fb1857423e
4 changed files with 32 additions and 14 deletions

View file

@ -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)))
{ }

View file

@ -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<COLL>::TypeReferred;
using Elm = typename Coll::value_type;
using iterator = typename lib::iter_stl::_SeqT<Coll>::Range;
using const_iterator = typename lib::iter_stl::_SeqT<const Coll>::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())
{ }

View file

@ -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"

View file

@ -2443,6 +2443,14 @@
<node CREATED="1458850746184" ID="ID_105803291" MODIFIED="1458850752370" TEXT="kein Mutator"/>
</node>
<node CREATED="1458850782747" ID="ID_1019140953" MODIFIED="1458850793430" TEXT="Umgang mit fehlendem Selector"/>
<node CREATED="1458934854051" ID="ID_898160956" MODIFIED="1458934860213" TEXT="Binding st&#xe4;rker abschlie&#xdf;en">
<node CREATED="1458934863225" ID="ID_843139682" MODIFIED="1458934897237" TEXT="contentBuffer k&#xf6;nnte privat sein">
<icon BUILTIN="help"/>
</node>
<node CREATED="1458934878911" ID="ID_986928457" MODIFIED="1458934893132" TEXT="welche Iteratoren m&#xfc;ssen exponiert werden">
<icon BUILTIN="help"/>
</node>
</node>
</node>
<node CREATED="1458868836883" ID="ID_717368167" MODIFIED="1458868851053" TEXT="Beobachtungen">
<node CREATED="1458868852849" ID="ID_1641586585" MODIFIED="1458869076689" TEXT="Sonderbarer &quot;this&quot;-Typ">