X-mas: switch demo-Child-Iterator to the new framework

...passes all the existing unit tests!
This commit is contained in:
Fischlurch 2017-12-24 23:26:22 +01:00
parent 2ea2d38cb2
commit 30a90166fb
4 changed files with 50 additions and 34 deletions

View file

@ -61,10 +61,12 @@
#define GUI_INTERACT_GEN_NODE_LOCATION_QUERY_H
#include "lib/error.hpp"
//#include "lib/symbol.hpp"
#include "lib/symbol.hpp"
#include "gui/interact/ui-coord-resolver.hpp"
#include "lib/diff/gen-node.hpp"
#include "lib/format-string.hpp"
#include "lib/iter-tree-explorer.hpp"
#include "lib/iter-source.hpp"
#include "lib/itertools.hpp"
#include "lib/util.hpp"
@ -82,10 +84,11 @@ namespace interact {
// using std::unique_ptr;
// using std::string;
// using lib::Literal;
// using lib::Symbol;
using lib::Literal;
using lib::Symbol;
using lib::diff::Rec;
using util::_Fmt;
using std::forward;
// using util::unConst;
// using util::isnil;
// using util::min;
@ -214,24 +217,34 @@ namespace interact {
}
struct TreePos
class GenNodeNavigator
: public TreeStructureNavigator
{
Rec const& node;
size_t depth;
////////////TODO wtf to return as iterator type? it is not uniform!
virtual TreeStructureNavigator*
expandChildren() const override
{
UNIMPLEMENTED ("build an iterator to yield the children. This requires to remember who we are ourselves.");
}
};
template<class IT>
static auto
expandableIterSource(IT && rawIterator)
{
return TreeStructureNavigator::buildIterator(
new lib::WrappedLumieraIter<IT, GenNodeNavigator> {forward<IT> (rawIterator)});
}
static ChildIter
childSequence (Rec const& node, size_t& depth)
{
//////////////////////////////////////////////////////////////////////////TICKET #1113 : capturing the string into the global Symbol table becomes obsolete, once GenNode exposes Literal as ID
auto internedString = [](string const& id) -> Literal
{
return Symbol{id};
};
return depth==UIC_PERSP? lib::iter_source::singleVal (internedString (node.getType()))
: lib::iter_source::transform (node.keys(), internedString);
/////////////////////////////////////////////////////////////////////TICKET #1113 : could just use lib::wrapIter when GenNode exposes Literal as ID
return depth==UIC_PERSP? expandableIterSource(singleValIterator (internedString (node.getType())))
: expandableIterSource(transformIterator (node.keys(), internedString));
}
};

View file

@ -101,23 +101,13 @@ namespace interact {
virtual TreeStructureNavigator* expandChildren() const =0;
/** build a Lumiera Forward Iterator as front-end for `*this`.
/** build a Lumiera Forward Iterator as front-end and managing Handle for a TreeStructureNavigator
* or subclass. The provided pointer is assumed to point to heap allocated storage.
* @return copyable iterator front-end handle, which allows to retrieve once all values
* yielded by this IterSource. The front-end does _not take ownership_ of this object.
* yielded by this IterSource. The front-end _takes ownership_ of the given object.
* @note the generated iterator is preconfigured to allow for _"child expansion"_, thereby
* calling through the virtual API function expandChildren()
*/
auto
buildIterator ()
{
return lib::treeExplore (*this)
.expand([](TreeStructureNavigator& parent){ return parent.expandChildren(); });
}
/** build a Lumiera Forward Iterator as front-end and managing Handle for a heap allocated
* TreeStructureNavigator or subclass. The provided pointer is assumed to point to heap allocated
* storage, which will be owned by the generated iterator.
*/
static auto
buildIterator (TreeStructureNavigator* source)
{
@ -142,8 +132,7 @@ namespace interact {
public:
virtual ~LocationQuery(); ///< this is an interface
using iteratorZ = decltype (TreeStructureNavigator::buildIterator(std::declval<TreeStructureNavigator*>()));
using ChildIter = lib::IterSource<Literal>::iterator;
using ChildIter = decltype (TreeStructureNavigator::buildIterator(0));
/** make the real anchor point explicit.

View file

@ -379,7 +379,7 @@ namespace lib {
/** an IterSource frontend to return just a single value once.
* @warning behind the scenes, a heap allocation is managed by shared_ptr,
* to maintain a copy of the wrapped element. When passing a reference,
* only a reference will be wrapped, but a heap allocation happens nontheless
* only a reference will be wrapped, but a heap allocation happens nonetheless
*/
template<typename VAL>
auto

View file

@ -977,7 +977,7 @@
<node CREATED="1502454601603" ID="ID_384770680" MODIFIED="1502454613220" TEXT="nein: MutationMessage wird &#xfc;berfl&#xfc;ssig">
<icon BUILTIN="button_ok"/>
</node>
<node CREATED="1502401987033" ID="ID_1584846573" MODIFIED="1514086999279" TEXT="erfordert Festlegung der Natur der Diff Message">
<node CREATED="1502401987033" ID="ID_1584846573" MODIFIED="1514154108467" TEXT="erfordert Festlegung der Natur der Diff Message">
<arrowlink COLOR="#bdbad3" DESTINATION="ID_89098030" ENDARROW="Default" ENDINCLINATION="821;-1406;" ID="Arrow_ID_554743885" STARTARROW="None" STARTINCLINATION="1459;870;"/>
<icon BUILTIN="messagebox_warning"/>
<node CREATED="1502402004383" ID="ID_1491065212" MODIFIED="1502403195803" TEXT="generisch bleiben?">
@ -8156,6 +8156,16 @@
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513962765760" ID="ID_795911284" MODIFIED="1513963084358" TEXT="Demo-Impl mit GenNode-Tree">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1514153936376" ID="ID_10587919" MODIFIED="1514153997161" TEXT="brauche neuen Builder">
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#338800" CREATED="1514153943993" ID="ID_1604846560" MODIFIED="1514153996307" TEXT="Sub-Interface dazwischenschieben">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1514153999177" ID="ID_1077665588" MODIFIED="1514154104535" TEXT="Child-Expansion">
<linktarget COLOR="#477889" DESTINATION="ID_1077665588" ENDARROW="Default" ENDINCLINATION="-191;0;" ID="Arrow_ID_1839260012" SOURCE="ID_1352163554" STARTARROW="None" STARTINCLINATION="277;0;"/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
@ -8173,10 +8183,14 @@
<linktarget COLOR="#1d3877" DESTINATION="ID_989478065" ENDARROW="Default" ENDINCLINATION="33;-151;" ID="Arrow_ID_1500458185" SOURCE="ID_1829231358" STARTARROW="Default" STARTINCLINATION="-102;2;"/>
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513560680562" ID="ID_634877617" MODIFIED="1513560754433" TEXT="TreeExplorer-Ausdr&#xfc;cke">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1513560680562" ID="ID_634877617" MODIFIED="1514154023415" TEXT="TreeExplorer-Ausdr&#xfc;cke">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513560690440" ID="ID_122153660" MODIFIED="1513560756281" TEXT="Spezial-Behandlung f&#xfc;r Perspektive">
<node COLOR="#338800" CREATED="1513560690440" ID="ID_122153660" MODIFIED="1514154026278" TEXT="Spezial-Behandlung f&#xfc;r Perspektive">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1514154062952" ID="ID_1352163554" MODIFIED="1514154104535" TEXT="Child-Expansion">
<arrowlink COLOR="#477889" DESTINATION="ID_1077665588" ENDARROW="Default" ENDINCLINATION="-191;0;" ID="Arrow_ID_1839260012" STARTARROW="None" STARTINCLINATION="277;0;"/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
@ -8191,8 +8205,8 @@
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513477873206" ID="ID_939423021" MODIFIED="1513477891813" TEXT="definieren was abzudecken ist...">
<icon BUILTIN="yes"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1513478153511" ID="ID_1826394146" MODIFIED="1513478160000" TEXT="bisherige ChildIter-Testf&#xe4;lle">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1513478153511" ID="ID_1826394146" MODIFIED="1514154134542" TEXT="bisherige ChildIter-Testf&#xe4;lle">
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
@ -17015,7 +17029,7 @@
</node>
</node>
</node>
<node CREATED="1502453753155" ID="ID_89098030" MODIFIED="1514086999279" TEXT="Schritt-2">
<node CREATED="1502453753155" ID="ID_89098030" MODIFIED="1514154108467" TEXT="Schritt-2">
<linktarget COLOR="#bdbad3" DESTINATION="ID_89098030" ENDARROW="Default" ENDINCLINATION="821;-1406;" ID="Arrow_ID_554743885" SOURCE="ID_1584846573" STARTARROW="None" STARTINCLINATION="1459;870;"/>
<icon BUILTIN="button_ok"/>
<node CREATED="1502453814499" ID="ID_727706359" MODIFIED="1502453827917" TEXT="Puffer-Ansatz...">