stub first round of mutation primitives to pass compiler again

now this feels like making progress again,
even when just writing stubs ;-)

Moreover, it became clear that the "typing" of typed child collections
will always be ad hoc, and thus needs to be ensured on a case by case
base. As a consequence, all mutation primitives must carry the
necessary information for the internal selector to decide if this
primitive is applicable to a given decorator layer. Because
otherwise it is not possible to uphold the concept of a single,
abstracted "source position", where in fact each typed sub-collection
of children (and thus each "onion layer" in the decorator chain)
maintains its own private position
This commit is contained in:
Fischlurch 2016-02-27 01:47:33 +01:00
parent 5d230aa7ac
commit 8bcd37df0a
5 changed files with 315 additions and 13 deletions

View file

@ -0,0 +1,184 @@
/*
TEST-MUTATION-TARGET.hpp - diagnostic helper for TreeMutator bindings
Copyright (C) Lumiera.org
2016, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file test-mutation-target.hpp
** Diagnostic helper for unit tests regarding mutation of custom data.
** The TreeMutator provides a specialised adapter to attach to a TestMutationTarget.
** This adapter is optional and can be combined with any other binding for arbitrary
** hierarchical data structures. It operates in the way of a "wire tap", where the
** observed "mutation primitives" are recorded within the TestMutationTarget,
** which offers query functions for the unit test to verify what happened.
**
** @remarks this facility was created during the attempt to shape the internal API
** of TreeMutator, including definition of the "mutation primitives";
** it might be helpful later to diagnose problems with data mutation.
**
** @todo WIP 2/2016
**
** @see TreeManipulationBinding_test
** @see TreeMutator
**
*/
#ifndef LIB_DIFF_TEST_MUTATION_TARGET_H
#define LIB_DIFF_TEST_MUTATION_TARGET_H
#include "lib/error.hpp"
#include "lib/symbol.hpp"
#include "lib/diff/record.hpp"
#include "lib/diff/tree-mutator.hpp"
#include "lib/idi/genfunc.hpp"
#include "lib/test/event-log.hpp"
//#include "lib/util.hpp"
//#include "lib/format-string.hpp"
//#include <functional>
#include <string>
//#include <vector>
//#include <map>
namespace lib {
namespace diff{
namespace error = lumiera::error;
//using util::_Fmt;
using lib::test::EventLog;
using lib::test::EventMatch;
using lib::Literal;
// using std::function;
using std::string;
namespace {
}
/**
* Test adapter to watch and verify how the
* TreeMutator binds to custom tree data structures.
* @todo WIP 2/2016
*/
class TestMutationTarget
{
EventLog log_{this->identify()};
public:
/* === Diagnostic / Verification === */
bool
empty() const
{
UNIMPLEMENTED ("NIL check");
}
bool
contains (string spec) const
{
UNIMPLEMENTED ("check for recorded element");
}
EventMatch
verify (string match) const
{
return getLog().verify(match);
}
EventMatch
verifyMatch (string regExp) const
{
return getLog().verifyMatch(regExp);
}
EventMatch
verifyEvent (string match) const
{
return getLog().verifyEvent(match);
}
EventMatch
verifyEvent (string classifier, string match) const
{
return getLog().verifyEvent (classifier,match);
}
EventMatch
verifyCall (string match) const
{
return getLog().verifyCall(match);
}
EventMatch
ensureNot (string match) const
{
return getLog().ensureNot(match);
}
EventLog const&
getLog() const
{
return log_;
}
private:
string
identify() const
{
return lib::idi::instanceTypeID(this);
}
};
namespace { // supply a suitable decorator for the TreeMutator
template<class PAR>
struct TestWireTap
: PAR
{
TestMutationTarget& target_;
TestWireTap(TestMutationTarget& dummy, PAR const& chain)
: PAR(chain)
, target_(dummy)
{ }
};
template<class PAR>
Builder<TestWireTap<PAR>>
Builder<PAR>::attachDummy (TestMutationTarget& dummy)
{
return WireTap (dummy, *this);
}
}
}} // namespace lib::diff
#endif /*LIB_DIFF_TREE_MUTATOR_H*/

View file

@ -254,18 +254,90 @@ namespace diff{
out().appendChild (move(*pos));
}
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992
/* == Forwarding: error handling == */
void
locate_and_assign (GenNode const& n)
__expect_in_target (GenNode const& elm, Literal oper)
{
}
void
locate_and_open_for_mutation (GenNode const& n)
__expect_further_elements (GenNode const& elm)
{
}
void
__fail_not_found (GenNode const& elm)
{
}
void
__expect_end_of_scope (GenNode::ID const& idi)
{
}
void
__expect_valid_parent_scope (GenNode::ID const& idi)
{
}
/* == Forwarding: mutation primitives == */
void
skip_src (GenNode const& n)
{
UNIMPLEMENTED("skip matching src element and advance abstract source position");
}
void
accept_src (GenNode const& n)
{
UNIMPLEMENTED("accept existing element");
}
void
inject (GenNode const& n)
{
UNIMPLEMENTED("inject a new element at current abstract position");
}
bool
find_and_accept (GenNode const& n)
{
UNIMPLEMENTED("locate designated element and accept it at current position");
}
bool
accept_until (GenNode const& refMark)
{
UNIMPLEMENTED("repeatedly accept until encountering the mark");
}
void
locate_and_assign (GenNode const& n)
{
UNIMPLEMENTED("locate allready accepted element and assign given new payload");
}
void
locate_and_open_for_mutation (GenNode const& n)
{
UNIMPLEMENTED("locate allready accepted element and open recursive sub-scope for mutation");
}
void
close_subScope()
{
UNIMPLEMENTED("finish and leave sub scope and return to invoking parent scope");
}
/* == Implementation of the list diff application primitives == */
@ -280,22 +352,21 @@ namespace diff{
del (GenNode const& n) override
{
__expect_in_target(n, "remove");
next_src();
skip_src (n);
}
virtual void
pick (GenNode const& n) override
{
__expect_in_target(n, "pick");
accept_src();
next_src();
accept_src (n);
}
virtual void
skip (GenNode const& n) override
{
__expect_further_elements (n);
next_src();
skip_src (n);
} // assume the actual content has been moved away by a previous find()
virtual void

View file

@ -41,6 +41,24 @@
** can be replaced by a binding closure, which allows to invoke arbitrary code in the
** context of the given object's implementation internals.
**
** ## Builder/Adapter concept
** TreeMutator is both an interface and a set of building blocks.
** On concrete usage, the (private, non disclosed) target data structure is assumed
** to _build a subclass of TreeMutator._ To this end, the TreeMutator is complemented
** by a builder API. Each call on this builder -- typically providing some closure --
** will add yet another decorating layer on top of the basic TreeMutator (recall all
** the "mutation primitives" are implemented NOP within the base class). So the actual
** TreeMutator will be structured like an onion, where each layer cares for the sole
** concrete aspect it was tied for by the supplied closure. For example, there might
** be a decorator to handle setting of a "foobar" attribute. Thus, when the diff
** dictates to mutate "foobar", the corresponding closure will be invoked.
**
** \par test dummy target
** There is a special adapter binding to support writing unit tests. The corresponding
** API is only declared (forward) by default. The TestMutationTarget is a helper class,
** which can be attached through this binding and allows a unit test fixture to record
** and verify all the mutation operations encountered.
**
** @see tree-mutator-test.cpp
** @see DiffDetector
**
@ -73,6 +91,10 @@ namespace diff{
using std::function;
using std::string;
class TestMutationTarget; // for unit testing
namespace {
template<class PAR>
struct Builder;
@ -100,7 +122,7 @@ namespace diff{
/* ==== operation API ==== */
virtual void
insertChild (ID id)
insertChild (GenNode const& n)
{
UNIMPLEMENTED("establish new child node at current position");
}
@ -133,7 +155,7 @@ namespace diff{
static Builder<TreeMutator> build();
};
namespace {
namespace { // Mutator-Builder decorator components...
/**
* Type rebinding helper to pick up the actual argument type.
@ -181,6 +203,11 @@ namespace diff{
{ }
};
template<class PAR>
struct TestWireTap;
template<class PAR>
struct Builder
: PAR
@ -192,6 +219,8 @@ namespace diff{
template<class CLO>
using Change = ChangeOperation<PAR,CLO>;
using WireTap = TestWireTap<PAR>;
/* ==== binding API ==== */
@ -201,9 +230,14 @@ namespace diff{
{
return Change<CLO> (attributeID, closure, *this);
}
Builder<WireTap>
attachDummy (TestMutationTarget& dummy);
};
}
}//(END) Mutator-Builder decorator components...
Builder<TreeMutator>
TreeMutator::build ()

View file

@ -25,6 +25,7 @@
#include "lib/format-util.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/diff/tree-mutator.hpp"
#include "lib/diff/test-mutation-target.hpp"
#include "lib/time/timevalue.hpp"
#include "lib/format-cout.hpp"
#include "lib/util.hpp"
@ -34,6 +35,7 @@
//#include <vector>
using util::isnil;
using lib::time::Time;
using std::string;
//using std::vector;
//using std::swap;
@ -107,7 +109,7 @@ namespace test{
TestMutationTarget target;
auto mutator =
TreeMutator::build()
.attachDummy(target);
.attachDummy (target);
CHECK (isnil (target));

View file

@ -1517,7 +1517,8 @@
<node CREATED="1456430363599" ID="ID_1608232847" MODIFIED="1456505525321" TEXT="erlaube typ-gefilterte Kinder"/>
</node>
</node>
<node CREATED="1456506101544" HGAP="4" ID="ID_133511037" MODIFIED="1456506127586" TEXT="Implementierung" VSHIFT="16">
<node CREATED="1456506101544" HGAP="4" ID="ID_133511037" MODIFIED="1456533241759" TEXT="Implementierung" VSHIFT="16">
<icon BUILTIN="pencil"/>
<node CREATED="1456506128581" ID="ID_322289358" MODIFIED="1456506131544" TEXT="Abw&#xe4;gungen">
<node CREATED="1456506135028" HGAP="29" ID="ID_470489868" MODIFIED="1456506141640" TEXT="Indirektionen" VSHIFT="-5">
<node CREATED="1456506145826" ID="ID_759825167" MODIFIED="1456506372089" TEXT="kosten">
@ -1705,7 +1706,17 @@
</node>
<node CREATED="1456528462585" ID="ID_1770521063" MODIFIED="1456528465332" TEXT="Elemente">
<node CREATED="1456528472016" ID="ID_315938795" MODIFIED="1456528476211" TEXT="bleiben abstrakt"/>
<node CREATED="1456528477415" ID="ID_1931717091" MODIFIED="1456528481850" TEXT="abstrakte &quot;Position&quot;"/>
<node CREATED="1456528477415" ID="ID_1931717091" MODIFIED="1456528481850" TEXT="abstrakte &quot;Position&quot;">
<node CREATED="1456533135345" ID="ID_1775378899" MODIFIED="1456533178551" TEXT="Problem: wem geh&#xf6;rt diese Position">
<icon BUILTIN="messagebox_warning"/>
</node>
<node CREATED="1456533146055" ID="ID_312959811" MODIFIED="1456533213989" TEXT="mu&#xdf; stets &#xfc;ber API klar gemacht werden">
<icon BUILTIN="yes"/>
</node>
<node CREATED="1456533166197" ID="ID_1000253494" MODIFIED="1456533204589" TEXT="der Selektor entscheidet, wer gemeint ist">
<icon BUILTIN="button_ok"/>
</node>
</node>
<node CREATED="1456528485326" ID="ID_1764970284" MODIFIED="1456528489737" TEXT="getypte Kinder">
<node CREATED="1456528491109" ID="ID_1550088866" MODIFIED="1456528504567" TEXT="auf Einzelfall-Basis"/>
<node CREATED="1456528505395" ID="ID_1091163328" MODIFIED="1456528519117" TEXT="wer per Selektor zust&#xe4;ndig ist"/>