StRoot
1
|
#include <StiCompositeTreeNode.h>
Public Types | |
typedef vector < StiCompositeTreeNode * > | vec_type |
For internal convenience. | |
typedef vector < StiCompositeTreeNode * > | StiCompositeTreeNodeVector |
For internal convenience. | |
Public Member Functions | |
StiCompositeTreeNode () | |
We provide only a default constructor. More... | |
virtual | ~StiCompositeTreeNode () |
Default Destructor. | |
void | reset () |
void | unset () |
void | setName (const string &) |
Set the name of the node. | |
void | setOrderKey (const StiOrderKey &) |
Set the order-key for the node. | |
void | setData (T *) |
Set the data to be hung on the node. More... | |
const string & | getName () const |
Return the name of the node. | |
unsigned int | getChildCount () const |
Return the number of children that belong to this node. | |
StiCompositeTreeNode * | getParent () const |
Return a (non-const!) pointer to the parent of this node. | |
const StiOrderKey & | getOrderKey () const |
Return a reference to the the orderkey of this node. | |
T * | getData () const |
Return a (non-const!) pointer to the data hung on this node. | |
virtual void | add (StiCompositeTreeNode *) |
Add a child to this node. More... | |
vec_type::iterator | whereInParent () |
Provide the iterator into the parent that can be dereferenced to get this node. | |
vec_type::iterator | begin () |
Provide random access iterator to the beginning of the vector of children. | |
vec_type::iterator | end () |
Provide random access iterator to the end of the vector of children. | |
vec_type::const_iterator | begin () const |
Provide const_iterator to the beginning of the vector of children. | |
vec_type::const_iterator | end () const |
Provied const_iterator to the end of the vector of children. | |
vec_type::reverse_iterator | rbegin () |
Provide reverse iterator to the beginning of the vector of children. | |
vec_type::reverse_iterator | rend () |
Provide reverse iterator to the end of the vector of children. | |
vec_type::const_reverse_iterator | rbegin () const |
Provide const_reverse_iterator tot he beginning of the vector of children. | |
vec_type::const_reverse_iterator | rend () const |
Provide const_reverse_iterator to the end of the vector of children. | |
StiCompositeTreeNode is a templated class that can be used to represent objects in a tree structure. The objects to be organized are stored as T* pointers by StiCompositeTreeNode and are accessed via getData() and setData(T*) methods. Additionaly, a StiCompositeTreeNode can have 0 or 1 parent and 0-n daughters. A node with no parent is called a root. A node with no daughters is called a leaf. Internally, the daughters treated as daughters stored in a vector. As such, StiCompositeTreeNode provides access (via STL iterators) to the bounds of the vector. This has the consequence that traversal of the tree can be performed via recursive calls to the STL algorithms. For such cases one merely needs to define funtors that either perform some action given a node (e.g., stream the node to screen), or evaluate whether a given node (or a comparison between two nodes) satisfies some logical condition. For more, see example in StlUtilities.h.
StiCompositeTreeNode is a special tree-node class in that it was designed with the ability to store daughters in a sorted order, which is especially useful for efficient traversal through the tree. One could manually sort the tree by the data stored, or one can use the StiOrderKey typedef. Currently this typedef is set to a double, and one can eager cache the sort-key to avoid calls into the data structure. Because StiCompositeTreeNode provides random-access iterators into the daughters, STL algorithms can easily be used (recursively) to perform tasks on an entire tree (e.g., sort, find, for_each). Many of these are already implemented in StlUtilities.h.
see also: StiCompositeLeafIterator
Definition at line 94 of file StiCompositeTreeNode.h.
StiCompositeTreeNode< T >::StiCompositeTreeNode | ( | ) |
We provide only a default constructor.
When the node is created all members are initialized to deafult values (namely 0 or null) and one must then set all information by hand.
Definition at line 205 of file StiCompositeTreeNode.h.
|
virtual |
Add a child to this node.
For the sake of consistency in the parent-child relationship of one node to another, you will find no public method setParent(). Instead, this task is performed internally by a call to add(). Thus, once a node2 is added to node1 via node1->add(node2), node1 is automatically set as the parent of node2, and no intervention by the user is necessary.
Additionally, node2 cannot be added as a daughter to node1 if node2 is already a daughter of node1. In such a case, an internal check in the add() method will recognize the situation and return with no action taken.
Definition at line 281 of file StiCompositeTreeNode.h.
Referenced by StiDetectorTreeBuilder::buildRoot(), and StiDetectorTreeBuilder::hangWhere().
|
inline |
Set the data to be hung on the node.
The pointer to data (T* mData) defaults to 'null' on creation. If no call to setData() is made, then mData remains set to 'null'.
Definition at line 233 of file StiCompositeTreeNode.h.
Referenced by StiDetectorTreeBuilder::addToTree().