OpenBarnyard
 
Loading...
Searching...
No Matches
TNodeTree< T > Class Template Reference

#include <TNodeTree.h>

Classes

class  TNode
 

Public Member Functions

 TNodeTree ()
 
 ~TNodeTree ()
 
void Insert (T *parentNode, T *sourceNode)
 Inserts node as a child of another node.
 
void InsertAtRoot (T *sourceNode)
 Inserts node to the default tree.
 
void ReInsert (T *parentNode, T *sourceNode)
 Tries to remove sourceNode from the tree and inserts it to the parentNode or to the root.
 
T * Remove (T &node, TBOOL flag=false)
 
T * Remove (T *node, TBOOL flag=false)
 
void DeleteRecurse (T *node)
 
void DeleteAll ()
 
T * GetRoot ()
 
T * ChildOfRoot ()
 
size_t Count () const
 
TBOOL IsLinked () const
 

Protected Attributes

TNode m_Root
 
size_t m_Count
 

Detailed Description

template<class T>
class TNodeTree< T >

Definition at line 7 of file TNodeTree.h.

Constructor & Destructor Documentation

◆ TNodeTree()

template<class T>
TNodeTree< T >::TNodeTree ( )
inline

Definition at line 48 of file TNodeTree.h.

49 {
50 m_Count = 0;
51 }
size_t m_Count
Definition TNodeTree.h:263

◆ ~TNodeTree()

template<class T>
TNodeTree< T >::~TNodeTree ( )
inline

Definition at line 53 of file TNodeTree.h.

54 {
55 DeleteAll();
56 TASSERT( IsLinked() == TFALSE );
57 }
#define TASSERT(X,...)
Definition Defines.h:138
void DeleteAll()
Definition TNodeTree.h:227
TBOOL IsLinked() const
Definition TNodeTree.h:256

Member Function Documentation

◆ ChildOfRoot()

template<class T>
T * TNodeTree< T >::ChildOfRoot ( )
inline

Definition at line 246 of file TNodeTree.h.

247 {
248 return m_Root.Child();
249 }
TNode m_Root
Definition TNodeTree.h:262

◆ Count()

template<class T>
size_t TNodeTree< T >::Count ( ) const
inline

Definition at line 251 of file TNodeTree.h.

252 {
253 return m_Count;
254 }

◆ DeleteAll()

template<class T>
void TNodeTree< T >::DeleteAll ( )
inline

Definition at line 227 of file TNodeTree.h.

228 {
229 T* node = GetRoot()->Child();
230
231 while ( node != TNULL )
232 {
233 Remove( node, TFALSE );
235 node = GetRoot()->Child();
236 }
237
238 TASSERT( Count() == 0 );
239 }
void DeleteRecurse(T *node)
Definition TNodeTree.h:184
T * GetRoot()
Definition TNodeTree.h:241
T * Remove(T &node, TBOOL flag=false)
Definition TNodeTree.h:127
size_t Count() const
Definition TNodeTree.h:251

◆ DeleteRecurse()

template<class T>
void TNodeTree< T >::DeleteRecurse ( T * node)
inline

Definition at line 184 of file TNodeTree.h.

185 {
186 while ( node != TNULL )
187 {
188 T* next = ( node->Next() != node ) ? node->Next() : TNULL;
189
190 if ( node->Child() != TNULL )
191 {
192 DeleteRecurse( node->Child() );
193 }
194
195 if ( node->Tree() == this )
196 {
197 m_Count -= 1;
198 }
199
200 if ( node->Tree() == TNULL || node->Tree() == this )
201 {
202 T* nodeParent = node->Parent();
203
204 if ( nodeParent != TNULL )
205 {
206 // If it's the first attached to the root node, set it to next or just remove
207 if ( nodeParent->Child() == node )
208 {
209 nodeParent->m_Child = ( node->Next() != node ) ? node->Next() : TNULL;
210 }
211
212 node->m_Parent = TNULL;
213 }
214
215 node->m_Prev->m_Parent = node->m_Next;
216 node->m_Next->m_Child = node->m_Prev;
217 node->m_Next = node;
218 node->m_Prev = node;
219 node->m_Tree = TNULL;
220 }
221
222 delete node;
223 node = next;
224 }
225 }

◆ GetRoot()

template<class T>
T * TNodeTree< T >::GetRoot ( )
inline

Definition at line 241 of file TNodeTree.h.

242 {
243 return TSTATICCAST( T, &m_Root );
244 }
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69

◆ Insert()

template<class T>
void TNodeTree< T >::Insert ( T * parentNode,
T * sourceNode )
inline

Inserts node as a child of another node.

Parameters
parentNodePointer to the parent node.
sourceNodePointer to the node you want to insert.

Definition at line 65 of file TNodeTree.h.

66 {
67 // Toshi::TNodeTree<Toshi::TResource>::Insert - 00691aa0
68 TASSERT( sourceNode->IsLinked() == TFALSE, "The source node shouldn't be linked" );
69
70 // Remove the source node from the tree
72
73 // Get the first attached to parent node
74 T* firstAttached = parentNode->Child();
75
76 if ( firstAttached != TNULL )
77 {
78 // Attach node to other attached nodes
79 T* lastAttached = firstAttached->Prev();
80
81 lastAttached->m_Next = sourceNode;
82 firstAttached->m_Prev = sourceNode;
83
84 sourceNode->m_Next = firstAttached;
85 sourceNode->m_Prev = lastAttached;
86 }
87 else
88 {
89 // Attach node as the first one
90 parentNode->m_Child = sourceNode;
91 }
92
93 sourceNode->m_Tree = this;
94 sourceNode->m_Parent = parentNode;
95 m_Count += 1;
96 }

◆ InsertAtRoot()

template<class T>
void TNodeTree< T >::InsertAtRoot ( T * sourceNode)
inline

Inserts node to the default tree.

Parameters
sourceNodePointer to the node you want to insert.

Definition at line 103 of file TNodeTree.h.

104 {
106 }
void Insert(T *parentNode, T *sourceNode)
Inserts node as a child of another node.
Definition TNodeTree.h:65

◆ IsLinked()

template<class T>
TBOOL TNodeTree< T >::IsLinked ( ) const
inline

Definition at line 256 of file TNodeTree.h.

257 {
258 return m_Root.IsLinked();
259 }

◆ ReInsert()

template<class T>
void TNodeTree< T >::ReInsert ( T * parentNode,
T * sourceNode )
inline

Tries to remove sourceNode from the tree and inserts it to the parentNode or to the root.

Definition at line 111 of file TNodeTree.h.

112 {
114
115 if ( parentNode == TNULL )
116 {
117 if ( this != TNULL )
118 {
120 return;
121 }
122 }
123
125 }
void InsertAtRoot(T *sourceNode)
Inserts node to the default tree.
Definition TNodeTree.h:103

◆ Remove() [1/2]

template<class T>
T * TNodeTree< T >::Remove ( T & node,
TBOOL flag = false )
inline

Definition at line 127 of file TNodeTree.h.

128 {
129 // Toshi::TNodeTree<Toshi::TResource>::Remove - 00691e70
130 TNodeTree<T>* nodeRoot = node.Tree();
131 T* nodeParent = node.Parent();
132
133 if ( nodeRoot != TNULL )
134 {
135 // Check if the node belongs to the current tree
136 if ( nodeRoot != this )
137 {
138 return &node;
139 }
140
141 m_Count -= 1;
142 }
143
144 if ( flag )
145 {
146 T* attachedNode = node.Child();
147
148 while ( attachedNode != TNULL )
149 {
150 TNodeTree<T>* nodeRoot = node.Tree();
151
153 Insert( node.Parent(), attachedNode );
154
155 attachedNode = node.Child();
156 TIMPLEMENT_D( "It seems to be unused and I hope it is. I don't know if it works and what it should do" );
157 }
158 }
159
160 if ( nodeParent != TNULL )
161 {
162 // If it's the first attached to the root node, set it to next or just remove
163 if ( nodeParent->Child() == &node )
164 {
165 nodeParent->m_Child = ( node.Next() != &node ) ? node.Next() : TNULL;
166 }
167
168 node.m_Parent = TNULL;
169 }
170
171 node.m_Prev->m_Next = node.m_Next;
172 node.m_Next->m_Prev = node.m_Prev;
173 node.m_Next = &node;
174 node.m_Prev = &node;
175 node.m_Tree = TNULL;
176 return &node;
177 }
#define TIMPLEMENT_D(DESC)
Definition Defines.h:137

◆ Remove() [2/2]

template<class T>
T * TNodeTree< T >::Remove ( T * node,
TBOOL flag = false )
inline

Definition at line 179 of file TNodeTree.h.

180 {
181 return Remove( *node, flag );
182 }

Member Data Documentation

◆ m_Count

template<class T>
size_t TNodeTree< T >::m_Count
protected

Definition at line 263 of file TNodeTree.h.

◆ m_Root

template<class T>
TNode TNodeTree< T >::m_Root
protected

Definition at line 262 of file TNodeTree.h.


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