#include <stringtree.hpp>
This struct is the default type for template parameter TNodeMaintainer of class StringTree.
Besides defining the character type as given with template parameter TChar, the node name string type is exposed with NameStringType. The string type depends on template parameter TLocalCapacity:
0
, the type evaluates to a simple string with no internal storage.This design allows to allocate a fixed-size string buffer with each node and only if a node's name exceeds this capacity, a dynamic allocation for storing the node name is performed. As a consequence, some overhead of wasted memory will occur, as this capacity is allocated with every node, regardless of its name's length.
Method InitializeNode is invoked after insertion of a new element (aka "node") into the container and FreeNode is invoked prior to the destruction of a node. When InitializeNode is invoked, the custom object of template type T (of the StringTree) is already default constructed and the name of the node (field detail::StringTreeBase::Node::name) is set to what was provided as a child name or path string. (In the latter case, it is set to a substring of the given path.). If template parameter TLocalCapacity is greater than 0, the method remains empty, as the LocalString manages its memory automatically. If 0
is given, the node name is replaced by a copy of the string which is dynamically allocated.
A custom implementation has to provide all four entities that this type provides in a compatible fashion.
The main purpose of the node maintainer types is to ensure that the name strings of inserted nodes are duly allocated, copied and freed as needed: When a new element is (or a whole path of new elements are) created, then the initial name of the nodes are taken from the string passed to the corresponding interface method of class StringTree (and inner types). The challenge is that these string's life-cycle might be only short term. Therefore, right after the creation of an element, method InitializeNode is invoked, allowing to create a safe copy of the name.
To free any allocated space, method FreeNode is invoked.
Besides this, custom implementation may tweak the given node node on their own discretion.
TChar | The character type of the key strings. This type is used with any interface method of StringTree that accepts a node name or path string. Defaults to type character. |
TLocalCapacity | The capacity of the LocalString to place in the StringTree's node. If 0 is given, a normal String is used for the name, and the buffer is copied to an dynamically allocated array.Defaults to 32 . |
Definition at line 84 of file stringtree.hpp.
Public Types | |
using | CharacterType = TChar |
using | NameStringType = ATMP_IF_T_F((TLocalCapacity > 0), strings::TLocalString< TChar ALIB_COMMA TLocalCapacity >, strings::TString< TChar >) |
Public Static Methods | |
template<typename TTree > | |
static void | FreeNode (TTree &tree, typename TTree::Node &node) |
template<typename TTree > | |
static void | InitializeNode (TTree &tree, typename TTree::Node &node) |
using CharacterType = TChar |
The character type that the StringTree uses for child name and path strings.
Definition at line 87 of file stringtree.hpp.
using NameStringType = ATMP_IF_T_F ( (TLocalCapacity > 0), strings::TLocalString<TChar ALIB_COMMA TLocalCapacity>, strings::TString <TChar> ) |
The string type of a node's name.
Definition at line 92 of file stringtree.hpp.
|
inlinestatic |
This implementation frees the dynamically allocated memory of the node's name.
TTree | The type of the templated instantiation of struct detail::StringTreeBase that this method is invoked by. |
tree | The instance of struct detail::StringTreeBase that invokes this method. Any member may be accessed, including nodeTable which contains the MonoAllocator that the tree uses for the allocation of nodes. |
node | The node that is to be removed. Allows access to the key and custom value data. While the parent and sibling nodes are likewise accessible, it is strictly forbidden to modify those. |
Definition at line 140 of file stringtree.hpp.
|
inlinestatic |
This implementation copies the node's name to a dynamically allocated piece of heap memory.
TTree | The type of the templated instantiation of struct detail::StringTreeBase that this method is invoked by. |
tree | The instance of struct detail::StringTreeBase that invokes this method. Any member may be accessed, including nodeTable which contains the MonoAllocator that the tree uses for the allocation of nodes. |
node | The node that was just created. Allows access to the key and custom value data. While the parent and sibling nodes are likewise accessible, it is strictly forbidden to modify those. |
Definition at line 111 of file stringtree.hpp.