to carry out that rather obvious step, I was bound to consider all the implications of choosing a given layout and handling pattern for our external structure representation. Finally, I settled upon the following decisions - the value space represented within the DataCap is flat, not further structured - the distinction between "attribute" and "nested object" is merely conceptual and will be enforced solely by the diff detection / representation protocol - basically, a nested subtree may appear as an attribute; the difference between attributes and children lies solely in the way of access and referral: by-name vs. positional - it is pointless to save space for the representation of the discriminator ID - but we can omit any further explicit type tag, because - we do *not* support programming by switch-on-type, and thus - we do *not* support full introspection, only a passive type-safety check - this is *not* a limitation, since we acknowledge that GenNode is a *Monad* - and the partial function needed within any flatMap implementation maps naturally onto our Variant-Visitor; thus - the DataCap can basically just *be* a Variant - and GenNode has just to supply the neccessary shaffolding to turn that into a full fledged Monad implementation, including direct construction by wrapping a value and flatMap with tree walk
146 lines
3.4 KiB
C++
146 lines
3.4 KiB
C++
/*
|
|
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;
|
|
|
|
using lib::test::showType;
|
|
using lib::test::demangleCxx;
|
|
|
|
|
|
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;
|
|
auto mutator =
|
|
TreeMutator::build()
|
|
.change("something", [&](string val)
|
|
{
|
|
cout << "Oink-Oink"<<endl;
|
|
localData = "Oink-Oink";
|
|
})
|
|
.change("something", [&](string val)
|
|
{
|
|
cout << "Change closure invoked with val="<<val<<endl;
|
|
localData = val;
|
|
});
|
|
|
|
cout << "concrete TreeMutator type="<< demangleCxx (showType (mutator)) <<endl;
|
|
|
|
CHECK (isnil (localData));
|
|
Attribute testAttribute(string ("boing"));
|
|
mutator.setAttribute ("zoing", testAttribute);
|
|
CHECK (!isnil (localData));
|
|
cout << "localData changed to:"<<localData<<endl;
|
|
}
|
|
|
|
|
|
void
|
|
verifySnapshot()
|
|
{
|
|
}
|
|
|
|
|
|
void
|
|
sequenceIteration()
|
|
{
|
|
}
|
|
|
|
|
|
void
|
|
duplicateDetection()
|
|
{
|
|
}
|
|
|
|
|
|
void
|
|
copy_and_move()
|
|
{
|
|
}
|
|
};
|
|
|
|
|
|
/** Register this test class... */
|
|
LAUNCHER (GenericTreeMutator_test, "unit common");
|
|
|
|
|
|
|
|
}}} // namespace lib::diff::test
|