My Project: dynamics.mod/NewtonDynamics/source/core/dgNode.h Source File

My Project

dgNode.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef __dgNode__
23 #define __dgNode__
24
25 #include "dgStdafx.h"
26 #include "dgCRC.h"
27 #include "dgRef.h"
28 #include "dgRtti.h"
29
30
31 class dgFile;
32 //enum dgSaveType;
33
34
35 class dgBaseNode: public dgRef
36 {
37 public:
38 dgBaseNode *GetChild () const;
39 dgBaseNode *GetParent () const;
40 dgBaseNode *GetSibling () const;
41
42 void Detach ();
43 void Attach (dgBaseNode* const parent, bool addFirst = false);
44
45 dgBaseNode *GetRoot () const;
46 dgBaseNode *GetFirst() const;
47 dgBaseNode *GetLast() const;
48 dgBaseNode *GetNext() const;
49 dgBaseNode *GetPrev() const;
50
51 dgBaseNode *Find (dgUnsigned32 nameCRC) const;
52 dgBaseNode *Find (const char* const name) const;
53 void DebugPrint (const char* const fileName);
54 bool SanityCheck();
55
56
57 protected:
58 dgBaseNode ();
59 dgBaseNode (const char* const name);
60 dgBaseNode (const dgBaseNode &clone);
61 ~dgBaseNode ();
62
63 // virtual void Save (dgFile &file, dgSaveType saveType, void* const context) const;
64 virtual void CloneFixUp (const dgBaseNode &clone);
65 virtual void PrintHierarchy (dgFile &file, char* indentation) const;
66
67 private:
68 inline void Clear();
69
70 dgAddRtti(dgRef);
71 dgBaseNode* parent;
72 dgBaseNode* child;
73 dgBaseNode* sibling;
74
75 };
76
77 template<class T>
78 class dgNode: public dgBaseNode
79 {
80 public:
81 dgNode ();
82 dgNode (const char* const name);
83 void Attach (T* parent, bool addFirst = false);
84 void Detach ();
85 T* GetChild () const;
86 T* GetSibling () const;
87 T* GetParent () const;
88 T* GetRoot () const;
89 T* GetFirst() const;
90 T* GetLast() const;
91 T* GetNext() const;
92 T* GetPrev() const;
93 T* Find (dgUnsigned32 nameCRC) const;
94 T* Find (const char* const name) const;
95
96 protected:
97 dgNode (const T &clone);
98 virtual ~dgNode ();
99 dgRef *CreateClone () const;
100
101 };
102
103
104
105
106
107 inline dgBaseNode::dgBaseNode ()
108 :dgRef ()
109 {
110 Clear ();
111 }
112
113 inline dgBaseNode::dgBaseNode (const char* const name)
114 :dgRef (name)
115 {
116 Clear ();
117 }
118
119
120 inline void dgBaseNode::Clear()
121 {
122 child = NULL;
123 parent = NULL;
124 sibling = NULL;
125 }
126
127
128 inline dgBaseNode *dgBaseNode::GetChild () const
129 {
130 return child;
131 }
132
133 inline dgBaseNode *dgBaseNode::GetSibling () const
134 {
135 return sibling;
136 }
137
138 inline dgBaseNode *dgBaseNode::GetParent () const
139 {
140 return parent;
141 }
142
143
144 inline dgBaseNode *dgBaseNode::Find (const char* const name) const
145 {
146 return Find (dgCRC (name));
147 }
148
149
150
151
152 template<class T>
153 dgNode<T>::dgNode ()
154 :dgBaseNode ()
155 {
156 }
157
158 template<class T>
159 dgNode<T>::dgNode (const T &clone)
160 :dgBaseNode (clone)
161 {
162 }
163
164 template<class T>
165 dgNode<T>::dgNode (const char* const name)
166 :dgBaseNode (name)
167 {
168 }
169
170 template<class T>
171 dgNode<T>::~dgNode ()
172 {
173 }
174
175
176 template<class T>
177 dgRef *dgNode<T>::CreateClone () const
178 {
179 return new T (*(T*)this);
180 }
181
182 template<class T>
183 void dgNode<T>::Attach (T* const parent, bool addFirst)
184 {
185 dgBaseNode::Attach(parent, addFirst);
186 }
187
188 template<class T>
189 void dgNode<T>::Detach ()
190 {
191 dgBaseNode::Detach ();
192 }
193
194 template<class T>
195 T* dgNode<T>::GetChild () const
196 {
197 return (T*) dgBaseNode::GetChild();
198 }
199
200 template<class T>
201 T* dgNode<T>::GetSibling () const
202 {
203 return (T*) dgBaseNode::GetSibling ();
204 }
205
206 template<class T>
207 T* dgNode<T>::GetParent () const
208 {
209 return (T*) dgBaseNode::GetParent ();
210 }
211
212
213 template<class T>
214 T* dgNode<T>::GetRoot () const
215 {
216 return (T*) dgBaseNode::GetRoot ();
217 }
218
219
220 template<class T>
221 T* dgNode<T>::GetFirst() const
222 {
223 return (T*) dgBaseNode::GetFirst ();
224 }
225
226 template<class T>
227 T* dgNode<T>::GetLast() const
228 {
229 return (T*) dgBaseNode::GetLast ();
230 }
231
232
233 template<class T>
234 T* dgNode<T>::GetNext() const
235 {
236 return (T*) dgBaseNode::GetNext ();
237 }
238
239 template<class T>
240 T* dgNode<T>::GetPrev() const
241 {
242 return (T*) dgBaseNode::GetPrev ();
243 }
244
245
246 template<class T>
247 T* dgNode<T>::Find (dgUnsigned32 nameCRC) const
248 {
249 return (T*) dgBaseNode::Find (nameCRC);
250 }
251
252 template<class T>
253 T* dgNode<T>::Find (const char* const name) const
254 {
255 return (T*) dgBaseNode::Find (name);
256 }
257
258
259
260
261 #endif
262
dgBaseNode::GetParent
dgBaseNode * GetParent() const
Definition: dgNode.h:138
dgCRC
dgUnsigned32 dgApi dgCRC(const char *const name)
Definition: dgCRC.cpp:340
dgBaseNode::GetRoot
dgBaseNode * GetRoot() const
Definition: dgNode.cpp:122
dgNode::Find
T * Find(dgUnsigned32 nameCRC) const
Definition: dgNode.h:247
dgBaseNode::GetChild
dgBaseNode * GetChild() const
Definition: dgNode.h:128
dgNode::GetNext
T * GetNext() const
Definition: dgNode.h:234
dgBaseNode::dgBaseNode
dgBaseNode()
Definition: dgNode.h:107
dgNode::GetSibling
T * GetSibling() const
Definition: dgNode.h:201
dgBaseNode::GetLast
dgBaseNode * GetLast() const
Definition: dgNode.cpp:159
dgNode::dgNode
dgNode()
Definition: dgNode.h:153
dgNode::CreateClone
dgRef * CreateClone() const
Definition: dgNode.h:177
dgNode::GetPrev
T * GetPrev() const
Definition: dgNode.h:240
dgNode
Definition: dgNode.h:78
dgBaseNode::PrintHierarchy
virtual void PrintHierarchy(dgFile &file, char *indentation) const
Definition: dgNode.cpp:203
dgBaseNode
Definition: dgNode.h:35
dgBaseNode::GetNext
dgBaseNode * GetNext() const
Definition: dgNode.cpp:143
dgNode::GetParent
T * GetParent() const
Definition: dgNode.h:207
dgCRC.h
dgBaseNode::Detach
void Detach()
Definition: dgNode.cpp:102
dgBaseNode::SanityCheck
bool SanityCheck()
Definition: dgNode.cpp:198
dgBaseNode::GetFirst
dgBaseNode * GetFirst() const
Definition: dgNode.cpp:133
dgStdafx.h
dgRef
Definition: dgRef.h:50
dgRef::CreateClone
virtual dgRef * CreateClone() const
Definition: dgRef.h:155
dgNode::Detach
void Detach()
Definition: dgNode.h:189
dgBaseNode::Attach
void Attach(dgBaseNode *const parent, bool addFirst=false)
Definition: dgNode.cpp:74
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgRtti.h
dgBaseNode::Find
dgBaseNode * Find(dgUnsigned32 nameCRC) const
Definition: dgNode.cpp:187
dgBaseNode::CloneFixUp
virtual void CloneFixUp(const dgBaseNode &clone)
Definition: dgNode.cpp:62
dgBaseNode::~dgBaseNode
~dgBaseNode()
Definition: dgNode.cpp:41
dgBaseNode::DebugPrint
void DebugPrint(const char *const fileName)
Definition: dgNode.cpp:216
dgNode::GetLast
T * GetLast() const
Definition: dgNode.h:227
dgNode::Attach
void Attach(T *parent, bool addFirst=false)
Definition: dgNode.h:183
dgNode::GetFirst
T * GetFirst() const
Definition: dgNode.h:221
dgBaseNode::GetSibling
dgBaseNode * GetSibling() const
Definition: dgNode.h:133
dgNode::~dgNode
virtual ~dgNode()
Definition: dgNode.h:171
dgBaseNode::GetPrev
dgBaseNode * GetPrev() const
Definition: dgNode.cpp:171
dgNode::GetRoot
T * GetRoot() const
Definition: dgNode.h:214
dgNode::GetChild
T * GetChild() const
Definition: dgNode.h:195
dgRef.h