TreeExplorer: implement simple auto-expansion

...just expand children instead of normal iteration;
works out of the box, since expansion itself performs a iteration step.
This commit is contained in:
Fischlurch 2017-12-10 00:24:36 +01:00
parent fd5d44f6ca
commit 13d32916ee
3 changed files with 36 additions and 10 deletions

View file

@ -549,8 +549,6 @@ namespace lib {
iterNext(); // consume current head element
if (not isnil(expanded))
expansions_.push (move(expanded));
SRC::expandChildren();
}
/** diagnostics: current level of nested child expansion */
@ -593,6 +591,25 @@ namespace lib {
template<class SRC>
class AutoExpander
: public SRC
{
static_assert(is_StateCore<SRC>::value, "need wrapped state as predecessor in pipeline");
public:
/** pass through ctor */
using SRC::SRC;
void
iterNext()
{
SRC::expandChildren();
}
};
/**
* @internal Decorator for TreeExplorer to map a transformation function on all results.
* The transformation function is invoked on demand, and only once per item to be treated,
@ -968,8 +985,10 @@ namespace lib {
auto
expandAll()
{
UNIMPLEMENTED ("automatically expand all elements");
return *this;
using ResCore = iter_explorer::AutoExpander<SRC>;
using ResIter = typename _DecoratorTraits<ResCore>::SrcIter;
return TreeExplorer<ResIter> (ResCore {move(*this)});
}

View file

@ -807,12 +807,13 @@ namespace test{
void
verify_depthFirstExploration()
{
cout << materialise(
CHECK (materialise(
treeExplore(CountDown{4})
.expand([](uint j){ return CountDown{j-1}; })
.expandAll()
.transform([](int i){ return i*10; })
) <<endl;
)
== "40-30-20-10-10-20-10-10-30-20-10-10-20-10-10");
using std::get;

View file

@ -5757,11 +5757,17 @@
</html>
</richcontent>
<icon BUILTIN="yes"/>
<node CREATED="1512861383695" ID="ID_837026008" MODIFIED="1512861394833" TEXT="setzt direkt auf drunterliegender State Core auf"/>
<node CREATED="1512861401133" ID="ID_930964397" MODIFIED="1512861421774" TEXT="ersetzt nur eine der State-Core-Operationen"/>
<node CREATED="1512861424976" ID="ID_1203553918" MODIFIED="1512861431277" TEXT="sehr einfach, da Typ gleich bleibt"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512844727150" ID="ID_706634236" MODIFIED="1512844732717" TEXT="expandAll">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1512844727150" ID="ID_706634236" MODIFIED="1512861467437" TEXT="expandAll">
<icon BUILTIN="button_ok"/>
<node CREATED="1512844742788" ID="ID_1270260953" MODIFIED="1512844748479" TEXT="expandChildren verz&#xf6;gert"/>
<node CREATED="1512844749235" ID="ID_1344028360" MODIFIED="1512844759661" TEXT="ausgel&#xf6;st durch Iteration"/>
<node CREATED="1512861437832" ID="ID_922141164" MODIFIED="1512861464189" TEXT="iterate() durch expandChildren() ersetzt">
<icon BUILTIN="forward"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512844733549" ID="ID_1055588501" MODIFIED="1512844738184" TEXT="expandLeaf">
<icon BUILTIN="flag-yellow"/>
@ -6768,8 +6774,8 @@
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1510969031379" ID="ID_1327871737" MODIFIED="1512844596824" TEXT="verify_depthFirstExploration();">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512844598906" ID="ID_933777340" MODIFIED="1512844621815" TEXT="expand incl Parent">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1512844598906" ID="ID_933777340" MODIFIED="1512861473722" TEXT="expand incl Parent">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1512844615941" ID="ID_1111018492" MODIFIED="1512844622908" TEXT="auto expand to leafs">
<icon BUILTIN="flag-yellow"/>