opensurgsim
Public Member Functions | Protected Member Functions | List of all members
SurgSim::DataStructures::TreeNode Class Referenceabstract

Basic tree node structure. More...

#include <TreeNode.h>

Inheritance diagram for SurgSim::DataStructures::TreeNode:
SurgSim::DataStructures::AabbTreeNode

Public Member Functions

 TreeNode ()
 Constructor. After construction, the node has no children, and the data is null.
 
virtual ~TreeNode ()
 Destructor.
 
void setData (std::shared_ptr< TreeData > data)
 Sets the data of this node. More...
 
const std::shared_ptr< TreeData > & getData () const
 
size_t getNumChildren () const
 
std::shared_ptr< TreeNode > & getChild (size_t index)
 Returns the specified child of this node. More...
 
void accept (TreeVisitor *visitor)
 Public entry point for visitor, currently this performs pre-order traversal of the tree. More...
 
bool operator== (const TreeNode &node) const
 Returns true if the nodes are equal; otherwise, returns false. More...
 
bool operator!= (const TreeNode &node) const
 Returns true if the nodes are not equal; otherwise, returns false. More...
 

Protected Member Functions

virtual bool isEqual (const TreeNode &node) const
 Returns true if the nodes are equal; otherwise, returns false. More...
 
virtual bool doAccept (TreeVisitor *visitor)=0
 Private function for use with the visitor pattern, this needs to be implemented to make the correct double dispatch call to the dynamic type of this class. More...
 
void setNumChildren (size_t numChildren)
 Sets the number of children of this node. More...
 
void addChild (const std::shared_ptr< TreeNode > &node)
 Add a child to this node. More...
 
void addChild (const std::shared_ptr< TreeNode > &&node)
 Add a child to this node. More...
 
void setChild (size_t index, const std::shared_ptr< TreeNode > &node)
 Set a specific child of this node. More...
 

Detailed Description

Basic tree node structure.

The nodes build up the structure of a Tree.

See also
Tree TreeData

Member Function Documentation

§ accept()

void SurgSim::DataStructures::TreeNode::accept ( TreeVisitor visitor)

Public entry point for visitor, currently this performs pre-order traversal of the tree.

Parameters
visitorThe visitor that wants to traverse the tree

§ addChild() [1/2]

void SurgSim::DataStructures::TreeNode::addChild ( const std::shared_ptr< TreeNode > &  node)
protected

Add a child to this node.

Parameters
nodeThe new child node.

§ addChild() [2/2]

void SurgSim::DataStructures::TreeNode::addChild ( const std::shared_ptr< TreeNode > &&  node)
protected

Add a child to this node.

Parameters
nodeThe new child node.

§ doAccept()

virtual bool SurgSim::DataStructures::TreeNode::doAccept ( TreeVisitor visitor)
protectedpure virtual

Private function for use with the visitor pattern, this needs to be implemented to make the correct double dispatch call to the dynamic type of this class.

Parameters
visitorThe visitor that is trying to traverse the tree.
Returns
true to indicate proceeding with the visitor, false indicates to abort the traversal.

Implemented in SurgSim::DataStructures::AabbTreeNode.

§ getChild()

std::shared_ptr< TreeNode > & SurgSim::DataStructures::TreeNode::getChild ( size_t  index)

Returns the specified child of this node.

Parameters
indexIndex of the child
Returns
Child at the specified index

§ getData()

const std::shared_ptr< TreeData > & SurgSim::DataStructures::TreeNode::getData ( ) const
Returns
The data of this node.

§ getNumChildren()

size_t SurgSim::DataStructures::TreeNode::getNumChildren ( ) const
Returns
The number of children of this node.

§ isEqual()

bool SurgSim::DataStructures::TreeNode::isEqual ( const TreeNode node) const
protectedvirtual

Returns true if the nodes are equal; otherwise, returns false.

Recurses on children. Override this method in derived classes to implement different comparisons.

Parameters
nodeThe node for comparison.
Returns
true if this node is equal to the node in the parameter.

§ operator!=()

bool SurgSim::DataStructures::TreeNode::operator!= ( const TreeNode node) const

Returns true if the nodes are not equal; otherwise, returns false.

If the nodes are not of the same type, returns false; otherwise, compares with the implementation of isEqual(const TreeNode&).

Parameters
nodeThe node for comparison.
Returns
true if this node and the parameter are not equal

§ operator==()

bool SurgSim::DataStructures::TreeNode::operator== ( const TreeNode node) const

Returns true if the nodes are equal; otherwise, returns false.

If the nodes are not of the same type, returns false; otherwise, compares with the implementation of isEqual(const TreeNode&).

Parameters
nodeThe node for comparison.
Returns
true is this node and the one from the parameter are equal.

§ setChild()

void SurgSim::DataStructures::TreeNode::setChild ( size_t  index,
const std::shared_ptr< TreeNode > &  node 
)
protected

Set a specific child of this node.

Parameters
indexIndex of the child
nodeNode to become a child

§ setData()

void SurgSim::DataStructures::TreeNode::setData ( std::shared_ptr< TreeData data)

Sets the data of this node.

Parameters
dataThe data for this node.

§ setNumChildren()

void SurgSim::DataStructures::TreeNode::setNumChildren ( size_t  numChildren)
protected

Sets the number of children of this node.

Any added children will be null.

Parameters
numChildrenThe new number of children.

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