C4 Engine
C4 Engine API Documentation

class Tree

Defined in:  TSTree.h
Objects inherit from the Tree class so that they can be stored in a hierarchical tree.
Definition

template <class type> class Tree : public TreeBase

Member Functions
Tree::GetSuperNode Returns the super node of an object.
Tree::GetRootNode Returns the root node of the tree containing an object.
Tree::GetFirstSubnode Returns the first subnode of an object.
Tree::GetLastSubnode Returns the last subnode of an object.
Tree::GetPreviousSubnode Returns the previous subnode in the same list of subnodes.
Tree::GetNextSubnode Returns the next subnode in the same list of subnodes.
Tree::GetNextTreeNode Returns the next node in a traversal of a tree.
Tree::GetNextLevelNode Returns the next node in a traversal of a tree that is not a subnode of the current node.
Tree::GetPreviousTreeNode Returns the previous node in a traversal of a tree.
Tree::GetPreviousLevelNode Returns the previous node in a traversal of a tree that is not a subnode of the current node.
Tree::GetSubnodeCount Returns the number of immediate subnodes of an object.
Tree::AppendSubnode Adds a subnode to an object at the end of the subnode list.
Tree::PrependSubnode Adds a subnode to an object at the beginning of the subnode list.
Tree::InsertSubnodeBefore Adds a subnode to an object before a specific subnode in the subnode list.
Tree::InsertSubnodeAfter Adds a subnode to an object after a specific subnode in the subnode list.
Tree::RemoveSubnode Removes a direct subnode of an object.
Tree::MoveSubtree Moves all subnodes of an object to another object.
Tree::RemoveSubtree Removes all subnodes of an object.
Tree::PurgeSubtree Deletes all subnodes of an object.
Tree::Successor Returns a boolean value indicating whether one node is a successor of another.
Template Parameters
type The type of the class that can be stored in a tree. This parameter should be the type of the class that inherits directly from the Tree class.
Constructor

Tree();

Description
The Tree class should be declared as a base class for objects that need to be stored in a hierarchical tree. The type template parameter should match the class type of such objects.

When a Tree object is initially created, its super node is nullptr and it has no subnodes. An object having no super node is the root of a tree. (A newly created Tree object can be thought of as the root of a tree containing a single object.) In a normal tree structure, one object is created to serve as the root node. Objects are added to the tree by calling the Tree::AppendSubnode function to designate them as subnodes of other objects in the tree.

A tree is traversed in depth-first order using the Tree::GetNextTreeNode function. The root node of a tree is considered to be the first node visited in a traversal. Iterative calls to the Tree::GetNextTreeNode function visit every non-root node in a tree.

When a Tree object is destroyed, all of its subnodes (and all of their subnodes, etc.) are also destroyed.
Base Classes
TreeBase Used internally to encapsulate common functionality that is independent of the template parameter.