Lumiera  0.pre.03
»edityourfreedom«
Expander< SRC, RES > Class Template Reference

#include "lib/iter-tree-explorer.hpp"

Description

template<class SRC, class RES>
class lib::iter_explorer::Expander< SRC, RES >

Decorator for TreeExplorer adding the ability to "expand children". The expandChildren() operation is the key element of a depth-first evaluation: it consumes one element and performs a preconfigured expansion functor on that element to yield its "children". These are given in the form of another iterator, which needs to be compatible to the source iterator ("compatibility" boils down to both iterators yielding a compatible value type). Now, this sequence of children effectively replaces the expanded source element in the overall resulting sequence; which means, the nested sequence was flattened into the results. Since this expand() operation can again be invoked on the results, the implementation of such an evaluation requires a stack datastructure, so the nested iterator from each expand() invocation can be pushed to become the new active source for iteration. Thus the primary purpose of this Expander (decorator) is to integrate those "nested child iterators" seamlessly into the overall iteration process; once a child iterator is exhausted, it will be popped and iteration continues with the previous child iterator or finally with the source iterator wrapped by this decorator.

Remarks
since we allow a lot of leeway regarding the actual form and definition of the expansion functor, there is a lot of minute technical details, mostly confined within the _FunTraits traits. For the same reason, we need to prepare two different bindings of the passed raw functor, one to work on the source sequence, and the other one to work on the result sequence of a recursive child expansions; these two sequences need not be implemented in the same way, which simplifies the definition of algorithms.
Template Parameters
SRCthe wrapped source iterator, typically a TreeExplorer or nested decorator.
FUNthe concrete type of the functor passed. Will be dissected to find the signature

Definition at line 622 of file iter-tree-explorer.hpp.

Public Member Functions

 Expander ()=default
 
template<typename FUN >
 Expander (SRC &&parentExplorer, FUN &&expandFunctor)
 
bool checkPoint () const
 
size_t depth () const
 diagnostics: current level of nested child expansion More...
 
void expandChildren ()
 core operation: expand current head element More...
 
void iterNext ()
 
void rootCurrent ()
 lock into the current child sequence. More...
 
SRC::reference yield () const
 

Protected Member Functions

ResIteraccessCurrentChildIter ()
 
void dropExhaustedChildren ()
 
bool hasChildren () const
 

Private Types

using ChldExpandFunctor = function< RES(ResIter &)>
 
using ResIter = typename _DecoratorTraits< RES >::SrcIter
 
using RootExpandFunctor = function< RES(SRC &)>
 

Private Member Functions

void incrementCurrent ()
 
bool invariant () const
 

Private Attributes

ChldExpandFunctor expandChild_
 
RootExpandFunctor expandRoot_
 
IterStack< ResIterexpansions_
 

Member Typedef Documentation

◆ ResIter

using ResIter = typename _DecoratorTraits<RES>::SrcIter
private

Definition at line 627 of file iter-tree-explorer.hpp.

◆ RootExpandFunctor

using RootExpandFunctor = function<RES(SRC&)>
private

Definition at line 631 of file iter-tree-explorer.hpp.

◆ ChldExpandFunctor

using ChldExpandFunctor = function<RES(ResIter&)>
private

Definition at line 632 of file iter-tree-explorer.hpp.

Constructor & Destructor Documentation

◆ Expander() [1/2]

Expander ( )
default

◆ Expander() [2/2]

Expander ( SRC &&  parentExplorer,
FUN &&  expandFunctor 
)
inline

Definition at line 644 of file iter-tree-explorer.hpp.

References _FunTraits< FUN, SRC >::adaptFunctor().

+ Here is the call graph for this function:

Member Function Documentation

◆ expandChildren()

void expandChildren ( )
inline

core operation: expand current head element

Definition at line 655 of file iter-tree-explorer.hpp.

References ENSURE(), util::isnil(), and IterStack< TY >::push().

+ Here is the call graph for this function:

◆ depth()

size_t depth ( ) const
inline

diagnostics: current level of nested child expansion

Definition at line 672 of file iter-tree-explorer.hpp.

References IterStack< TY >::size().

+ Here is the call graph for this function:

◆ rootCurrent()

void rootCurrent ( )
inline

lock into the current child sequence.

This special feature turns the current child sequence into the new root, thereby discarding everything else in the expansions stack, including the original root sequence.

Definition at line 683 of file iter-tree-explorer.hpp.

References IterStack< TY >::clear().

+ Here is the call graph for this function:

◆ checkPoint()

bool checkPoint ( ) const
inline

Definition at line 694 of file iter-tree-explorer.hpp.

References ENSURE(), and util::isValid().

+ Here is the call graph for this function:

◆ yield()

SRC::reference yield ( ) const
inline

Definition at line 703 of file iter-tree-explorer.hpp.

◆ iterNext()

void iterNext ( )
inline

Definition at line 710 of file iter-tree-explorer.hpp.

References ENSURE().

+ Here is the call graph for this function:

◆ invariant()

bool invariant ( ) const
inlineprivate

Definition at line 719 of file iter-tree-explorer.hpp.

References IterStateWrapper< T, ST >::isValid().

+ Here is the call graph for this function:

◆ incrementCurrent()

void incrementCurrent ( )
inlineprivate

Definition at line 726 of file iter-tree-explorer.hpp.

◆ accessCurrentChildIter()

ResIter& accessCurrentChildIter ( )
inlineprotected

accessor for downstream layers to allow close collaboration

Definition at line 738 of file iter-tree-explorer.hpp.

◆ dropExhaustedChildren()

void dropExhaustedChildren ( )
inlineprotected

Definition at line 745 of file iter-tree-explorer.hpp.

◆ hasChildren()

bool hasChildren ( ) const
inlineprotected

Definition at line 752 of file iter-tree-explorer.hpp.

Member Data Documentation

◆ expandRoot_

RootExpandFunctor expandRoot_
private

Definition at line 634 of file iter-tree-explorer.hpp.

◆ expandChild_

ChldExpandFunctor expandChild_
private

Definition at line 635 of file iter-tree-explorer.hpp.

◆ expansions_

IterStack<ResIter> expansions_
private

Definition at line 637 of file iter-tree-explorer.hpp.

+ Inheritance diagram for Expander< SRC, RES >:
+ Collaboration diagram for Expander< SRC, RES >:

The documentation for this class was generated from the following file: