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 before its first use.
TConst | If true, internal fields representing the StringTree and the current Node become const and methods which are not declared const become unavailable. |
class StringTree
Definition at line 712 of file stringtree.hpp.
#include <stringtree.hpp>
Public Type Index: | |
using | TStringTree = ATMP_IF_T_F(!TConst, StringTree, const StringTree) |
Public Method Index: | |
TCursor () noexcept=default | |
TCursor (const TCursor &src) noexcept | |
TCursor (TCursor &&src) noexcept | |
~TCursor () noexcept=default | |
Trivial default destructor. | |
strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > & | AssemblePath (strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > &targetString, const TCursor< true > &parent, lang::CurrentData targetData=lang::CurrentData::Clear) const |
strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > & | AssemblePath (strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > &targetString, lang::CurrentData targetData=lang::CurrentData::Clear) const |
TCursor | Child (const NameType &name) const |
uinteger | CountChildren () const |
template<typename TCheck = CHK, 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 |
int | Distance (const TCursor< true > &other) const |
CursorHandle | Export () |
ConstCursorHandle | Export () const |
TCursor | FirstChild () const |
SubstringType | GoTo (const NameType &path) |
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 () |
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 |
std::pair< TCursor, SubstringType > | operator() (const NameType &path) const |
T & | operator* () |
const T & | operator* () const |
T * | operator-> () |
const T * | operator-> () 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 |
template<typename TParent = StringTree> | |
const TParent & | Tree () |
T & | Value () |
const T & | Value () const |
Protected Type Index: | |
using | cmCursor = ATMP_IF_T_F(!TConst, baseCursor, baseConstCursor) |
using | cmNode = ATMP_IF_T_F(!TConst, baseNode, const baseNode) |
using | cmTree = ATMP_IF_T_F(!TConst, basetree, const basetree) |
Protected Method Index: | |
TCursor (cmTree *pTree, cmNode *pNode) noexcept | |
void | dbgCheckTree () const |
void | dbgCheckTreeAndNode () const |
|
protected |
Constant or mutable version of the base cursor type, depending on template parameter TConst
Definition at line 739 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base node type, depending on template parameter TConst
Definition at line 735 of file stringtree.hpp.
|
protected |
Constant or mutable version of the base tree type, depending on template parameter TConst
Definition at line 731 of file stringtree.hpp.
using TStringTree = ATMP_IF_T_F(!TConst, StringTree, const StringTree) |
Constant or mutable version of the outer string tree type, depending on template parameter TConst
Definition at line 771 of file stringtree.hpp.
|
inlineprotectednoexcept |
Internal constructor
pTree | The StringTree we work on. |
pNode | The node to refer to. |
Definition at line 746 of file stringtree.hpp.
|
defaultnoexcept |
Public constructor. Creates an invalid cursor. The only way to make a default-constructed instance valid is by (copy-) assigning another instance.
|
inline |
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.
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 before appending the path. Defaults to CurrentData::Clear. |
Definition at line 1511 of file stringtree.hpp.
|
inline |
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 maintaining a string representing the current path with every iteration.
targetString | The string buffer to append the path to. |
targetData | Denotes whether target should be cleared before appending the path. Defaults to CurrentData::Clear. |
Definition at line 1482 of file stringtree.hpp.
|
inline |
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 cannot exist and hence can't be found. However, in debug-builds, an ALIB_WARNING is reported.
name | The name of the child to search. |
Definition at line 1041 of file stringtree.hpp.
|
inline |
Returns the number of direct children of the represented node.
Note that this method runs in constant time.
Definition at line 1432 of file stringtree.hpp.
|
inline |
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.
TCheck | If NC, no check for an existing child with the same name is performed. |
TArgs | Types of variadic parameters given with parameter args. |
childName | The name of the child |
args | Variadic parameters to be forwarded to the constructor of custom type T of the child created. |
Definition at line 1552 of file stringtree.hpp.
|
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.
TArgs | Types of variadic parameters given with parameter args. |
name | The name of the desired child. |
args | Variadic parameters to be forwarded to the constructor of custom type T in the case a child is created. |
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 1092 of file stringtree.hpp.
|
inline |
Follows the given path and creates non-existing children along the way.
Child names "."
and ".."
are allowed and respected the same as documented with the operator()(const NameType&). New child nodes are constructed by forwarding the given args. Existing children remain untouched.
TArgs | Types of variadic parameters given with parameter args. |
path | The path to move along. |
args | Variadic parameters to be forwarded to the constructor of each node that is created. |
std::pair
containing a resulting Cursor and the number of nodes created. Definition at line 1210 of file stringtree.hpp.
|
inlineprotected |
Checks if this cursor is associated with a tree. Empty and optimized out with release-builds.
Definition at line 751 of file stringtree.hpp.
|
inlineprotected |
Checks if this cursor is associated with a tree and a valid node of the tree. Empty and optimized out with release-builds.
Definition at line 760 of file stringtree.hpp.
|
inline |
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 DestructRootValue are to be used.
Definition at line 1656 of file stringtree.hpp.
|
inline |
Searches and deletes the child named childName from the node that this object refers to. This object itself is not changed.
childName | The name of the desired child. |
true
if the child existed and was deleted, false
otherwise. Definition at line 1591 of file stringtree.hpp.
|
inline |
Deletes the child represented by the given cursor child from the node that this cursor refers to. After the invocation, the given child cursor refers to its next sibling. If no such sibling exists, child becomes invalid. This cursor itself is not changed.
child | Deletes the child represented by the given node. |
Definition at line 1622 of file stringtree.hpp.
|
inline |
Deletes the children of the node that this cursor refers to. This object itself is not changed.
Definition at line 1634 of file stringtree.hpp.
|
inline |
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.
Definition at line 1394 of file stringtree.hpp.
|
inline |
Determines the distance between the node represented by this cursor to the node represented by given other. The distace is defined as follows:
other | The node to test. |
-1
is returned in case other is not found in the path to this node. Definition at line 1412 of file stringtree.hpp.
|
inline |
This method exports the address of the node in the StringTree. The second pointer needed to comprise a cursor determines the tree a node belongs to. Sometimes, it is necessary to store and restore a cursor, where the corresponding tree is known. With this method, in combination with method StringTree::ImportCursor, such storage with sizeof(void*)
(instead of twice that size).
reinterpret_cast
. Use with care. Definition at line 837 of file stringtree.hpp.
|
inline |
Overloaded const
version that returns a const
handle, usable likewise only to re-construct a const
cursor instance.
Definition at line 844 of file stringtree.hpp.
|
inline |
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.
Definition at line 980 of file stringtree.hpp.
|
inline |
Same as the operator()(const NameType&), but moves this cursor instead of returning a new one.
path | The path to move this cursor along. |
Definition at line 1187 of file stringtree.hpp.
|
inline |
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 a name cannot exist and hence can't be found. However, in debug-builds, an ALIB_WARNING is reported.
name | The name of the child to search. |
true
if the child existed and this object changed, false
otherwise. Definition at line 1061 of file stringtree.hpp.
|
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.
TArgs | Types of variadic parameters given with parameter args. |
name | The name of the desired child. |
args | Variadic parameters to be forwarded to the constructor of custom type T in the case a child is created. |
false
if the child was found, and true
if one was created or the given child name was invalid. Definition at line 1120 of file stringtree.hpp.
|
inline |
Follows the given path and creates non-existing children along the way.
Child names "."
and ".."
are allowed and respected same as in operator()(const NameType&).
New child nodes are constructed by forwarding the given args. Existing children remain untouched.
TArgs | Types of variadic parameters given with parameter args. |
path | The path to move along. |
args | Variadic parameters to be forwarded to the constructor of each node that is created. |
Definition at line 1238 of file stringtree.hpp.
|
inline |
Moves this cursor to the first child of its represented node. If the represented node has no children, this cursor becomes invalid.
true
if the cursor was moved, false
if the represented node has no children. Definition at line 991 of file stringtree.hpp.
|
inline |
Moves this cursor to the last child of its represented node. If the represented node has no children, this cursor becomes invalid.
true
if the cursor was moved, false
if the represented node has no children. Definition at line 1019 of file stringtree.hpp.
|
inline |
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.
true
if this cursor was moved, false
if the represented node has no next sibling. Definition at line 934 of file stringtree.hpp.
|
inline |
Moves this cursor to the parent of the current node. If this is the root node, this object becomes invalid.
Definition at line 909 of file stringtree.hpp.
|
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.
true
if this cursor was moved, false
if the represented node has no previous sibling. Definition at line 964 of file stringtree.hpp.
|
inline |
Moves this cursor to the root node of the tree.
Definition at line 884 of file stringtree.hpp.
|
inline |
Returns true
if the represented node has at least one direct child.
true
if the current node has children, false
otherwise. Definition at line 1423 of file stringtree.hpp.
|
inline |
Evaluates if the node represented by this object has a next sibling in its parent's list of children.
true
if a next sibling to this object's represented node exists, false
otherwise. Definition at line 1442 of file stringtree.hpp.
|
inline |
Evaluates if the node represented by this object has a previous sibling in its parent's list of children.
true
if a previous sibling to this object's represented node exists, false
otherwise. Definition at line 1453 of file stringtree.hpp.
|
inline |
Returns the opposite of IsValid.
true
if this is an invalid cursor that must not be used, false
otherwise. Definition at line 867 of file stringtree.hpp.
|
inline |
Returns true
if this cursor represents the root node of the StringTree, false
otherwise.
true
if this object represents the root node, false
otherwise. Definition at line 1385 of file stringtree.hpp.
|
inline |
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
Note that the latter is not applicable to a default-constructed objects (which are also invalid) as with such no StringTree is assigned.
true
if this is a valid cursor. If invalid, false
is returned and this object must not be used. Definition at line 858 of file stringtree.hpp.
|
inline |
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.
Definition at line 1008 of file stringtree.hpp.
|
inline |
Returns the name of the represented node. Note that the concatenated names of recursive child nodes, separated by TSeparator constitute a path.
Definition at line 1257 of file stringtree.hpp.
|
inline |
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.
Definition at line 922 of file stringtree.hpp.
|
inline |
Conversion operator from TCursor<TConst> to TCursor<!TConst>. For const to mutable, this will fail as intended.
Definition at line 806 of file stringtree.hpp.
|
inline |
Comparison operator.
other | The object to compare ourselves to. |
false
if this and given cursor are equal, true
otherwise. Definition at line 822 of file stringtree.hpp.
|
inline |
Follows the given path from the currently represented node to the target node and returns a new cursor instance..
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.
0
to evaluate success of the traversal.path | The path to follow, starting with the node this pointer represents. |
Definition at line 1172 of file stringtree.hpp.
T & operator* | ( | ) |
Retrieves a reference to the templated value of type T stored in the represented node.
|
inline |
Retrieves a reference to the templated value of type T stored in the represented node.
Definition at line 1373 of file stringtree.hpp.
T * operator-> | ( | ) |
Retrieves a pointer to the templated value of type T stored in the represented node.
|
inline |
Retrieves a constant pointer to the templated value of type T stored in the represented node.
Definition at line 1341 of file stringtree.hpp.
|
defaultnoexcept |
Trivial default copy assign operator.
this
.
|
defaultnoexcept |
Trivial default move assign operator.
this
.
|
inline |
Comparison operator.
other | The object to compare ourselves to. |
true
if this and given cursor are equal, false
otherwise. Definition at line 812 of file stringtree.hpp.
|
inline |
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.
Definition at line 899 of file stringtree.hpp.
|
inline |
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.
Definition at line 952 of file stringtree.hpp.
|
inline |
Returns a cursor to the root node of the tree.
Definition at line 876 of file stringtree.hpp.
|
inline |
Returns the tree that this cursor belongs to.
TParent | Optional template parameter, which casts the internal tree type to a derived type. This is for convenience, as otherwise the cast hast to be done by the caller which does not look too nice. |
T & Value | ( | ) |
Retrieves a reference to the templated value of type T stored in the represented node.
|
inline |
Retrieves a constant reference to the templated value of type T stored in the represented node.
Definition at line 1310 of file stringtree.hpp.