|
libyuni
|
A generic N-ary tree class. More...
#include <treeN.h>


Public Types | |
| typedef T | Type |
| The real type. | |
| typedef T | Node |
| Node. | |
| typedef TreeN< T, TP, ChckP, ConvP > | TreeNNode |
| The template class tree node. | |
| typedef TP< TreeNNode > | ThreadingPolicy |
| The threading policy. | |
| typedef SmartPtr< Node, Policy::Ownership::COMReferenceCounted, ChckP, ConvP > | PtrThreadSafe |
| A thread-safe node type. | |
| typedef SmartPtr< Node, Policy::Ownership::COMReferenceCounted, ChckP, ConvP > | PtrSingleThreaded |
| A default node type. | |
| typedef Static::If< ThreadingPolicy::threadSafe, PtrThreadSafe, PtrSingleThreaded >::ResultType | Ptr |
| Pointer to a node. | |
| typedef Ptr::StoragePolicy | StoragePolicy |
| The Storage policy. | |
| typedef Ptr::OwnershipPolicy | OwnershipPolicy |
| The Ownership policy. | |
| typedef Ptr::ConversionPolicy | ConversionPolicy |
| The Conversion policy. | |
| typedef Ptr::CheckingPolicy | CheckingPolicy |
| The Checking policy. | |
| typedef Ptr::ConstnessPolicy | ConstnessPolicy |
| The Constness policy. | |
| typedef Ptr::ConstSmartPtrType | ConstPtr |
| A const pointer. | |
| typedef Ptr::NonConstSmartPtrType | NonConstPtr |
| A non-const pointer. | |
| typedef uint | SizeType |
| Size. | |
| typedef int | SignedSizeType |
| Size (signed) | |
| typedef std::vector< Ptr > | Vector |
| A vector of nodes (std::vector) | |
| typedef std::list< Ptr > | List |
| A list of nodes (std::list) | |
Iterators | |
| typedef IIterator< Private::Core::Tree::ChildIterator< Node >, false > | iterator |
| typedef IIterator< Private::Core::Tree::ChildIterator< Node >, true > | const_iterator |
| typedef IIterator< Private::Core::Tree::DepthPrefixIterator< Node >, false > | depth_prefix_iterator |
| typedef IIterator< Private::Core::Tree::DepthPrefixIterator< Node >, true > | const_depth_prefix_iterator |
| typedef IIterator< Private::Core::Tree::DepthInfixIterator< Node >, false > | depth_infix_iterator |
| typedef IIterator< Private::Core::Tree::DepthInfixIterator< Node >, true > | const_depth_infix_iterator |
Public Member Functions | |
| std::ostream & | print (std::ostream &out, bool recursive=true, uint level=0) |
| Print the entire tree to the output stream. More... | |
Constructors & Destructor | |
| TreeN () | |
| Default constructor. | |
| virtual | ~TreeN () |
| Destructor. | |
Parent of the node | |
| Ptr | parent () |
| Get the parent of the node. | |
| Ptr | parent () const |
| Get the parent of the node. | |
| void | parent (Ptr newParent) |
| ReAttach to another parent. | |
| void | detachFromParent () |
| Detach the node from its parent. | |
Adding | |
| void | append (Ptr &node) |
| Append a child node to the end of the list. More... | |
| void | append (T *node) |
| void | push_back (Ptr &node) |
| Append a child node at the end. More... | |
| void | push_back (T *node) |
| void | push_front (Ptr &node) |
| Append a child node at the begining. More... | |
| void | push_front (T *node) |
Removing | |
| void | clear () |
| Remove all children. | |
| bool | remove (Ptr &node) |
| Remove a child node. More... | |
| bool | remove (const SizeType index) |
| Remove the n-th child of the node. More... | |
| bool | remove (const SignedSizeType index) |
Searching | |
| iterator | begin () |
| Return iterator to the first child of the node. | |
| const const_iterator | begin () const |
| depth_prefix_iterator | depth_prefix_begin () |
| const const_depth_prefix_iterator | depth_prefix_begin () const |
| iterator | end () |
| Return iterator to the last child of the node. | |
| const const_iterator | end () const |
| depth_prefix_iterator | depth_prefix_end () |
| const const_depth_prefix_iterator | depth_prefix_end () const |
| Ptr | find (const SizeType index) |
| Find the n-th child of the node. More... | |
| Ptr | find (const SignedSizeType index) |
| bool | empty () const |
| Get if the node has children. | |
| SizeType | count () const |
| SizeType | size () const |
| Alias for count() | |
| Ptr | firstChild () |
| Get the first child. | |
| const Ptr | firstChild () const |
| Ptr | lastChild () |
| Get the last child. | |
| const Ptr | lastChild () const |
| Ptr | previousSibling () |
| Get the previous sibling. | |
| const Ptr | previousSibling () const |
| Ptr | nextSibling () |
| Get the next sibling. | |
| const Ptr | nextSibling () const |
Extra | |
| bool | leaf () const |
| Get if the node is a leaf. More... | |
| SizeType | depth () const |
| Computes the depth of this node. More... | |
| SizeType | treeHeight () |
| Computes the height from this node. More... | |
Comparisons | |
| bool | equals (const Ptr &node) const |
| Test if the current node is equals to another one. More... | |
Z-Order | |
| void | bringToFront () |
| Move the node to the end. More... | |
| void | sendToBack () |
| Move the node to the begining. More... | |
| void | invalidate () |
| Schedule an asynchronous update of the item (depending upon the implementation) | |
| bool | isInvalidated () |
| Get if the item is invalidated (depending upon the implementation) | |
Operators | |
| Node & | operator+= (Ptr &node) |
| Append a child at the end. | |
| Node & | operator+= (T *node) |
| Append a child at the end. | |
| Node & | operator-= (Ptr &node) |
| Remove a child node. | |
| Node & | operator<< (Ptr &node) |
| Append a child at the end. | |
| Node & | operator<< (T *node) |
| Append a child at the end. | |
| Node & | operator== (const Ptr &node) const |
| Comparison with another node. | |
| Ptr | operator[] (const SizeType index) |
| Get the n-th child of the node. More... | |
| Ptr | operator[] (const SignedSizeType index) |
| Get the n-th child of the node. More... | |
Pointer management | |
| void | addRef () const |
| Increment the internal reference counter. | |
| bool | release () const |
| Decrement the internal reference counter. | |
Protected Member Functions | |
| virtual void | invalidateWL () |
| Invalidate the item. | |
| virtual bool | isInvalidatedWL () |
| Get if the item is invalidated. | |
| virtual void | printBeginWL (std::ostream &out, uint level) const |
| (only used for debugging) | |
| virtual void | printEndWL (std::ostream &out, uint level) const |
| (only used for debugging) | |
| void | clearWL () |
| Remove all children. | |
| void | pushBackWL (Ptr &node) |
| Append a child to the end of the list. | |
| void | pushFrontWL (Ptr &node) |
| Append a child to the end of the list. | |
| void | detachFromParentWL () |
| Detach from the parent. More... | |
| Ptr | findFromIndexWL (const SizeType index) |
| Find a child node from its index (slow) | |
Protected Attributes | |
| Node * | pParent |
| Parent (weak pointer) | |
| SizeType | pChildrenCount |
| How many children do we have ? | |
| Ptr | pPreviousSibling |
| The previous sibling. | |
| Ptr | pNextSibling |
| The next sibling. | |
| Ptr | pFirstChild |
| The first child. | |
| Ptr | pLastChild |
| The last child. | |
A generic N-ary tree class.
This class provides a generic and thread-safe implementation for N-ary trees. It behaves like an STL container class.
Example of a pseudo XML tree :
SingleThreaded policy is not used, it is safe to manipulate a node from everywhere.Ptr typedef.| T | The real type of the tree class (CRTP) |
| TP | The Threading policy |
| ChckP | The Checking policy |
| ConvP | The Conversion policy |
| void Yuni::Core::TreeN< T, TP, ChckP, ConvP >::append | ( | Ptr & | node | ) |
Append a child node to the end of the list.
| node | The new child node |
| void Yuni::Core::TreeN< T, TP, ChckP, ConvP >::bringToFront | ( | ) |
Move the node to the end.
This method is especially useful when manipulating items on a layer. When iterating over all children, the last one can be considered as the last drawn thus the first visible item for the user.
| TreeN< T, TP, ChckP, ConvP >::SizeType Yuni::Core::TreeN< T, TP, ChckP, ConvP >::depth | ( | ) | const |
Computes the depth of this node.
The depth of a node n is the length of the path from the root to the node. The set of all nodes at a given depth is sometimes called a level of the tree. The root node is at depth zero.
|
inlineprotected |
Detach from the parent.
|
inline |
Test if the current node is equals to another one.
| Ptr Yuni::Core::TreeN< T, TP, ChckP, ConvP >::find | ( | const SizeType | index | ) |
Find the n-th child of the node.
This method is only provided for convenience reasons. This method is slow and should be used with care.
| index | Index of the child node to remove (zero-based) and this value can be out of bounds |
|
inline |
Get if the node is a leaf.
A leaf is merely a node without any children
|
inline |
Get the n-th child of the node.
|
inline |
Get the n-th child of the node.
| std::ostream & Yuni::Core::TreeN< T, TP, ChckP, ConvP >::print | ( | std::ostream & | out, |
| bool | recursive = true, |
||
| uint | level = 0 |
||
| ) |
Print the entire tree to the output stream.
Should only be used for debugging purposes only
|
inline |
Append a child node at the end.
| node | The new child node |
|
inline |
Append a child node at the begining.
| node | The new child node |
|
inline |
Remove a child node.
| bool Yuni::Core::TreeN< T, TP, ChckP, ConvP >::remove | ( | const SizeType | index | ) |
Remove the n-th child of the node.
This method is only provided for convenience reasons. This method is slow and should be used with care.
| index | Index of the child node to remove (zero-based) and this value can be out of bounds |
| void Yuni::Core::TreeN< T, TP, ChckP, ConvP >::sendToBack | ( | ) |
Move the node to the begining.
This method is especially useful when manipulating items on a layer When iterating over all children, the first one can be considered as the first drawn thus the last visible item for the user.
| TreeN< T, TP, ChckP, ConvP >::SizeType Yuni::Core::TreeN< T, TP, ChckP, ConvP >::treeHeight | ( | ) |
Computes the height from this node.
The height of a tree is the length of the path from the root to the deepest node in the tree. A (rooted) tree with only a node (the root) has a height of zero.
1.8.13