WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
Component.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
11{
12public:
13 Component();
14 virtual ~Component();
15
17 virtual bool addChild(Component*);
18
20 virtual bool removeChild(Component*);
21
22 virtual void removeAllChildren()
23 {
24 }
25
26 virtual unsigned int nbChildren() const { return 0; }
27
28 virtual bool findChildComponent(Component* /* component */, bool /* recursive */) { return false; }
29 virtual Component* getChild(unsigned int /* index */) { return nullptr; }
30 virtual const Component* getChild(unsigned int /* index */) const { return nullptr; }
31
34
36 virtual void onParentSet(Component*);
37
39 const Component* parent() const { return m_p_parent; }
40
43
47 template <class DataType>
48 const DataType* firstParentOfType();
49
51 void ref();
52
54 void unref();
55
56 // Name management
57 void setName(const std::string& name);
58 std::string name() const;
59 virtual void onNameChanged();
60
61 // misc
62 void print(int l_depth = 0);
63 // overlaod in inheritted classes to perform specific stuff at display time
64 virtual void doPrint();
65
66 // copy
67 void copy(const Component& component, bool /* recursive*/);
68
69private:
71
72 unsigned int m_refCounter;
73
74 std::string m_name;
75};
76
77template <class DataType>
79{
80 if (parent() != nullptr)
81 {
82 DataType* l_p_parent = dynamic_cast<DataType*>(parent());
83 if (l_p_parent != nullptr)
84 return l_p_parent;
85 else
86 return parent()->firstParentOfType<DataType>();
87 }
88 return nullptr;
89}
Base class for all scene-graph nodes in the component hierarchy.
Definition Component.h:11
void unref()
Decrement the reference counter; deletes this when it reaches zero.
Definition Component.cpp:27
virtual void removeAllChildren()
Definition Component.h:22
void print(int l_depth=0)
Definition Component.cpp:61
const Component * parent() const
Get the parent component (const).
Definition Component.h:39
void ref()
Increment the reference counter.
Definition Component.cpp:22
virtual void onNameChanged()
Definition Component.cpp:57
Component * m_p_parent
Definition Component.h:70
virtual unsigned int nbChildren() const
Definition Component.h:26
virtual void doPrint()
Definition Component.cpp:97
std::string name() const
Definition Component.cpp:52
virtual const Component * getChild(unsigned int) const
Definition Component.h:30
void setName(const std::string &name)
Definition Component.cpp:46
std::string m_name
Definition Component.h:74
Component * parent()
Get the parent component.
Definition Component.h:42
unsigned int m_refCounter
Definition Component.h:72
virtual void onParentSet(Component *)
Called after the parent has been set; override for custom logic.
Definition Component.cpp:36
void setParentComponent(Component *)
Set the parent of this component.
Definition Component.cpp:40
void copy(const Component &component, bool)
Definition Component.cpp:92
virtual ~Component()
virtual Component * getChild(unsigned int)
Definition Component.h:29
virtual bool findChildComponent(Component *, bool)
Definition Component.h:28
virtual bool addChild(Component *)
Add a child component to this node.
Definition Component.cpp:12
virtual bool removeChild(Component *)
Remove a child component from this node.
Definition Component.cpp:17
const DataType * firstParentOfType()
Walk up the parent chain and return the first ancestor of the given type.
Definition Component.h:78