SpatiumLib
Public Member Functions | Protected Attributes | List of all members
spatium::idx::TreeNode< G > Class Template Reference

Node in a Tree. More...

#include <TreeNode.h>

Collaboration diagram for spatium::idx::TreeNode< G >:
Collaboration graph
[legend]

Public Member Functions

 TreeNode (std::weak_ptr< TreeNode< G >> parent=std::weak_ptr< TreeNode< G >>(), size_t estimatedChildCount=0)
 Constructor. More...
 
 TreeNode (const G &object, std::weak_ptr< TreeNode< G >> parent=std::weak_ptr< TreeNode< G >>(), size_t estimatedChildCount=0)
 Constructor. More...
 
bool hasChildren ()
 
size_t childCount () const
 Get child count. More...
 
std::shared_ptr< TreeNode< G > > child (size_t index) const
 Get a child. More...
 
std::shared_ptr< TreeNode< G > > addChild (const std::shared_ptr< TreeNode< G >> &parentSharedPtr, const G &object)
 Add child node. More...
 
G & object ()
 Set the object. More...
 
void setObject (const G &object)
 Get the object. More...
 

Protected Attributes

std::weak_ptr< TreeNode< G > > m_parent
 
std::vector< std::shared_ptr< TreeNode< G > > > m_children
 
m_object
 

Detailed Description

template<typename G>
class spatium::idx::TreeNode< G >

Node in a Tree.

TreeNode is a node in a Tree. Each node can have any number of children. A TreeNode is a container for a single object. The type of this object is passed as template argument.

Constructor & Destructor Documentation

◆ TreeNode() [1/2]

template<typename G>
spatium::idx::TreeNode< G >::TreeNode ( std::weak_ptr< TreeNode< G >>  parent = std::weak_ptr<TreeNode<G>>(),
size_t  estimatedChildCount = 0 
)
inline

Constructor.

Parameters
[in]parentParent node
[in]estimatedChildCountEstimated child count. Will allocate memory for the child references in advance to prevent later reallocation.

◆ TreeNode() [2/2]

template<typename G>
spatium::idx::TreeNode< G >::TreeNode ( const G &  object,
std::weak_ptr< TreeNode< G >>  parent = std::weak_ptr<TreeNode<G>>(),
size_t  estimatedChildCount = 0 
)
inline

Constructor.

Parameters
[in]objectObject for node
[in]parentParent node
[in]estimatedChildCountEstimated child count. Will allocate memory for the child references in advance to prevent later reallocation.

Member Function Documentation

◆ addChild()

template<typename G>
std::shared_ptr<TreeNode<G> > spatium::idx::TreeNode< G >::addChild ( const std::shared_ptr< TreeNode< G >> &  parentSharedPtr,
const G &  object 
)
inline

Add child node.

Parameters
[in]parentSharedPtrParent node (this object) as shared pointer.
[in]objectObject
Returns
Created child node

◆ child()

template<typename G>
std::shared_ptr<TreeNode<G> > spatium::idx::TreeNode< G >::child ( size_t  index) const
inline

Get a child.

Parameters
[in]indexChild index
Returns
Child or nullptr

◆ childCount()

template<typename G>
size_t spatium::idx::TreeNode< G >::childCount ( ) const
inline

Get child count.

Returns
Child count

◆ hasChildren()

template<typename G>
bool spatium::idx::TreeNode< G >::hasChildren ( )
inline
Returns
True when child count > 0, otherwise false.

◆ object()

template<typename G>
G& spatium::idx::TreeNode< G >::object ( )
inline

Set the object.

◆ setObject()

template<typename G>
void spatium::idx::TreeNode< G >::setObject ( const G &  object)
inline

Get the object.

Member Data Documentation

◆ m_children

template<typename G>
std::vector<std::shared_ptr<TreeNode<G> > > spatium::idx::TreeNode< G >::m_children
protected

◆ m_object

template<typename G>
G spatium::idx::TreeNode< G >::m_object
protected

◆ m_parent

template<typename G>
std::weak_ptr<TreeNode<G> > spatium::idx::TreeNode< G >::m_parent
protected

The documentation for this class was generated from the following file: