OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
osvr::util::tree::TreeNode< ValueType > Singleton Reference

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

#include <osvr/Util/TreeNode.h>

Inherits noncopyable, and operators< 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. Does not confer ownership.
 
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.
 
std::string const & getName () const
 Gets the name of the current node. This will be empty if and only if this is the root.
 
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.
 
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>
singleton 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:

  • All non-root nodes are named, and children may only be created attached to a parent.
  • All children of a given node are uniquely named.
  • Node names are immutable.
  • Contained values are mutable.
  • Traversal is provided for by templated visit methods that accept a functor.
  • A "get or create" method is provided that guarantees the return a child of the given name (default-constructing one if it doesn't exist)

Definition at line 72 of file TreeNode.h.

Member Function Documentation

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.

Definition at line 209 of file TreeNode.h.

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.

Definition at line 223 of file TreeNode.h.

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

Definition at line 291 of file TreeNode.h.

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.

Definition at line 141 of file TreeNode.h.

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.

Definition at line 162 of file TreeNode.h.


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