![]() |
|
A templated class for directed rooted trees. More...
#include <Tree.h>

Public Types | |
| typedef drain::DRAIN_TREE_NAME< T, EXCLUSIVE, P > | tree_t |
| typedef T | node_data_t |
| typedef P | path_t |
| typedef path_t::elem_t | key_t |
| typedef path_t::elem_t | path_elem_t |
| typedef std::pair< key_t, tree_t > | pair_t |
| typedef container_t::iterator | iterator |
| typedef container_t::const_iterator | const_iterator |
| typedef std::pair< key_t, node_data_t > | node_pair_t |
| Experimental. Given pair<elem, data> assigns child[elem] = data;. | |
Public Member Functions | |
| typedef | DRAIN_TREE_CONTAINER (key_t, tree_t) container_t |
| DRAIN_TREE_NAME () | |
| Default constructor. | |
| DRAIN_TREE_NAME (const node_data_t &data) | |
| Copy constructor; copy only node data at the root. | |
| DRAIN_TREE_NAME (const DRAIN_TREE_NAME &t) | |
| Copy constructor; copy only node data at the root. | |
| virtual bool | hasMultipleData () const |
| virtual const node_data_t & | getData () const |
| virtual node_data_t & | getData () |
| virtual const node_data_t & | getData (const key_t &key) const |
| virtual node_data_t & | getData (const key_t &key) |
| container_t::const_iterator | begin () const |
| Child iterator pointing to the first child. | |
| container_t::const_iterator | end () const |
| Child iterator pointing beyond the last child. | |
| container_t::iterator | begin () |
| Child iterator pointing to the first child. | |
| container_t::iterator | end () |
| Child iterator end. | |
| tree_t & | operator= (const tree_t &t) |
| Copies the data of another node. Does not copy the children. | |
| template<class T2 > | |
| tree_t & | operator= (const T2 &v) |
| Assigns value to contents. | |
| tree_t & | operator= (const char *str) |
| template<typename K , typename V > | |
| tree_t & | operator= (std::initializer_list< std::pair< K, V > > l) |
| Assign tree structure (of depth one). | |
| tree_t & | operator= (std::initializer_list< std::pair< const char *, const Variable > > l) |
| Assign tree structure (of depth one). | |
| template<typename V > | |
| tree_t & | operator= (const std::initializer_list< V > &l) |
| Assign data. | |
| tree_t & | operator<< (const node_pair_t &entry) |
| Experimental. Given pair(elem, data) assigns child[elem] = data;. | |
| operator const node_data_t & () const | |
| operator node_data_t & () | |
| tree_t & | operator[] (const key_t &key) |
| Child addressing operator. | |
| const tree_t & | operator[] (const key_t &key) const |
| Child addressing operator. | |
| template<class K > | |
| tree_t & | operator[] (const K &key) |
| NEW 2025 templated child addressing operator. | |
| template<class K > | |
| const tree_t & | operator[] (const K &key) const |
| NEW 2025 templated child addressing operator. | |
| tree_t & | operator() (const path_t &path) |
| Returns a descendant. Creates one if not existing already. | |
| template<class S > | |
| tree_t & | operator() (const S &arg) |
| Returns a descendant. Creates one if not existing already. | |
| tree_t & | operator() (const char *arg) |
| Redirects the call to operator()(const std::string & arg) . | |
| const tree_t & | operator() (const path_t &path) const |
| Returns a descendant if that exists, else returns an empty node. Otherwise like non-const counterpart. | |
| template<class S > | |
| const tree_t & | operator() (const S &arg) const |
| Returns a descendant if that exists, else returns an empty node. Otherwise like non-const counterpart. | |
| const tree_t & | operator() (const char *arg) const |
| Redirects the call to operator()(const std::string & arg) . | |
| void | clear () |
| Clear children and node data. | |
| void | clearData () |
| void | clearChildren () |
| Clears the children of this node. Does not clear data. | |
| void | erase (const path_t &path) |
| Deletes a descendant node and hence its subtrees. | |
| virtual const tree_t & | getEmpty () const |
| virtual bool | empty () const |
| Check if the tree structure is empty. | |
| bool | hasChildren () const |
| virtual int | hasChildren (const key_t &key) const |
| The number of children with name key. | |
| virtual bool | hasChild (const key_t &key) const |
Check if the tree node has a direct descendant with name key. | |
| template<typename K > | |
| bool | hasChild (const K &key) const |
| bool | hasPath (const path_t &path) const |
| virtual tree_t & | addChild (const key_t &key=key_t()) |
| Add a child node. If unordered and UNIQUE, reuse existing nodes. | |
| virtual tree_t & | retrieveChild (const key_t &key) |
| virtual const tree_t & | retrieveChild (const key_t &key) const |
| container_t & | getChildren () |
| Returns the map containing the children. | |
| const container_t & | getChildren () const |
| Returns the map containing the children. | |
| const node_data_t * | operator-> () const |
| Fast access to data, applied widely in TreeXML (HTML/SVG) | |
| node_data_t * | operator-> () |
| Fast access to data, applied widely in TreeXML (HTML/SVG) | |
| void | swap (tree_t &t) |
| Replace children (but no data?) | |
Static Public Member Functions | |
| static bool | isExclusive () |
| static bool | isMulti () |
| static bool | isOrdered () |
Public Attributes | |
| node_data_t | data |
| Contents (data) of the node. | |
Protected Member Functions | |
| bool | hasPath (typename path_t::const_iterator it, typename path_t::const_iterator eit) const |
| "Default implementation" of key conversion – the identity mapping. | |
| tree_t & | get (typename path_t::const_iterator it, typename path_t::const_iterator eit) |
| Returns a descendant. Creates one, if not present. | |
| const tree_t & | get (typename path_t::const_iterator it, typename path_t::const_iterator eit) const |
| Given the descendant pointed to by a given path segment. | |
Protected Attributes | |
| container_t | children |
Static Protected Attributes | |
| static const tree_t | emptyNode |
A templated class for directed rooted trees.
This file provides templates of for basic types of trees (directed rooted trees):
| T | - node type, containing user-designed data implementing clear(), size() and empty() for future compatibility. |
| EXCLUSIVE | - node can contains either data or children but not both (JSON-like convention) |
| P | - applied path structure, like std::list – must implement empty() both for path and keys (path elements) |
Data:
The nodes in a tree contain user defined data, the type of which is given as template T.
Currenty, data Concept is requires the following methods:
A tree is EXCLUSIVE, if a node contains either data or children. For example, a JSON tree is EXCLUSIVE and an XML tree is not (a tag can containg attributes (data) and inner tages (children).
Further, each type listed above has two variants:
Limitation: in OrderedTree the children are in a std::map, and threrefore each child of a node has a unique key. In UnorderedTree there may be children having the same key.
Addressing:
tree(<path>) return a descendant tree[<path_element>] returns childs only (complains separators, for some time)
Child nodes can be addressed with operator[] with std::string valued keys:
As the operator[] returns a reference, it may be used recursively:
Tree also recognizes a path separator, which is '/' by default. Hence, the node created in the above example could be likewise created or addressed as:
One may iterate the children directly:
Each node contains data of type T. It may be unused (empty), that is, a node can be used only as a branching point.
(Direct assignments to and from the node data has been supported, but is now disabled for c++ compatibility reasons.)
Also direct referencing of the node data is now disabled:
Obsolete: template C - path element comparison functor, should be compatible with Path<P>::key_t. #ifndef DRAIN_AMBIVALUE #define DRAIN_AMBIVALUE "0.1beta" template <class T, class K> class CombiValue { public:
typedef T data_t; typedef K key_t;
T data; CONSIDER! But Hi5Node heavy?
inline
~CombiValue(){};
/ True, if data is structured. virtual bool hasMultipleData() const = 0;
virtual const data_t & getData() const = 0; virtual data_t & getData() = 0; virtual const data_t & getData(const key_t &) const = 0; virtual data_t & getData(const key_t &) = 0;
}; #endif
| K | – key type |
| K | – key type |
|
inlinevirtual |
Add a child node. If unordered and UNIQUE, reuse existing nodes.
Behaviour of this function varies as follows:
key, if existskey, if exists, else create one.key and return it.
|
inline |
Clear children and node data.
|
inline |
|
inline |
|
inline |
|
inlineprotected |
Given the descendant pointed to by a given path segment.
|
inline |
Returns the map containing the children.
This is useful for example for map::swap ?
|
inlinevirtual |
GENERAL (independent from container type) Empty "default" node; typically initialized with empty data as well.
|
inlinevirtual |
Check if the tree node has a direct descendant with name key.
A multiple tree may have more than one children with the same name. With them, consider hasChildren(const key_t &key) .
|
inlinevirtual |
The number of children with name key.
Checks how many immediate descendants with name key exist.
A multiple tree may have more than one children with the same name.
With simple trees, use the faster hasChild(const key_t &key).
|
inlineprotected |
"Default implementation" of key conversion – the identity mapping.
Conversion of char array to key type, which itself should never be a char array. Mapping of keys of external type - for example an enumerated type - to native key_t type. Checks if there is a node with a given path name. Could be called hasDescendant; hence is like hasChild() but calls children recursively.
| eit | - end() |
|
inline |
Redirects the call to operator()(const std::string & arg) .
| arg | - by default, the path from the current node to the child node. |
|
inline |
Returns a descendant. Creates one if not existing already.
| path | - the path from the current node to the child node. |
This function, using native path_t type, should be reserved for this semantic by not redefining (specialising) this function in template classes.
|
inline |
Returns a descendant if that exists, else returns an empty node. Otherwise like non-const counterpart.
| path | - the path from the current node to the child node. |
This function, using native path_t type, should be reserved for this semantic by not redefining (specialising) this function in template classes.
|
inline |
Returns a descendant. Creates one if not existing already.
| path | - the path from the current node to the child node. |
This function, not using native path_t type, can be redefined in template classes. For example, an important attribute can be set using this method.
However, operator()(const char *arg) should be redefined to produce equivalent result with const string &arg.
|
inline |
Assign data.
If init list elements are not pairs, assign it to node data.
2025/01 experimental.
|
inline |
Assigns value to contents.
Assigns a value to contents. This may be redefined in derived classes. For example, assigning a value of certain class may cause adding a specific child element instead of assigning to data (the default, here).
|
inline |
Copies the data of another node. Does not copy the children.
Default use to reset a node (re-initialize its data).
|
inline |
Assign tree structure (of depth one).
Default implementation: assign new nodes (children).
Examples of overriding:
|
inline |
Assign tree structure (of depth one).
Default implementation: assign new nodes (children).
|
inline |
NEW 2025 templated child addressing operator.
Allows using EnumDict enums as keys, for example.
1.9.8