#include <stringtree.hpp>
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 to insert and remove child nodes.
Instances of this class can be received with methods StringTree::Root and StringTree::RecursiveIterator::Node.
The default constructor creates an invalid object, which has to be initialized by assigning a valid object prior to its first use.
class StringTree
Definition at line 568 of file stringtree.hpp.
Public Methods | |
NodePtr () noexcept=default | |
NodePtr (const NodePtr &) noexcept=default | |
NodePtr (NodePtr &&) noexcept=default | |
~NodePtr () noexcept=default | |
AString & | AssemblePath (AString &target, CurrentData targetData=CurrentData::Clear) const |
NodePtr | Child (const NameType &name) |
NodePtr | Clone () const |
uinteger | CountChildren () const |
template<bool TCheck = true, typename... TArgs> | |
NodePtr | CreateChild (const NameType &childName, TArgs &&... args) const |
template<typename... TArgs> | |
std::pair< NodePtr, bool > | CreateChildIfNotExistent (const NameType &name, TArgs &&... args) |
template<typename... TArgs> | |
std::pair< NodePtr, integer > | CreatePathIfNotExistent (const NameType &path, TArgs &&... args) |
uinteger | Delete () |
bool | DeleteChild (const NameType &childName) const |
void | DeleteChild (NodePtr &child) const |
uinteger | DeleteChildren () const |
int | Depth () const |
NodePtr | 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 () |
NodePtr & | GoToParent () |
bool | GoToPreviousSibling () |
NodePtr | GoToRoot () |
SubstringType | GoToTraversedPath (const NameType &path) |
bool | HasChildren () const |
bool | HasNextSibling () const |
bool | HasPreviousSibling () const |
bool | IsInvalid () const |
bool | IsRoot () const |
bool | IsValid () const |
NodePtr | LastChild () const |
const NameType & | Name () const |
NodePtr | NextSibling () const |
bool | operator!= (const NodePtr &other) const |
NodePtr & | operator= (const NodePtr &) noexcept=default |
NodePtr & | operator= (NodePtr &&) noexcept=default |
bool | operator== (const NodePtr &other) const |
NodePtr | Parent () const |
NodePtr | PreviousSibling () const |
NodePtr | Root () const |
std::pair< NodePtr, SubstringType > | TraversePath (const NameType &path) |
StringTree & | Tree () |
T & | Value () |
const T & | Value () const |
Protected Methods | |
NodePtr (basetree *pTree, baseNode *pNode) noexcept | |
|
inlineprotectednoexcept |
Internal constructor
pTree | The StringTree we work on. |
pNode | The node to refer to. |
Definition at line 582 of file stringtree.hpp.
|
defaultnoexcept |
Public constructor. Creates a node pointer which is not valid. The only way to make a default-constructed instance valid is by (copy-) assigning another instance.
|
defaultnoexcept |
Trivial default destructor.
|
inline |
Writes the path to the represented node (excluding the represented node's name) to the given AString.
If this node represents the root node, then nothing is written.
No separation character is prepended to the start and appended to the end of the resulting path.
Note that this method is rather inefficient, as the list of parent nodes have to be inserted to the beginning of the string in an iteration loop, which implies a string copy per parent node. In many situations, it is recommended to search for other ways to keep track of the current path of a node. Class StringTree::RecursiveIterator for example, optionally allows to maintain a string representing the current path with every iteration.
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 1219 of file stringtree.hpp.
Searches a child with the given name and returns a node pointer to it. If no child with this name exists, the returned node pointer 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.
name | The name of the child to search. |
Definition at line 864 of file stringtree.hpp.
|
inline |
Creates a node pointer value representing the same node like this pointer.
Definition at line 666 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 1167 of file stringtree.hpp.
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 node pointer 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.
false
and inserting child nodes with the same name, sets a StringTree to an undefined state.TCheck | If false , 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 constructor of custom type T of the child created. |
Definition at line 1258 of file stringtree.hpp.
|
inline |
Moves this node pointer 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 node pointer 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 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 node pointer will be invalid while the boolean still indicates "not found" (aka true
). Definition at line 919 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 documented with method TraversePath.
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 constructor of each node that is created. |
std::pair
containing a resulting NodePtr and the number of nodes created. Definition at line 1046 of file stringtree.hpp.
|
inline |
Deletes the branch that this node pointer refers to from the tree. If this node pointer 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.
Definition at line 1378 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 1300 of file stringtree.hpp.
|
inline |
Deletes the child represented by the given node pointer child from the node that this node pointer refers to. After the invocation the given child refers to its next sibling. If no such sibling exists, child becomes invalid. This node pointer itself is not changed.
child | Deletes the child represented by the given node. |
Definition at line 1337 of file stringtree.hpp.
|
inline |
Deletes the children of the node that this node pointer refers to. This object itself is not changed.
Definition at line 1354 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 1146 of file stringtree.hpp.
|
inline |
Returns a node pointer value that represents the first child of the node represented. If the represented node has no children, an invalid node pointer is returned.
Definition at line 796 of file stringtree.hpp.
|
inline |
Searches a child with the given name and moves this node pointer to it. If no child with this name exists, the node pointer 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.
name | The name of the child to search. |
true
if the child existed and this object changed, false
otherwise. Definition at line 886 of file stringtree.hpp.
|
inline |
Moves this node pointer 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 node pointer 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 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 950 of file stringtree.hpp.
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.
TArgs | Types of variadic parameters given with parameter args. |
path | The path to move along. |
args | Variadic parameters to be forwarded to constructor of each node that is created. |
Definition at line 1074 of file stringtree.hpp.
|
inline |
Moves this node pointer to the first child of its represented node. If the represented node has no children, this node pointer becomes invalid.
true
if the node pointer was moved, false
if the represented node has no children. Definition at line 809 of file stringtree.hpp.
|
inline |
Moves this node pointer to the last child of its represented node. If the represented node has no children, this node pointer becomes invalid.
true
if the node pointer was moved, false
if the represented node has no children. Definition at line 840 of file stringtree.hpp.
|
inline |
Moves this node pointer to the next sibling of the represented node. If the node has no next sibling, this node pointer becomes invalid. The latter is always true if this is the root node of the tree.
true
if this node pointer was moved, false
if the represented node has no next sibling. Definition at line 743 of file stringtree.hpp.
|
inline |
Moves this node pointer to its parent node. If this is the root node, this object becomes invalid.
Definition at line 715 of file stringtree.hpp.
|
inline |
Moves this node pointer to the previous sibling of the represented node. If the node has no previous sibling, this node pointer becomes invalid. The latter is always true if this is the root node of the tree.
true
if this node pointer was moved, false
if the represented node has no previous sibling. Definition at line 777 of file stringtree.hpp.
|
inline |
Returns a node pointer to the root node of the tree.
Definition at line 688 of file stringtree.hpp.
|
inline |
Same as TraversePath, but moves this node pointer instead of returning one.
path | The path to move this node pointer along. |
Definition at line 1021 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 1156 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 1179 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 1192 of file stringtree.hpp.
|
inline |
Returns the opposite of IsValid.
true
if this is an invalid node pointer that must not be used, false
otherwise. Definition at line 656 of file stringtree.hpp.
|
inline |
Returns true
if this node pointer represents the root node of the StringTree, false
otherwise.
true
if this object represents the root node, false
otherwise. Definition at line 1135 of file stringtree.hpp.
|
inline |
Determines if this is a valid object. Node pointers 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 node pointer. If invalid, false
is returned and this object must not be used. Definition at line 645 of file stringtree.hpp.
|
inline |
Returns a node pointer value that represents the last child of the node represented. If the represented node has no children, an invalid node pointer is returned.
Definition at line 828 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 1094 of file stringtree.hpp.
|
inline |
Returns a node pointer value that represents the next sibling of the node represented this node pointer. If the node has no next sibling, an invalid node pointer is returned.
Definition at line 730 of file stringtree.hpp.
|
inline |
Comparison operator.
other | The object to compare ourselves to. |
false
if this and given node pointer are equal, true
otherwise. Definition at line 626 of file stringtree.hpp.
Trivial default copy assign operator.
this
. Trivial default move assign operator.
this
.
|
inline |
Comparison operator.
other | The object to compare ourselves to. |
true
if this and given node pointer are equal, false
otherwise. Definition at line 617 of file stringtree.hpp.
|
inline |
Creates a node pointer value representing the parent node of the node represented by this object.
If this object represents the root node of the tree, the returned node pointer is invalid.
Definition at line 703 of file stringtree.hpp.
|
inline |
Returns a node pointer value that represents the previous sibling of the node represented this node pointer. If the node has no previous sibling, an invalid node pointer is returned.
Definition at line 762 of file stringtree.hpp.
|
inline |
Returns a node pointer to the root node of the tree.
Definition at line 677 of file stringtree.hpp.
|
inline |
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 node pointers. 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 1006 of file stringtree.hpp.
|
inline |
Returns the three that this pointer is created of.
Definition at line 1105 of file stringtree.hpp.
|
inline |
Retrieves a reference to the templated value of type T stored in the represented node.
Definition at line 1115 of file stringtree.hpp.
|
inline |
Retrieves a constant reference to the templated value of type T stored in the represented node.
Definition at line 1124 of file stringtree.hpp.