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
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.
class StringTree
Definition at line 1664 of file stringtree.hpp.
#include <stringtree.hpp>
Inner Type Index: | |
struct | RecursionData |
Public Method Index: | |
TRecursiveIterator ()=default | |
TRecursiveIterator (const TRecursiveIterator &)=default | |
TRecursiveIterator (TRecursiveIterator &&)=default | |
~TRecursiveIterator ()=default | |
int | CurrentDepth () const |
const NameType & | CurrentPath () const |
uinteger | DeleteNode () |
AString & | FullPath (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 |
TRecursiveIterator & | operator= (const TRecursiveIterator &)=default |
TRecursiveIterator & | operator= (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) |
|
protected |
Constant or mutable version of the base Cursor type, depending on template parameter TConst
Definition at line 1678 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base node type, depending on template parameter TConst
Definition at line 1674 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base tree type, depending on template parameter TConst
Definition at line 1670 of file stringtree.hpp.
|
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.
|
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.
|
protected |
A pointer to a user-defined comparison function for path names.
Definition at line 1791 of file stringtree.hpp.
|
protected |
Denotes if the children are iterated in a sorting fashion or not.
Definition at line 1794 of file stringtree.hpp.
|
protected |
The case sensitivity of the sort (used with built-in sorting by node name).
Definition at line 1800 of file stringtree.hpp.
|
protected |
The sort order (used with built-in sorting by node name).
Definition at line 1797 of file stringtree.hpp.
|
protected |
The pointer to the actual node.
Definition at line 1766 of file stringtree.hpp.
|
protected |
The requested depth of iteration recursion.
Definition at line 1788 of file stringtree.hpp.
|
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.
|
protected |
The StringTree this iterator belongs to.
Definition at line 1763 of file stringtree.hpp.
|
default |
Default constructor.
|
default |
Trivial copy constructor.
|
default |
Trivial default move constructor.
|
default |
Destructor.
|
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.
Definition at line 2114 of file stringtree.hpp.
|
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.
Definition at line 2055 of file stringtree.hpp.
|
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.
Methods TCursor::DeleteChild and TCursor::DeleteChildren are allowed with this iterator type. Consequently, no replacement method for those is given with this class.
Definition at line 2160 of file stringtree.hpp.
|
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.
target | The target to append the path to. |
targetData | Denotes whether target should be cleared prior to appending the path. Defaults to CurrentData::Clear. |
Definition at line 2075 of file stringtree.hpp.
|
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.
cursor | The cursor to define the branch of the tree to iterate. |
depth | Sets 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.
|
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.
pTree | The StringTree to use. |
depth | Sets 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.
|
inlineprotected |
Resets this iterator to represent to the given node of the given tree.
pTree | The tree to iterate on. |
newnode | The new node to start the iteration from. |
depth | The requested recursion depth. |
Definition at line 2178 of file stringtree.hpp.
|
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.
other | The iterator whose current node becomes the start node for this iterator. |
depth | Sets 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.
|
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.
|
inline |
The negation of IsValid.
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.
|
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.
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.
|
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.
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.
|
inlineprotected |
Goes to the next node. This method is used with interface methods Next, NextSibling and NextParentSibling, as well as with DeleteNode}.
skipMode | 0 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. |
true
if this iterator is valid (a next node was found), false
otherwise. Definition at line 2277 of file stringtree.hpp.
|
inline |
Skips the remaining siblings of the current recursion level and continues with the next available sibling of a previous level.
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.
|
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.
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.
|
inline |
Returns the current node, encapsulated in a cursor object.
Definition at line 2134 of file stringtree.hpp.
|
default |
Trivial default copy assign operator.
this
.
|
default |
Trivial default move assign operator.
this
.
|
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.
|
inline |
Returns the requested maximum depth of iteration, set with Initialize.
Definition at line 2100 of file stringtree.hpp.
|
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.
pathGeneration | Denotes whether the path should be generated or not. |
Definition at line 1839 of file stringtree.hpp.
|
inline |
Sets the sorting of children by their template value, using the given callback function.
customSorterFunction | A custom comparison method used for sorting the children of nodes. |
Definition at line 1996 of file stringtree.hpp.
|
inline |
Sets the sorting of children by their path name, using the built-in comparison methods, which in turn use method String::Equals .
order | The sort order. Defaults to SortOrder::Ascending. |
sensitivity | The case sensitivity when comparing path names. Defaults to Case::Ignore. |
Definition at line 1977 of file stringtree.hpp.
|
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.
sorting | The switch value. |
Definition at line 1956 of file stringtree.hpp.