|
|
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.
|
| |
|
bool | dataEmpty () const |
| |
|
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 |
| | Iterator interface enables for-each type iteration.
|
| |
|
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 |
| | Return a reference to node data.
|
| |
| | operator node_data_t & () |
| | Return a reference to node data.
|
| |
| 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 node has empty data and no children.
|
| |
|
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 |
| |
| void | initChild (tree_t &) const |
| | Means for automatically setting something, for example the type of a node.
|
| |
| tree_t & | addChild () |
| | Add a child with an automatically generated key (path element).
|
| |
| tree_t & | addChild (const key_t &key) |
| | Ensure that a child node with given key exists. For MULTIPLE, always add one.
|
| |
| template<typename E > |
| tree_t & | addChild (const E &key) |
| | Converts argument to std:string and calls addChild()
|
| |
|
tree_t & | prependChild () |
| | Push in the front. This is only available for unordered trees.
|
| |
| template<typename E > |
| tree_t & | prependChild (const E &key) |
| | Converts argument to std:string and calls addChild()
|
| |
|
tree_t & | prependChild (const key_t &key) |
| |
|
tree_t & | operator++ () |
| | Shorthand for prependChild().
|
| |
|
tree_t & | operator++ (int) |
| | Shorthand for appendChild().
|
| |
| 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?)
|
| |
|
void | swapData (node_data_t &node) |
| | User should redefine (implement) this function for applied node types.
|
| |
template<class T, bool EXCLUSIVE = false, class P = drain::Path<std::string,'/'>>
class drain::DRAIN_TREE_NAME< T, EXCLUSIVE, P >
A templated class for directed rooted trees.
This file provides templates of for basic types of trees (directed rooted trees):
- OrderedTree – std::map<>
- OrderedMultiTree – std::multimap
- UnorderedTree – std::list
- UnorderedMultiTree – std::list
- Template Parameters
-
| 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:
- clear() – resetting the data to default initial (empty) value.
- empty() – returning true if the data is empty, or can be identified with empty.
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:
- inclusive (implicit, default) – each node may contain data and child nodes.
- exclusive – each node may contain data or child nodes, but not both. In the code, both data and children exist as members but in exclusive trees data is automatically cleared if children are added, and inversely, chilren are cleared (removed) if data is assigned.
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:
OrderedTree<std::string> tree;
t["first"] = "Hello!";
t["second"] = "Another greeting...";
As the operator[] returns a reference, it may be used recursively:
OrderedTree<std::string> & subTree1 = t["first"]["child"]["grandChild"];
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:
OrderedTree<std::string> & subTree = t("first/child/grandChild");
One may iterate the children directly:
for (auto & entry: tree){
std::cout << entry.first << ':' << entry.second << '\n';
}
Each node contains data of type T. It may be unused (empty), that is, a node can be used only as a branching point.
OrderedTree<std::string> t;
t.data = "Hello world";
std::string s = t;
(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:
Tree<std::string> t;
t = "Hello world";
Tree<std::string> &r = t;
std::string &s = t;
- Template Parameters
-
| T | – node data type |
| EXCLUSIVE | - a node may contain either data or children but not both. |