OpenDaVINCI  4.16.0
TreeNode.h
Go to the documentation of this file.
1 
20 #ifndef OPENDAVINCI_CORE_BASE_TREENODE_H_
21 #define OPENDAVINCI_CORE_BASE_TREENODE_H_
22 
24 
25 namespace odcore {
26  namespace base {
27 
28  using namespace std;
29 
33  template<typename T>
35  private:
41  TreeNode(const TreeNode &);
42 
48  TreeNode& operator=(const TreeNode &);
49 
50  public:
52  m_value(),
53  m_parent(NULL),
54  m_children() {}
55 
56  virtual ~TreeNode() {
57  typename vector<TreeNode<T>* >::iterator it = m_children.begin();
58  while (it != m_children.end()) {
59  TreeNode<T> *child = (*it++);
60  delete child;
61  }
62  m_children.clear();
63  }
64 
70  void setValue(T value) {
71  m_value = value;
72  }
73 
79  T getValue() {
80  return m_value;
81  }
82 
89  return m_parent;
90  }
91 
97  void setParent(TreeNode<T> *parent) {
98  m_parent = parent;
99  }
100 
106  void addChild(TreeNode<T> *child) {
107  if (child != NULL) {
108  child->setParent(this);
109  m_children.push_back(child);
110  }
111  }
112 
118  vector<TreeNode<T>* > getChildren() {
119  return m_children;
120  }
121 
122  private:
123  T m_value;
124  TreeNode<T> *m_parent;
125  vector<TreeNode<T>* > m_children;
126  };
127 
128  }
129 } // odcore::base
130 
131 #endif /*OPENDAVINCI_CORE_BASE_TREENODE_H_*/
virtual ~TreeNode()
Definition: TreeNode.h:56
Definition: TreeNode.h:34
TreeNode< T > * getParent()
Definition: TreeNode.h:88
#define OPENDAVINCI_API
Definition: opendavinci.h:67
void setParent(TreeNode< T > *parent)
Definition: TreeNode.h:97
void addChild(TreeNode< T > *child)
Definition: TreeNode.h:106
void setValue(T value)
Definition: TreeNode.h:70
vector< TreeNode< T > * > getChildren()
Definition: TreeNode.h:118
T getValue()
Definition: TreeNode.h:79
TreeNode()
Definition: TreeNode.h:51