WIP start definition with a basic tree diff example...

This commit is contained in:
Fischlurch 2015-10-02 18:47:44 +02:00
parent 6ecd24a0a0
commit eaba418d15
5 changed files with 145 additions and 13 deletions

View file

@ -137,8 +137,8 @@ namespace diff{
* of constant size. The actual verbs of the diff language in use are defined
* through the operations of the \em Interpreter; each #VerbToken corresponds
* to a handler function on the Interpreter interface. In addition to the verb,
* each DiffStep also carries a content data element, like e.g. "insert elm
* at next position".
* each DiffStep also carries a content data element as argument,
* like e.g. "insert elm at next position".
* @param I Interpreter interface of the actual language to use
* @param E type of the elementary data elements.
* @remarks recommendation is to set up a builder function for each distinct

View file

@ -25,7 +25,7 @@
** Concrete implementation(s) to apply structural changes to hierarchical
** data structures. Together with the generic #DiffApplicator, this allows
** to receive linearised structural diff descriptions and apply them to
** a given target data structure, to effect the correspoinding changes.
** a given target data structure, to effect the corresponding changes.
**
** @see diff-list-application-test.cpp
** @see VerbToken
@ -38,13 +38,21 @@
#include "lib/diff/tree-diff.hpp"
#include "lib/diff/gen-node.hpp"
namespace lib {
namespace diff{
template<typename E, typename...ARGS>
class DiffApplicationStrategy<wtf<E,ARGS...>>
: public ListDiffInterpreter<E>
/**
* concrete strategy to apply a structural diff to a target data structure
* made from #Record<GenNode> elements.
* @throws lumiera::error::State when diff application fails due to the
* target sequence being different than assumed by the given diff.
* @see #TreeDiffInterpreter explanation of the verbs
*/
template<>
class DiffApplicationStrategy<Rec>
: public TreeDiffInterpreter<Rec>
{
};

View file

@ -1,8 +1,8 @@
/*
TREE-DIFF.hpp - language to describe differences in linearised form
TREE-DIFF.hpp - language to describe differences in hierarchical data structures
Copyright (C) Lumiera.org
2014, Hermann Vosseler <Ichthyostega@web.de>
2015, 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
@ -21,7 +21,7 @@
*/
/** @file list-diff.hpp
/** @file tree-diff.hpp
** A token language to represent structural changes in a tree like
** hierarchical data structure. In combination with the #DiffLanguage framework,
** this building block defines the set of operations to express both content
@ -30,9 +30,9 @@
** @todo UNIMPLEMENTED as of 12/14
**
** @see diff-language.cpp
** @see diff-list-application-test.cpp
** @see list-diff.cpp
** @see VerbToken
** @see diff-tree-application-test.cpp
** @see tree-diff.cpp
** @see GenNode
**
*/

View file

@ -91,7 +91,9 @@ namespace test{
* to a given source list, transforming this list to hold the intended
* target list contents.
*
* @see session-structure-mapping-test.cpp
* @see DiffListGeneration_test
* @see DiffTreeApplication_test
* @see VerbFunctionDispatch_test
*/
class DiffListApplication_test : public Test
{

View file

@ -0,0 +1,122 @@
/*
DiffTreeApplication(Test) - demonstrate the basics of tree diff representation
Copyright (C) Lumiera.org
2015, 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.
* *****************************************************/
#include "lib/test/run.hpp"
#include "lib/diff/tree-diff-application.hpp"
#include "lib/iter-adapter-stl.hpp"
#include "lib/util.hpp"
#include <string>
#include <vector>
using lib::iter_stl::snapshot;
using util::isnil;
using std::string;
using std::vector;
namespace lib {
namespace diff{
namespace test{
namespace {//Test fixture....
#define TOK(id) id(STRINGIFY(id))
string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5);
string TOK(b1), TOK(b2), TOK(b3), TOK(b4);
using Interpreter = TreeDiffInterpreter<Rec>;
using DiffStep = TreeDiffLanguage<Rec>::DiffStep;
using DiffSeq = iter_stl::IterSnapshot<DiffStep>;
DiffStep_CTOR(ins);
DiffStep_CTOR(del);
DiffStep_CTOR(pick);
DiffStep_CTOR(find);
DiffStep_CTOR(skip);
inline DiffSeq
generateTestDiff()
{
return snapshot({del(a1)
, del(a2)
, ins(b1)
, pick(a3)
, find(a5)
, ins(b2)
, ins(b3)
, pick(a4)
, skip(a5)
, ins(b4)
});
}
}//(End)Test fixture
/***********************************************************************//**
* @test Demonstration/Concept: a description language for list differences.
* The representation is given as a linearised sequence of verb tokens.
* This test demonstrates the application of such a diff representation
* to a given source list, transforming this list to hold the intended
* target list contents.
*
* @see session-structure-mapping-test.cpp
*/
class DiffTreeApplication_test : public Test
{
virtual void
run (Arg)
{
DataSeq src({a1,a2,a3,a4,a5});
DiffSeq diff = generateTestDiff();
CHECK (!isnil (diff));
DataSeq target = src;
DiffApplicator<DataSeq> application(target);
application.consume(diff);
CHECK (isnil (diff));
CHECK (!isnil (target));
CHECK (src != target);
CHECK (target == DataSeq({b1,a3,a5,b2,b3,a4,b4}));
}
};
/** Register this test class... */
LAUNCHER (DiffTreeApplication_test, "unit common");
}}} // namespace lib::diff::test