#include <node_tree.hpp>
Public Types | |
typedef NodeT | node_type |
typedef ::s11n::node_traits< node_type > | traits_type |
typedef traits_type::child_list_type | list_type |
Public Member Functions | |
node_tree (node_type *root) | |
Ownership of node does not change, and root should outlive this object, or at least live until clime_tree() is called with another root. | |
node_tree () | |
~node_tree () | |
size_t | climb_tree (node_type *node, size_t internal_use=0) |
Maps relations of parens to children in node tree, using the given root node. | |
node_type * | parent_of (node_type &node) |
Returns the parent node of node, of 0 if no parent was mapped by climb_tree(). | |
list_type & | children_of (node_type &node) |
A convenience wrapper around traits_type::children(node). | |
bool | take_node (node_type *node) |
Removes the given node from the tree. | |
bool | reparent (node_type *n, node_type *newp) |
Reparents node n to parent node newp. | |
node_type * | root () |
Returns this object's root node. | |
void | clear () |
Clears this object's data and sets its root() node to 0. |
NodeT must usable via s11n::node_traits<NodeT>.
An example use for this class: the s11nbrowser app uses it to assist in the mapping of s-nodes to UI elements and for cutting/pasting subtrees of nodes.
Definition at line 27 of file node_tree.hpp.
typedef NodeT s11n::util::node_tree< NodeT >::node_type |
Definition at line 30 of file node_tree.hpp.
typedef ::s11n::node_traits< node_type > s11n::util::node_tree< NodeT >::traits_type |
Definition at line 31 of file node_tree.hpp.
typedef traits_type::child_list_type s11n::util::node_tree< NodeT >::list_type |
Definition at line 51 of file node_tree.hpp.
s11n::util::node_tree< NodeT >::node_tree | ( | node_type * | root | ) | [inline, explicit] |
Ownership of node does not change, and root should outlive this object, or at least live until clime_tree() is called with another root.
root may be 0.
Definition at line 40 of file node_tree.hpp.
References s11n::util::node_tree< NodeT >::climb_tree().
s11n::util::node_tree< NodeT >::node_tree | ( | ) | [inline] |
Definition at line 45 of file node_tree.hpp.
s11n::util::node_tree< NodeT >::~node_tree | ( | ) | [inline] |
Definition at line 48 of file node_tree.hpp.
size_t s11n::util::node_tree< NodeT >::climb_tree | ( | node_type * | node, | |
size_t | internal_use = 0 | |||
) | [inline] |
Maps relations of parens to children in node tree, using the given root node.
Returns the cumulative number of nodes traversed.
Ownership of node does not change, so node must outlive this object or, if it is destroyed first, climb_tree() must be called with another node before any other API of this class is called.
If node == 0 then this object's data is cleared and 0 is returned.
The second parameter is for internal use: never pass a value, or pass 0 if you must pass something.
Definition at line 70 of file node_tree.hpp.
References s11n::node_traits< NodeT >::children(), and s11n::util::node_tree< NodeT >::clear().
Referenced by s11n::util::node_tree< NodeT >::node_tree().
node_type* s11n::util::node_tree< NodeT >::parent_of | ( | node_type & | node | ) | [inline] |
Returns the parent node of node, of 0 if no parent was mapped by climb_tree().
The caller does not own the pointer: it is owned by its own parent. If it has no parent, then "someone else" is assumed to have ownership of it (whoever gave it to this object, presumably).
Definition at line 104 of file node_tree.hpp.
list_type& s11n::util::node_tree< NodeT >::children_of | ( | node_type & | node | ) | [inline] |
A convenience wrapper around traits_type::children(node).
Definition at line 115 of file node_tree.hpp.
References s11n::node_traits< NodeT >::children().
bool s11n::util::node_tree< NodeT >::take_node | ( | node_type * | node | ) | [inline] |
Removes the given node from the tree.
If it returns true, the caller owns node, otherwise ownership is unchanged.
Definition at line 125 of file node_tree.hpp.
References s11n::node_traits< NodeT >::children().
bool s11n::util::node_tree< NodeT >::reparent | ( | node_type * | n, | |
node_type * | newp | |||
) | [inline] |
Reparents node n to parent node newp.
Both n and newp are assumed to be under root().
n may not be root() and neither n nor newp may be 0.
Returns true on success, false on error.
If this function returns false then ownership is unchanged and there are no side effects. If it returns true, ownership of n *typically* moves to newp. That is, newp will delete n when newp is destroyed. More specifically, that depends on node_type's implementation, but s11n::data_node and s11n::s11n_node both work that way.
Definition at line 172 of file node_tree.hpp.
References s11n::node_traits< NodeT >::children().
node_type* s11n::util::node_tree< NodeT >::root | ( | ) | [inline] |
Returns this object's root node.
Ownership is not changed.
Definition at line 191 of file node_tree.hpp.
void s11n::util::node_tree< NodeT >::clear | ( | ) | [inline] |
Clears this object's data and sets its root() node to 0.
This object does not own root() and therefor does not delete it.
Definition at line 198 of file node_tree.hpp.
Referenced by s11n::util::node_tree< NodeT >::climb_tree().