OSVR-Core
Public Types | Public Member Functions | Static Public Member Functions | List of all members
osvr::util::tree::TreeNode< ValueType > Class Template Reference

A node in a generic tree, which can contain an object by value. More...

#include <TreeNode.h>

Inheritance diagram for osvr::util::tree::TreeNode< ValueType >:

Public Types

typedef TreeNode< ValueType > type
 This template instantiation's type.
 
typedef TreeNodePointer< ValueType >::type ptr_type
 The pointer for holding this template instantiation - used primarily/only in holding the root node.
 
typedef typeparent_ptr_type
 The pointer for accessing a node's parent. More...
 
typedef ValueType value_type
 The contained value type.
 

Public Member Functions

typegetOrCreateChildByName (std::string const &name)
 Get the named child, creating it if it doesn't exist.
 
type const & getChildByName (std::string const &name) const
 Get the named child, throwing NoSuchChild if it doesn't exist. More...
 
std::string const & getName () const
 Gets the name of the current node. More...
 
bool isRoot () const
 Is the current node a root node?
 
parent_ptr_type getParent () const
 Gets the node's parent, or nullptr if no parent (root node)
 
bool hasChildren () const
 Does the node have any children? More...
 
size_t numChildren () const
 How many children does the node have?
 
value_typevalue ()
 Reference accessor for contained value.
 
value_type const & value () const
 Const reference accessor for contained value.
 
template<typename F >
void visitChildren (F &visitor)
 Generic visitation method that calls a functor on each of the children in an undefined order. More...
 
template<typename F >
void visitConstChildren (F &visitor) const
 Generic constant visitation method that calls a functor on each of the children (as const) in an undefined order. More...
 
template<typename F >
void visitChildren (F &visitor) const
 Generic constant visitation method that calls a functor on each of the children in an undefined order. More...
 
bool operator== (const type &x) const
 Equality comparison operator - tests object identity.
 

Static Public Member Functions

static typecreate (TreeNode &parent, std::string const &name)
 Create a child tree node. More...
 
static typecreate (TreeNode &parent, std::string const &name, value_type const &val)
 Create a child tree node with a value. More...
 
static ptr_type createRoot ()
 Create a root.
 
static ptr_type createRoot (value_type const &val)
 Create a root with a value.
 

Detailed Description

template<typename ValueType>
class osvr::util::tree::TreeNode< ValueType >

A node in a generic tree, which can contain an object by value.

Template Parameters
ValueTypeThe contained value type: must be default-constructible.

Key features:

Todo:
methods to remove a child (by pointer and by name)

Member Typedef Documentation

§ parent_ptr_type

template<typename ValueType>
typedef type* osvr::util::tree::TreeNode< ValueType >::parent_ptr_type

The pointer for accessing a node's parent.

Does not confer ownership.

Member Function Documentation

§ create() [1/2]

template<typename ValueType >
TreeNode< ValueType > & osvr::util::tree::TreeNode< ValueType >::create ( TreeNode< ValueType > &  parent,
std::string const &  name 
)
inlinestatic

Create a child tree node.

Exceptions
std::logic_errorif a child of that name already exists or if the name provided is empty.

§ create() [2/2]

template<typename ValueType >
TreeNode< ValueType > & osvr::util::tree::TreeNode< ValueType >::create ( TreeNode< ValueType > &  parent,
std::string const &  name,
value_type const &  val 
)
inlinestatic

Create a child tree node with a value.

Exceptions
std::logic_errorif a child of that name already exists or if the name provided is empty.

§ getChildByName()

template<typename ValueType >
TreeNode< ValueType > const & osvr::util::tree::TreeNode< ValueType >::getChildByName ( std::string const &  name) const
inline

Get the named child, throwing NoSuchChild if it doesn't exist.

§ getName()

template<typename ValueType >
std::string const & osvr::util::tree::TreeNode< ValueType >::getName ( ) const
inline

Gets the name of the current node.

This will be empty if and only if this is the root.

§ hasChildren()

template<typename ValueType >
bool osvr::util::tree::TreeNode< ValueType >::hasChildren ( ) const
inline

Does the node have any children?

May be faster than testing numChildren() != 0

§ visitChildren() [1/2]

template<typename ValueType>
template<typename F >
void osvr::util::tree::TreeNode< ValueType >::visitChildren ( F &  visitor)
inline

Generic visitation method that calls a functor on each of the children in an undefined order.

Using indices and re-evaluating size each time to safely handle visitors that add things.

§ visitChildren() [2/2]

template<typename ValueType>
template<typename F >
void osvr::util::tree::TreeNode< ValueType >::visitChildren ( F &  visitor) const
inline

Generic constant visitation method that calls a functor on each of the children in an undefined order.

Todo:
does this overload clutter the interface and reduce clarity between const and non-const visitors?

§ visitConstChildren()

template<typename ValueType>
template<typename F >
void osvr::util::tree::TreeNode< ValueType >::visitConstChildren ( F &  visitor) const
inline

Generic constant visitation method that calls a functor on each of the children (as const) in an undefined order.


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