SurgSim::DataStructures::TreeNode Class Referenceabstract

Basic tree node structure. More...

`#include <SurgSim/DataStructures/TreeNode.h>`

Inheritance diagram for SurgSim::DataStructures::TreeNode:

## Public Member Functions

| TreeNode ()
| Constructor. After construction, the node has no children, and the data is null. More...
virtual | ~TreeNode ()
| Destructor. More...
void | setData (std::shared_ptr< TreeData > data)
| Sets the data of this node. More...
std::shared_ptr< TreeData > | getData () const
size_t | getNumChildren () const
std::shared_ptr< TreeNode > | getChild (size_t index) const
| 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...

## Private Attributes

std::vector< std::shared_ptr< TreeNode > > | m_children
| Children of this node. More...
std::shared_ptr< TreeData > | m_data
| Data of this node. More...

## Detailed Description

Basic tree node structure.

The nodes build up the structure of a Tree.

See also
  Tree TreeData

## Constructor & Destructor Documentation

## TreeNode()

SurgSim::DataStructures::TreeNode::TreeNode | ( |  | ) |

Constructor. After construction, the node has no children, and the data is null.

## ~TreeNode()

SurgSim::DataStructures::TreeNode::~TreeNode | ( |  | ) |

virtual

Destructor.

## 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

  visitor | The 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

  node | The 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

  node | The new child node.

## doAccept()

virtual bool SurgSim::DataStructures::TreeNode::doAccept | ( | TreeVisitor * | visitor | ) |

protected pure 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

  visitor | The 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 | ) | const

Returns the specified child of this node.

Parameters

  index | Index of the child

Returns
  Child at the specified index

## getData()

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

protected virtual

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

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

Parameters

  node | The 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

  node | The 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

  node | The 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

  index | Index of the child
  node | Node to become a child

## setData()

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

Sets the data of this node.

Parameters

  data | The 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

  numChildren | The new number of children.

## Member Data Documentation

## m_children

std::vector<std::shared_ptr<TreeNode> > SurgSim::DataStructures::TreeNode::m_children

private

Children of this node.

## m_data

std::shared_ptr<TreeData> SurgSim::DataStructures::TreeNode::m_data

private

Data of this node.

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

- SurgSim/DataStructures/TreeNode.h
- SurgSim/DataStructures/TreeNode.cpp