-
Notifications
You must be signed in to change notification settings - Fork 5
/
SceneGraph.cpp
123 lines (114 loc) · 3.02 KB
/
SceneGraph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <vector>
#include <cstring>
#define __node_h_ 1
using namespace std;
class Node
{
private:
Node* m_Parent;
const char* m_Name;
vector<Node* > m_Children;
public:
Node(Node* Parent = NULL, const char* Name = NULL) : m_Name(Name)
{
m_Parent = Parent;
}
~Node()
{
m_Parent = NULL;
m_Children.clear();
}
void Update()
{
if (!m_Children.empty())
{
for (size_t i = 0; i < m_Children.size(); ++i)
{
if (NULL != m_Children[i])
{
m_Children[i]->Update();
}
}
}
}
Node* GetParentNode(void) const
{
return m_Parent;
}
void SetParentNode(Node* NewParent)
{
if (NULL != m_Parent)
{
m_Parent->RemoveChildNode(this);
}
m_Parent = NewParent;
}
void AddChildNode(Node* ChildNode)
{
if (NULL != ChildNode)
{
if (NULL != ChildNode->GetParentNode())
{
ChildNode->SetParentNode(this);
}
m_Children.push_back(ChildNode);
}
}
void RemoveChildNode(Node* ChildNode)
{
if (NULL != ChildNode && !m_Children.empty())
{
for (size_t i = 0; i < m_Children.size(); ++i)
{
if (m_Children[i] == ChildNode)
{
m_Children.erase(m_Children.begin() + i);
break;
}
}
}
}
const char* GetNodeName(void) const
{
return m_Name;
}
const size_t CountChildNodes(const bool& RecursiveCount) const
{
if (!RecursiveCount)
{
return(m_Children.size());
}
else
{
size_t Retval = m_Children.size();
for (size_t i = 0; i < m_Children.size(); ++i)
{
Retval += m_Children[i]->CountChildNodes(true);
}
return(Retval);
}
}
//virtual const bool IsRootNode() const = 0;
Node* GetChildNodeByName(const char* SearchName)
{
Node* Retval = NULL;
if(!m_Children.empty())
{
for (size_t i = 0; i < m_Children.size(); ++i)
{
if (0 == strcmp(m_Children[i]->m_Name, SearchName))
{
Retval = m_Children[i];
break;
}
}
}
return(Retval);
}
};
int main()
{
Node sg(NULL,"shubham");
return 0;
}