template<typename T, typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
class alib::monomem::StringTree< T, TNodeMaintainer, TRecycling >::TCursor< TConst >
This public, inner class provides the main interface into outer class StringTree. The class should be considered being similar to a simple pointer or to a lightweight iterator type, which refers to a tree and a current node.
The class's interface allows the access to a node's name and value and to insert and remove child nodes.
Instances of this class can be received with methods Root and RecursiveIterator::Node.
The default constructor creates an invalid object, which has to be initialized by assigning a valid object prior to its first use.
- See also
- For more information on how this class is used, see paragraph 2.1 Inner Class Cursor of the description of class StringTree.
- Template Parameters
-
TConst | If true, internal fields representing the StringTree and the current Node become const and methods which are not declared const become unavailable. |
Friends
class StringTree
Definition at line 685 of file stringtree.hpp.
|
| TCursor () noexcept=default |
|
| TCursor (const TCursor &src) noexcept |
|
| TCursor (TCursor &&src) noexcept |
|
| TCursor (TStringTree &pTree, uinteger exportValue) noexcept |
|
| ~TCursor () noexcept=default |
|
AString & | AssemblePath (AString &targetString, const TCursor &parent, lang::CurrentData targetData=lang::CurrentData::Clear) const |
|
AString & | AssemblePath (AString &targetString, lang::CurrentData targetData=lang::CurrentData::Clear) const |
|
TCursor | Child (const NameType &name) const |
|
TCursor | Clone () const |
|
uinteger | CountChildren () const |
|
template<bool TCheck = true, typename... TArgs> |
TCursor | CreateChild (const NameType &childName, TArgs &&... args) const |
|
template<typename... TArgs> |
std::pair< TCursor, bool > | CreateChildIfNotExistent (const NameType &name, TArgs &&... args) |
|
template<typename... TArgs> |
std::pair< TCursor, integer > | CreatePathIfNotExistent (const NameType &path, TArgs &&... args) |
|
uinteger | Delete () |
|
bool | DeleteChild (const NameType &childName) const |
|
void | DeleteChild (TCursor &child) const |
|
uinteger | DeleteChildren () const |
|
int | Depth () const |
|
uinteger | Export () const |
|
TCursor | FirstChild () const |
|
bool | GoToChild (const NameType &name) |
|
template<typename... TArgs> |
bool | GoToCreateChildIfNotExistent (const NameType &name, TArgs &&... args) |
|
template<typename... TArgs> |
integer | GoToCreatedPathIfNotExistent (const NameType &path, TArgs &&... args) |
|
bool | GoToFirstChild () |
|
bool | GoToLastChild () |
|
bool | GoToNextSibling () |
|
TCursor & | GoToParent () |
|
bool | GoToPreviousSibling () |
|
TCursor & | GoToRoot () |
|
SubstringType | GoToTraversedPath (const NameType &path) |
|
bool | HasChildren () const |
|
bool | HasNextSibling () const |
|
bool | HasPreviousSibling () const |
|
bool | IsInvalid () const |
|
bool | IsRoot () const |
|
bool | IsValid () const |
|
TCursor | LastChild () const |
|
const NameType & | Name () const |
|
TCursor | NextSibling () const |
|
| operator TCursor<!TConst > () |
|
bool | operator!= (const TCursor &other) const |
|
TCursor & | operator= (const TCursor &) noexcept=default |
|
TCursor & | operator= (TCursor &&) noexcept=default |
|
bool | operator== (const TCursor &other) const |
|
TCursor | Parent () const |
|
TCursor | PreviousSibling () const |
|
TCursor | Root () const |
|
std::pair< TCursor, SubstringType > | TraversePath (const NameType &path) const |
|
StringTree & | Tree () |
|
const StringTree & | Tree () const |
|
T & | Value () |
|
const T & | Value () const |
|
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Same as AssemblePath but accepts a parent node to stop at, instead of the root node. The path created is a relative path from the parent to the represented node, hence it does not include the parent' name and also does not start with the separation character. The latter is true even if the given targetParent
represents the root node. In this case the path is a relative path from the root node '/'
to the child.
If the given parent is not found within the list of parent nodes, then an absolute path from the tree's root to the represented node is returned.
- Parameters
-
targetString | The string buffer to append the path to. |
parent | Denotes the parent node to start a relative path from. |
targetData | Denotes whether target should be cleared prior to appending the path. Defaults to CurrentData::Clear. |
- Returns
- The given AString to allow concatenated operations on it.
Definition at line 1430 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Writes the absolute path to the represented node (including the represented node's name) to the given AString.
If this node represents the root node, then nothing is written but a single separation character.
While the implementation of this method is as efficient as possible (to avoid insertions at the beginning of the target string while moving to the destination/root node, internally a local node-stack is created first, which then is traversed top-down), still in many situations, it is recommended to search for other ways to keep track of the current path of a node and modify and re-use such path. For this, class StringTree::RecursiveIterator , optionally allows to maintain a string representing the current path with every iteration.
- See also
- Overloaded version AssemblePath(AString&,TCursor<TConst>&,lang::CurrentData), which allows to create a relative path from a parent node to this node.
- Parameters
-
targetString | The string buffer to append the path to. |
targetData | Denotes whether target should be cleared prior to appending the path. Defaults to CurrentData::Clear. |
- Returns
- The given AString to allow concatenated operations on it.
Definition at line 1401 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Searches a child with the given name and returns a cursor to it. If no child with this name exists, the returned cursor is invalid
The given name is not considered a path and is not checked for being "."
or ".."
or if it contains a separator character. Children with such name can not exist and hence can't be found. However, in debug builds, an ALIB_WARNING is reported.
- Parameters
-
name | The name of the child to search. |
- Returns
- A cursor representing the last child of the node represented by this cursor.
Definition at line 1024 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
template<bool TCheck = true, typename... TArgs>
Creates and returns a child node. If a node already exists, nothing is done and nullptr
is returned as this is considered an error.
If the child name is illegal (equal to "."
or ".."
or contains a separation character), an ALib warning is raised and an invalid cursor is returned.
Template parameter TCheck may be used to suppress the search for an existing child with the same name, as well as the check for correctness of the given child name. This tremendously improves the execution performance of this method.
- Attention
- Setting template parameter TCheck to
false
and inserting child nodes with the same name, sets a StringTree to an undefined state.
- Template Parameters
-
TCheck | If false , no check for an existing child with the same name is performed. |
TArgs | Types of variadic parameters given with parameter args . |
- Parameters
-
childName | The name of the child |
args | Variadic parameters to be forwarded to constructor of custom type T of the child created. |
- Returns
- A new cursor object representing the created child node. If the given childName was invalid or the child existed already, the returned object is invalid.
Definition at line 1472 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
template<typename... TArgs>
std::pair< TCursor, bool > CreateChildIfNotExistent |
( |
const NameType & | name, |
|
|
TArgs &&... | args ) |
|
inline |
Moves this cursor to the child with given name . If no child with this name exists, one will be created.
If the given childName is invalid (equals to "."
or ".."
or contains the separation character), then still true
is returned, but this cursor becomes invalid. In addition, with debug builds, an ALIB_WARNING is reported.
- Template Parameters
-
TArgs | Types of variadic parameters given with parameter args . |
- Parameters
-
name | The name of the desired child. |
args | Variadic parameters to be forwarded to constructor of custom type T in the case a child is created. |
- Returns
- A pair of a cursor pointing to the child and a boolean that equals
false
if the child was found, and true
if a child was created. If the given name was invalid, the returned cursor will be invalid while the boolean still indicates "not found" (aka true
).
Definition at line 1079 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
template<typename... TArgs>
Follows the given path and creates non-existing children along the way.
Child names "."
and ".."
are allowed and respected same as documented with method TraversePath.
New child nodes are constructed by forwarding the given args . Existing children remain untouched.
- Template Parameters
-
TArgs | Types of variadic parameters given with parameter args . |
- Parameters
-
path | The path to move along. |
args | Variadic parameters to be forwarded to constructor of each node that is created. |
- Returns
- A
std::pair
containing a resulting Cursor and the number of nodes created.
Definition at line 1205 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Deletes the branch that this cursor refers to from the tree. If this cursor does not represent the root node, then after the operation, it refers to the parent of the current node.
If the represented node is the root node, only the children are deleted and this object remains representing the root node. Note that in this case any explicitly set custom value of the root node is not deleted. For this, exclusively methods ConstructRootValue and DeleteRootValue are to be used.
- Note
- If this method is invoked on an object returned by method RecursiveIterator::Node, the invoking iterator becomes invalid.
To avoid this, method RecursiveIterator::DeleteNode is to be used.
- Returns
- The total number of nodes deleted. Can be zero, in case this object represents the root node and this node has no children.
Definition at line 1592 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool DeleteChild |
( |
const NameType & | childName | ) |
const |
|
inline |
Searches and deletes the child named childName from the node that this object refers to. This object itself is not changed.
- See also
- Overloaded version of this method that accepts a cursor referring to the child in question.
- Parameters
-
childName | The name of the desired child. |
- Returns
true
if the child existed and was deleted, false
otherwise.
Definition at line 1514 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
void DeleteChild |
( |
TCursor< TConst > & | child | ) |
const |
|
inline |
Deletes the child represented by the given cursor child from the node that this cursor refers to. After the invocation the given child refers to its next sibling. If no such sibling exists, child becomes invalid. This cursor itself is not changed.
- Note
- This method is handy to implement forward iterations through children of a parent node with the aim to delete certain child nodes. No corresponding version of this method exists that moves the given child pointer to its previous sibling. For reverse iterations, a clone of the child argument has to be passed. However, any overhead caused by such temporary object creation will be optimized out by modern C++ compilers.
- Parameters
-
child | Deletes the child represented by the given node. |
Definition at line 1551 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Determines the depth of the node represented by this object. This is done by counting the iterations needed to reach the root node of the tree.
- Returns
- The distance from this node to the root node.
Definition at line 1328 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Returns a cursor object that represents the first child of the node represented. If the represented node has no children, an invalid cursor is returned.
- Returns
- A cursor representing the first child of the node this cursor points to.
Definition at line 955 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Searches a child with the given name and moves this cursor to it. If no child with this name exists, the cursor does not change and false
is returned.
The given name is not considered a path and is not checked for being "."
or ".."
or if it contains a separator character. Children with such name can not exist and hence can't be found. However, in debug builds, an ALIB_WARNING is reported.
- Parameters
-
name | The name of the child to search. |
- Returns
true
if the child existed and this object changed, false
otherwise.
Definition at line 1046 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
template<typename... TArgs>
bool GoToCreateChildIfNotExistent |
( |
const NameType & | name, |
|
|
TArgs &&... | args ) |
|
inline |
Moves this cursor to the child with given name . If no child with this name exists, one will be created.
If the given childName is invalid (equals to "."
or ".."
or contains the separation character), then still true
is returned, but this cursor becomes invalid. In addition, with debug builds, an ALIB_WARNING is reported.
- Template Parameters
-
TArgs | Types of variadic parameters given with parameter args . |
- Parameters
-
name | The name of the desired child. |
args | Variadic parameters to be forwarded to constructor of custom type T in the case a child is created. |
- Returns
false
if the child was found, and true
if one was created or the given child name was invalid.
Definition at line 1110 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
template<typename... TArgs>
integer GoToCreatedPathIfNotExistent |
( |
const NameType & | path, |
|
|
TArgs &&... | args ) |
|
inline |
Follows the given path and creates non-existing children along the way.
Child names "."
and ".."
are allowed and respected same as in TraversePath.
New child nodes are constructed by forwarding the given args . Existing children remain untouched.
- Template Parameters
-
TArgs | Types of variadic parameters given with parameter args . |
- Parameters
-
path | The path to move along. |
args | Variadic parameters to be forwarded to constructor of each node that is created. |
- Returns
- The number of nodes created.
Definition at line 1233 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Moves this cursor to the first child of its represented node. If the represented node has no children, this cursor becomes invalid.
- Returns
true
if the cursor was moved, false
if the represented node has no children.
Definition at line 968 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Moves this cursor to the last child of its represented node. If the represented node has no children, this cursor becomes invalid.
- Returns
true
if the cursor was moved, false
if the represented node has no children.
Definition at line 1000 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Moves this cursor to the next sibling of the represented node. If the node has no next sibling, this cursor becomes invalid. The latter is always true if this is the root node of the tree.
- Returns
true
if this cursor was moved, false
if the represented node has no next sibling.
Definition at line 903 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Moves this cursor to the parent of the current node. If this is the root node, this object becomes invalid.
- Returns
- *this to allow concatenated calls
Definition at line 873 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
bool GoToPreviousSibling |
( |
| ) |
|
|
inline |
Moves this cursor to the previous sibling of the represented node. If the node has no previous sibling, this cursor becomes invalid. The latter is always true if this is the root node of the tree.
- Returns
true
if this cursor was moved, false
if the represented node has no previous sibling.
Definition at line 937 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Returns true
if this cursor represents the root node of the StringTree, false
otherwise.
- Returns
true
if this object represents the root node, false
otherwise.
Definition at line 1317 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Determines if this is a valid object. Cursors may become invalid with transition methods like GoToParent, GoToFirstChild or GoToNextSibling. An invalid object may be turned into a valid one by either
- assigning a valid object (copy assignment), or
- invoking method GoToRoot, or
- invoking method GoToTraversedPath using absolute path addressing.
Note that the latter is not applicable to a default-constructed objects (which are also invalid) as with such no StringTree is assigned.
- Returns
true
if this is a valid cursor. If invalid, false
is returned and this object must not be used.
Definition at line 808 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Returns a cursor value that represents the last child of the node represented. If the represented node has no children, an invalid cursor is returned.
- Returns
- A cursor representing the last child of the node represented by this cursor.
Definition at line 987 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Returns the name of the represented node. Note that the concatenated names of recursive child nodes, separated by TSeparator constitute a path.
- Returns
- A constant reference to the name of the represented node.
Definition at line 1253 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Returns a cursor value that represents the next sibling of the node represented this cursor. If the node has no next sibling, an invalid cursor is returned.
- Returns
- A cursor object representing the next sibling of the node represented by this object.
Definition at line 889 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Conversion operator from TCursor<TConst> to TCursor<!TConst>. For const to mutable, this will fail as intended.
- Returns
- A constant iterator, if this is a mutable. Otherwise compilation will duly fail.
Definition at line 763 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Creates a cursor value representing the parent node of the node represented by this object.
If this object represents the root node of the tree, the returned cursor is invalid.
- Returns
- A cursor pointing to the parent node of the node represented by this cursor.
Definition at line 860 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Returns a cursor value that represents the previous sibling of the node represented this cursor. If the node has no previous sibling, an invalid cursor is returned.
- Returns
- A cursor object representing the previous sibling of the node represented by this object.
Definition at line 923 of file stringtree.hpp.
template<typename T , typename TNodeMaintainer = StringTreeNamesDynamic<character>, typename TRecycling = Recycling::Private>
template<bool TConst>
Follows the given path from the currently represented node to the target node.
The method supports absolute and relative path addressing: If path begins with a separation character, then the transition starts with the root node of the StringTree. Furthermore, child name "."
is ignored and just skipped while a name of ".."
addresses the parent node during the transition. Repeated separation characters are ignored.
If, while processing the path string, the root node is found an the next path element is "..", this element is ignored and processing continues. As a sample, assuming that nodes /a and /b exist, the paths:
/a/../b
and
/a/../../b
both evaluate to
/b
Relative paths must not be used on invalid cursors. Doing so is undefined behavior and raises an ALib assertion in debug-compilations.
If a child along the path does not exist, the traversal is ended and the remaining portion of the path is returned.
- Note
- If parameter path is a temporary object, the resulting Substring must not be used, as it refers to the given string's buffer. In any case, its length can still be compared to
0
to evaluate success of the traversal.
- Parameters
-
path | The path to follow, starting with the node this pointer represents. |
- Returns
- A pair of a cursor pointing to last child not of the existing portion of the given path , and a substring that contains the non-existing portion of a path, or is empty if the complete path existed.
Definition at line 1165 of file stringtree.hpp.