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 later iterations.
The sorting of child nodes is optional and can be changed before each recursion. A built-in comparison function which works on node names (path names) allows choosing ascending and descending order and to ignore or be sensitive about the 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 the methods Next or NextSibling to proceed. Furthermore, method NextParentSibling allows skipping the rest of the current iteration branch.
The end of an iteration is detected with the 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 mor e information about this feature.
class StringTree
Definition at line 1735 of file stringtree.hpp.
#include <stringtree.hpp>
Inner Type Index: | |
struct | RecursionData |
Protected, internal struct used to store the data of recursive iterations. More... | |
Public Method Index: | |
TRecursiveIterator ()=default | |
Default constructor. | |
TRecursiveIterator (const TRecursiveIterator &)=default | |
Trivial copy constructor. | |
TRecursiveIterator (TRecursiveIterator &&)=default | |
Trivial default move constructor. | |
~TRecursiveIterator ()=default | |
Destructor. | |
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 Type Index: | |
using | cmCursor = ATMP_IF_T_F(!TConst, Cursor , ConstCursor ) |
using | cmNode = ATMP_IF_T_F(!TConst, baseNode , const baseNode ) |
using | cmNodeBase = ATMP_IF_T_F(!TConst, baseNodeBase, const baseNodeBase ) |
using | cmTree = ATMP_IF_T_F(!TConst, StringTree , const StringTree ) |
Protected Field Index: | |
size_t | actDepth = size_t(-1) |
AString | actPath |
bool(* | nextCustomSorter )(const cmCursor &, const cmCursor &) = nullptr |
A pointer to a user-defined comparison function. | |
bool | nextIsSorting = false |
Denotes if the children are iterated in a sorting fashion or not. | |
bool | nextSortingIsCaseSensitive = false |
The case sensitivity of the sort (used with built-in sorting by node name). | |
bool | nextSortingIsDescending = false |
The sort order (used with built-in sorting by node name). | |
cmNode * | node |
The pointer to the actual node. | |
unsigned int | recursionDepth =(std::numeric_limits<unsigned int>::max)() |
The requested depth of iteration recursion. | |
std::vector< RecursionData > | stack |
cmTree * | tree = nullptr |
The StringTree this iterator belongs to. | |
Protected Method Index: | |
void | initialize (cmTree *pTree, cmNode *newnode, unsigned int depth) |
bool | next (int skipMode) |
void | recursion () |
|
protected |
Constant or mutable version of the base Cursor type, depending on template parameter TConst
Definition at line 1761 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base node type, depending on template parameter TConst
Definition at line 1757 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base node type, depending on template parameter TConst
Definition at line 1753 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base tree type, depending on template parameter TConst
Definition at line 1749 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 1854 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 1858 of file stringtree.hpp.
|
protected |
A pointer to a user-defined comparison function.
Definition at line 1864 of file stringtree.hpp.
|
protected |
Denotes if the children are iterated in a sorting fashion or not.
Definition at line 1867 of file stringtree.hpp.
|
protected |
The case sensitivity of the sort (used with built-in sorting by node name).
Definition at line 1873 of file stringtree.hpp.
|
protected |
The sort order (used with built-in sorting by node name).
Definition at line 1870 of file stringtree.hpp.
|
protected |
The pointer to the actual node.
Definition at line 1843 of file stringtree.hpp.
|
protected |
The requested depth of iteration recursion.
Definition at line 1861 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 1849 of file stringtree.hpp.
|
protected |
The StringTree this iterator belongs to.
Definition at line 1840 of file stringtree.hpp.
|
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 2142 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 before the current iteration. Activation is performed with method SetPathGeneration.
Definition at line 2092 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 2184 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 before the current iteration. Activation is performed with method SetPathGeneration.
target | The target to append the path to. |
targetData | Denotes whether target should be cleared before appending the path. Defaults to CurrentData::Clear. |
Definition at line 2110 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 limiting 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 1947 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 1926 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 1966 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 2200 of file stringtree.hpp.
|
inline |
Invalidates this object. After invoking this method, this iterator cannot be used further, until one of the overloaded methods Initialize is invoked. After the invocation, method IsValid will return false
.
Definition at line 1975 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 before being initialized. Definition at line 1996 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 before being initialized. Definition at line 1987 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 2061 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 2297 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 2078 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 2071 of file stringtree.hpp.
|
inline |
Returns the current node, encapsulated in a cursor object.
Definition at line 2160 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 2225 of file stringtree.hpp.
|
inline |
Returns the requested maximum depth of iteration, set with Initialize.
Definition at line 2133 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 1910 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 2049 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 2032 of file stringtree.hpp.
|
inline |
Allows switching 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 store the given parameters for future use. Such a use happens whenever a recursive iteration over a list of child nodes is started. At that moment the current configuration of sorting is applied to the list of direct children.
sorting | The switch value. |
Definition at line 2013 of file stringtree.hpp.