ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
StringTree< T, TNodeMaintainer, TRecycling >::TRecursiveIterator< TConst > Class Template Reference

Description:

template<typename T, typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
class alib::monomem::StringTree< T, TNodeMaintainer, TRecycling >::TRecursiveIterator< TConst >

This public, inner class can be used to recursively iterate through the nodes of outer class StringTree.
The type does not apply to the concept of std::iterator_traits. The rationale for this is the fact that mechanics for sorting the child nodes are provided, which requires allocation of more resources than usual container iterators do. Therefore, objects of this type are not supposed to be temporary and created "on the fly", e.g. in C++ range based loops. Instead, instances should rather be created once and then re-used with subsequent iterations.

The sorting of child nodes is optional and can be changed prior to each recursion. A built-in comparison function which works on node names (path names) allows to choose ascending and descending order and to ignore or be sensitive about letter case. Besides this, custom comparison functions that take a combination of arbitrary node attributes, including a node's value of template type T can be established. See overloaded methods SetSorting for details on this topic.

Objects of this type can be initialized, respectively reset to distinct start nodes by providing objects of

  • type StringTree,
  • type StringTree::Cursor or
  • other objects of this type itself,

to overloaded methods Initialize.

The maximum depth of recursion may be limited with optional parameter depth found with each overloaded version of Initialize. During the iteration, the recursion can be individually selected per node visited. This is done by using either of methods Next or NextSibling to proceed. Furthermore, method NextParentSibling allows to skip the rest of the current iteration branch.
The end of an iteration is detected with method IsValid.

The children of a node can be iterated in a sorted fashion. To enable and disable sorting, various overloads of SetSorting exist. These methods may be invoked any time during the iteration. Whenever a recursion in iteration occurs, the most recent settings of sorting are respected for the list of children of the node that is processed with that recursion.

Finally, the generation of a string representing the actual path to the current iteration node, relative to the iteration's start node can be activated. See method SetPathGeneration for more information about this feature.

See also
For more information on how this class is used, see paragraph 2.2 Inner Class RecursiveIterator of the description of class StringTree.

Friends

class StringTree

Definition at line 1664 of file stringtree.hpp.

#include <stringtree.hpp>

Collaboration diagram for StringTree< T, TNodeMaintainer, TRecycling >::TRecursiveIterator< TConst >:
[legend]

Inner Type Index:

struct  RecursionData
 

Public Method Index:

 TRecursiveIterator ()=default
 
 TRecursiveIterator (const TRecursiveIterator &)=default
 
 TRecursiveIterator (TRecursiveIterator &&)=default
 
 ~TRecursiveIterator ()=default
 
int CurrentDepth () const
 
const NameTypeCurrentPath () const
 
uinteger DeleteNode ()
 
AStringFullPath (AString &target, lang::CurrentData targetData=lang::CurrentData::Clear) const
 
void Initialize (cmCursor cursor, unsigned int depth=(std::numeric_limits< unsigned int >::max)())
 
void Initialize (cmTree &pTree, unsigned int depth=(std::numeric_limits< unsigned int >::max)())
 
void Initialize (const TRecursiveIterator &other, unsigned int depth=(std::numeric_limits< unsigned int >::max)())
 
void Invalidate ()
 
bool IsInvalid () const
 
bool IsValid () const
 
bool Next ()
 
bool NextParentSibling ()
 
bool NextSibling ()
 
cmCursor Node () const
 
TRecursiveIteratoroperator= (const TRecursiveIterator &)=default
 
TRecursiveIteratoroperator= (TRecursiveIterator &&)=default
 
int RequestedDepth () const
 
void SetPathGeneration (lang::Switch pathGeneration)
 
void SetSorting (bool(*customSorterFunction)(const Cursor &, const Cursor &))
 
void SetSorting (lang::SortOrder order=lang::SortOrder::Ascending, lang::Case sensitivity=lang::Case::Ignore)
 
void SetSorting (lang::Switch sorting)
 

Type Definition Details:

◆ cmCursor

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
using cmCursor = ATMP_IF_T_F(!TConst, Cursor , ConstCursor )
protected

Constant or mutable version of the base Cursor type, depending on template parameter TConst

Definition at line 1678 of file stringtree.hpp.

◆ cmNode

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
using cmNode = ATMP_IF_T_F(!TConst, baseNodeBase, const baseNodeBase )
protected

Constant or mutable version of the base node type, depending on template parameter TConst

Definition at line 1674 of file stringtree.hpp.

◆ cmTree

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
using cmTree = ATMP_IF_T_F(!TConst, StringTree , const StringTree )
protected

Constant or mutable version of the base tree type, depending on template parameter TConst

Definition at line 1670 of file stringtree.hpp.

Field Details:

◆ actDepth

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
size_t actDepth = size_t(-1)
protected

The current depth of the iteration (and usage but not size of field stack). set to -1 to if iteration is finished, respectively this iterator was not initialized.

Definition at line 1781 of file stringtree.hpp.

◆ actPath

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
AString actPath
protected

The path to the actual node (excluding the name of the actual node). If this object is nulled, no paths are generated.

Definition at line 1785 of file stringtree.hpp.

◆ nextCustomSorter

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool(* nextCustomSorter) (const cmCursor &, const cmCursor &) = nullptr
protected

A pointer to a user-defined comparison function for path names.

Definition at line 1791 of file stringtree.hpp.

◆ nextIsSorting

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool nextIsSorting = false
protected

Denotes if the children are iterated in a sorting fashion or not.

Definition at line 1794 of file stringtree.hpp.

◆ nextSortingIsCaseSensitive

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool nextSortingIsCaseSensitive = false
protected

The case sensitivity of the sort (used with built-in sorting by node name).

Definition at line 1800 of file stringtree.hpp.

◆ nextSortingIsDescending

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool nextSortingIsDescending = false
protected

The sort order (used with built-in sorting by node name).

Definition at line 1797 of file stringtree.hpp.

◆ node

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
cmNode* node
protected

The pointer to the actual node.

Definition at line 1766 of file stringtree.hpp.

◆ recursionDepth

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
unsigned int recursionDepth =(std::numeric_limits<unsigned int>::max)()
protected

The requested depth of iteration recursion.

Definition at line 1788 of file stringtree.hpp.

◆ stack

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
std::vector<RecursionData> stack
protected

A stack holding the recursive list of unsorted or sorted children and the hook to the current child. Implemented as a vector in combination with member actDepth, to reuse allocated storage space during iteration and when this iterator is re-used (freshly initialized).

Definition at line 1774 of file stringtree.hpp.

◆ tree

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
cmTree* tree = nullptr
protected

The StringTree this iterator belongs to.

Definition at line 1763 of file stringtree.hpp.

Constructor(s) / Destructor Details::

◆ TRecursiveIterator() [1/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
TRecursiveIterator ( )
default

Default constructor.

◆ TRecursiveIterator() [2/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
TRecursiveIterator ( const TRecursiveIterator< TConst > & )
default

Trivial copy constructor.

◆ TRecursiveIterator() [3/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
TRecursiveIterator ( TRecursiveIterator< TConst > && )
default

Trivial default move constructor.

◆ ~TRecursiveIterator()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
~TRecursiveIterator ( )
default

Destructor.

Method Details:

◆ CurrentDepth()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
int CurrentDepth ( ) const
inline

Returns the depth of the current iteration. This is value is available to the algorithm which means this method executes in constant time.

To get the absolute depth of the current node, method TCursor::Depth may be used.

Returns
The distance of the current node and the node of the start of the iteration.

Definition at line 2114 of file stringtree.hpp.

◆ CurrentPath()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
const NameType & CurrentPath ( ) const
inline

Retrieves the current path of walking as a string representation. The path returned is relative to the start node and does not contain a leading separator character. Also, it does not contain the name of the current node, which can be received by invoking method TCursor::Name on the cursor returned by method Node.

Note that this method can be used only if path generation was activated prior to the current iteration. Activation is performed with method SetPathGeneration.

Returns
The path of the current node.

Definition at line 2055 of file stringtree.hpp.

◆ DeleteNode()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
uinteger DeleteNode ( )
inline

Deletes the node that this iterator currently refers to from the tree. After the operation, the iterator is moved forward to the next sibling of the current node, respectively of the first sibling found in the recursion stack.

Note
This method constitutes a legal alternative to method TCursor::Delete, which is forbidden to be invoked on the node returned by method Node as this would invalidate this iterator.

Methods TCursor::DeleteChild and TCursor::DeleteChildren are allowed with this iterator type. Consequently, no replacement method for those is given with this class.

Returns
The total number of nodes deleted.

Definition at line 2160 of file stringtree.hpp.

◆ FullPath()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
AString & FullPath ( AString & target,
lang::CurrentData targetData = lang::CurrentData::Clear ) const
inline

Writes the results of CurrentPath and TCursor::Name, separated by the separator character TSeparator .

Note that this method can be used only if path generation was activated prior to the current iteration. Activation is performed with method SetPathGeneration.

Parameters
targetThe target to append the path to.
targetDataDenotes whether target should be cleared prior to appending the path. Defaults to CurrentData::Clear.
Returns
The given string to allow concatenated operations

Definition at line 2075 of file stringtree.hpp.

Here is the call graph for this function:

◆ Initialize() [1/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void Initialize ( cmCursor cursor,
unsigned int depth = (std::numeric_limits<unsigned int>::max)() )
inline

Resets this iterator to the first child of the node that the given cursor object represents. If the cursor is invalid, the root node of the tree it represents is used.

If the given node has no children, this iterator is marked invalid when this method returns.

Optional parameter depth allows to limit the recursion depth.

Parameters
cursorThe cursor to define the branch of the tree to iterate.
depthSets the recursion depth. A depth of 0 iterates only the direct children of the node represented by cursor . Defaults to std::numeric_limits<unsigned int>::max() for "unlimited" recursion.

Definition at line 1880 of file stringtree.hpp.

◆ Initialize() [2/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void Initialize ( cmTree & pTree,
unsigned int depth = (std::numeric_limits<unsigned int>::max)() )
inline

Resets this iterator to work with the given StringTree. Initializes recursive iteration to the tree's root node. Optionally, a recursion depth can be set.

Parameters
pTreeThe StringTree to use.
depthSets the recursion depth. A depth of 0 iterates only the direct children of the root node. Defaults to std::numeric_limits<unsigned int>::max() for "unlimited" recursion.

Definition at line 1857 of file stringtree.hpp.

◆ initialize()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void initialize ( cmTree * pTree,
cmNode * newnode,
unsigned int depth )
inlineprotected

Resets this iterator to represent to the given node of the given tree.

Parameters
pTreeThe tree to iterate on.
newnodeThe new node to start the iteration from.
depthThe requested recursion depth.

Definition at line 2178 of file stringtree.hpp.

◆ Initialize() [3/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void Initialize ( const TRecursiveIterator< TConst > & other,
unsigned int depth = (std::numeric_limits<unsigned int>::max)() )
inline

Resets this iterator to the first child of the node that the given other iterator currently refers to. The given iterator has to be in a valid state. Optionally, a recursion depth can be set.

Parameters
otherThe iterator whose current node becomes the start node for this iterator.
depthSets the recursion depth. A depth of 0 iterates only the direct children of the node represented by other . Defaults to std::numeric_limits<unsigned int>::max() for "unlimited" recursion.

Definition at line 1901 of file stringtree.hpp.

◆ Invalidate()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void Invalidate ( )
inline

Invalidates this object. After invoking this method, this iterator can not be used further, until one of the overloaded methods Initialize is invoked. After the invocation, method IsValid will return false.

Definition at line 1912 of file stringtree.hpp.

◆ IsInvalid()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool IsInvalid ( ) const
inline

The negation of IsValid.

Returns
false if this is a valid iterator. If invalid, true is returned and the iterator must not be evaluated prior to being initialized.

Definition at line 1937 of file stringtree.hpp.

◆ IsValid()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool IsValid ( ) const
inline

Determines if this is a valid. RecursiveIterator instances may become invalid after invocations of one of the methods Next, NextSibling or NextParentSibling (at the end of the iteration) and become valid with the invocation of one of the overloaded methods Initialize.

Returns
true if this is a valid iterator. If invalid, false is returned and the iterator must not be evaluated prior to being initialized.

Definition at line 1926 of file stringtree.hpp.

◆ Next()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool Next ( )
inline

Iterates to the first child of the current node. If no such child exists, to the next sibling node. If also no sibling exists, iteration continues with the next available node of a previous recursion level.

Returns
true if a next node was found, false otherwise. If false is returned, this iterator is invalid after the call.

Definition at line 2009 of file stringtree.hpp.

◆ next()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool next ( int skipMode)
inlineprotected

Goes to the next node. This method is used with interface methods Next, NextSibling and NextParentSibling, as well as with DeleteNode}.

Parameters
skipMode0 iterates to the first child (if available), 1 iterates to the next sibling (if available) and 2 to the next available sibling of the parent, respectively the current recursion stack.
Returns
true if this iterator is valid (a next node was found), false otherwise.

Definition at line 2277 of file stringtree.hpp.

◆ NextParentSibling()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool NextParentSibling ( )
inline

Skips the remaining siblings of the current recursion level and continues with the next available sibling of a previous level.

Returns
true if a next node was found, false otherwise. If false is returned, this iterator is invalid after the call.

Definition at line 2036 of file stringtree.hpp.

◆ NextSibling()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool NextSibling ( )
inline

Omits recursion on the current node's children, even if the current depth is lower than RequestedDepth.

If no sibling exists, iteration continues with the next available node of a previous recursion level.

Returns
true if a next node was found, false otherwise. If false is returned, this iterator is invalid after the call.

Definition at line 2024 of file stringtree.hpp.

◆ Node()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
cmCursor Node ( ) const
inline

Returns the current node, encapsulated in a cursor object.

Note
It is not allowed to use method TCursor::Delete on the node returned by this method. As a replacement, use method DeleteNode implemented in this class.
However, methods TCursor::DeleteChild and TCursor::DeleteChildren are allowed to be invoked and therefore have no replacement in this class.
Returns
An instance of the public node interface pointing to the currently referenced tree node.

Definition at line 2134 of file stringtree.hpp.

◆ operator=() [1/2]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
TRecursiveIterator & operator= ( const TRecursiveIterator< TConst > & )
default

Trivial default copy assign operator.

Returns
A reference to this.

◆ operator=() [2/2]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
TRecursiveIterator & operator= ( TRecursiveIterator< TConst > && )
default

Trivial default move assign operator.

Returns
A reference to this.

◆ recursion()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void recursion ( )
inlineprotected

Sets this iterator to point to the first child of the actual node. If sorting is enabled, copies all children from the map to a vector and sorts them there.

Definition at line 2204 of file stringtree.hpp.

◆ RequestedDepth()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
int RequestedDepth ( ) const
inline

Returns the requested maximum depth of iteration, set with Initialize.

See also
For the current iteration depth, use CurrentDepth.
Returns
The distance of the current node and the node of the start of the iteration.

Definition at line 2100 of file stringtree.hpp.

◆ SetPathGeneration()

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void SetPathGeneration ( lang::Switch pathGeneration)
inline

With this method, the assembly of a string representing the path from the node used to initialize this iterator to the actual node, is activated or deactivated.
If activated, the path to the current node can be received using overloaded methods CurrentPath and FullPath.

The invocation of the method invalidates this iterator. Note that the path generation can be enabled and disabled with the optional parameter of the overloaded Initialize methods.

Parameters
pathGenerationDenotes whether the path should be generated or not.

Definition at line 1839 of file stringtree.hpp.

Here is the call graph for this function:

◆ SetSorting() [1/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void SetSorting ( bool(* customSorterFunction )(const Cursor &, const Cursor &))
inline

Sets the sorting of children by their template value, using the given callback function.

See also
For more details on sorting see method SetSorting(lang::Switch sorting).
Parameters
customSorterFunctionA custom comparison method used for sorting the children of nodes.

Definition at line 1996 of file stringtree.hpp.

◆ SetSorting() [2/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void SetSorting ( lang::SortOrder order = lang::SortOrder::Ascending,
lang::Case sensitivity = lang::Case::Ignore )
inline

Sets the sorting of children by their path name, using the built-in comparison methods, which in turn use method String::Equals .

See also
For more details on sorting see method SetSorting(lang::Switch sorting).
Parameters
orderThe sort order. Defaults to SortOrder::Ascending.
sensitivityThe case sensitivity when comparing path names. Defaults to Case::Ignore.

Definition at line 1977 of file stringtree.hpp.

◆ SetSorting() [3/3]

template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void SetSorting ( lang::Switch sorting)
inline

Allows to switch sorting on or off. If switched on, sorting is performed by the node names in ascending order.

This and the overloaded versions of this method may be invoked at any time, even on invalid iterators and those that are not initialized. All that the methods do is storing the given parameters for future use. Such use happens whenever a recursive iteration over a list of child nodes is started. In that moment the current configuration of sorting is applied to the list of direct children.

Parameters
sortingThe switch value.

Definition at line 1956 of file stringtree.hpp.


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