initial syntax draft
the envisioned DSL syntax for installing the binding closures into a generic tree mutator object seems to work out
This commit is contained in:
parent
e490fe0263
commit
e4a1261849
3 changed files with 245 additions and 0 deletions
108
src/lib/diff/tree-mutator.hpp
Normal file
108
src/lib/diff/tree-mutator.hpp
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
TREE-MUTATOR.hpp - flexible binding to map generic tree changing operations
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/** @file tree-mutator.hpp
|
||||
** Customisable intermediary to abstract generic tree mutation operations.
|
||||
** This is the foundation for generic treatment of tree altering operations,
|
||||
** and especially to handling of changes (diff) to hierarchical data structures.
|
||||
** The goal is to represent a standard set of conceptual operations working on
|
||||
** arbitrary data structures, without the need for these data structures to
|
||||
** comply to any interface or base type. Rather, we allow each instance to
|
||||
** define binding closures, which allows to tap into any internal data
|
||||
** representation, without any need of disclosure. The only assumption is
|
||||
** that the data to be treated is \em hierarchical and \em object-like,
|
||||
** i.e. it has (named) attributes and it may have a collection of children.
|
||||
** If necessary, typing constraints can be integrated through symbolic
|
||||
** representation of types as chained identifiers. (path dependent types).
|
||||
**
|
||||
** The interface implemented by the TreeMutator is shaped such as to support
|
||||
** the primitives of Lumiera's tree \link diff-language.hpp diff handling language. \endlink
|
||||
** By default, each of these primitives is implemented as a \c NOP -- but each operation
|
||||
** can be replaced by a binding closure, which allows to invoke arbitrary code in the
|
||||
** context of the given object's implementation internals.
|
||||
**
|
||||
** @see generic-tree-mutator-test.cpp
|
||||
** @see DiffDetector
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LIB_DIFF_TREE_MUTATOR_H
|
||||
#define LIB_DIFF_TREE_MUTATOR_H
|
||||
|
||||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/symbol.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::Literal;
|
||||
using std::function;
|
||||
using std::string;
|
||||
|
||||
namespace {
|
||||
class ChangeOperationBinder
|
||||
{
|
||||
public:
|
||||
void
|
||||
operator= (function<void(string)> closure)
|
||||
{
|
||||
UNIMPLEMENTED("install closure");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Customisable intermediary to abstract
|
||||
* mutating operations on arbitrary, hierarchical
|
||||
* object-like data
|
||||
*/
|
||||
class TreeMutator
|
||||
{
|
||||
|
||||
public:
|
||||
ChangeOperationBinder
|
||||
change (Literal attributeID)
|
||||
{
|
||||
UNIMPLEMENTED ("setup binder");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}} // namespace lib::diff
|
||||
#endif /*LIB_DIFF_TREE_MUTATOR_H*/
|
||||
|
|
@ -141,6 +141,11 @@ return: 0
|
|||
END
|
||||
|
||||
|
||||
PLANNED "GenericTreeMutator_test" GenericTreeMutator_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
TEST "HashGenerator_test" HashGenerator_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
|
|
|||
132
tests/library/diff/generic-tree-mutator-test.cpp
Normal file
132
tests/library/diff/generic-tree-mutator-test.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
GenericTreeMutator(Test) - customisable intermediary to abstract tree changing operations
|
||||
|
||||
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/test/test-helper.hpp"
|
||||
#include "lib/diff/tree-mutator.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
//#include <utility>
|
||||
#include <string>
|
||||
//#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using util::isnil;
|
||||
using std::string;
|
||||
//using std::vector;
|
||||
//using std::swap;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace diff{
|
||||
namespace test{
|
||||
|
||||
// using lumiera::error::LUMIERA_ERROR_LOGIC;
|
||||
|
||||
namespace {//Test fixture....
|
||||
|
||||
|
||||
|
||||
}//(End)Test fixture
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************//**
|
||||
* @test Demonstrate a customisable component for flexible bindings
|
||||
* to enable generic tree changing and mutating operations to
|
||||
* arbitrary hierarchical data structures.
|
||||
*
|
||||
* @see TreeMutator
|
||||
* @see GenNodeBasic_test
|
||||
* @see GenNodeBasic_test
|
||||
* @see GenericTreeRepresentation_test
|
||||
*/
|
||||
class GenericTreeMutator_test : public Test
|
||||
{
|
||||
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
simpleAttributeBinding();
|
||||
verifySnapshot();
|
||||
sequenceIteration();
|
||||
duplicateDetection();
|
||||
copy_and_move();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
simpleAttributeBinding()
|
||||
{
|
||||
string localData;
|
||||
TreeMutator mutator;
|
||||
|
||||
mutator.change("something") = [&](string val)
|
||||
{
|
||||
cout << "Change closure invoked with val="<<val<<endl;
|
||||
localData = val;
|
||||
};
|
||||
|
||||
CHECK (isnil (localData));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
verifySnapshot()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sequenceIteration()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
duplicateDetection()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
copy_and_move()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Register this test class... */
|
||||
LAUNCHER (GenericTreeMutator_test, "unit common");
|
||||
|
||||
|
||||
|
||||
}}} // namespace lib::diff::test
|
||||
Loading…
Reference in a new issue