ITreeNode.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ionTypes.h"
5 
6 
7 namespace ion
8 {
9 
19  template <typename Implementation>
20  class ITreeNode
21  {
22 
23  public:
24 
25  Implementation const * const GetParent() const
26  {
27  return Parent;
28  }
29 
30  set<Implementation *> const & GetChildren() const
31  {
32  return Children;
33  }
34 
35  void AddChild(Implementation * child)
36  {
37  child->SetParent(static_cast<Implementation *>(this));
38  }
39 
40  void RemoveChild(Implementation * child)
41  {
42  if (child->Parent == this)
43  child->SetParent(0);
44  }
45 
46  void SetParent(Implementation * parent)
47  {
48  if (Parent)
49  static_cast<ITreeNode<Implementation> *>(Parent)->Children.erase(static_cast<Implementation *>(this));
50 
51  Parent = parent;
52 
53  if (Parent)
54  static_cast<ITreeNode<Implementation> *>(parent)->Children.insert(static_cast<Implementation *>(this));
55  }
56 
58  {
59  for (auto & Child : Children)
60  Child->Parent = 0;
61  Children.clear();
62  }
63 
64  void Remove()
65  {
66  delete this;
67  }
68 
69  virtual ~ITreeNode()
70  {
71  SetParent(0);
72  }
73 
74  template <typename Return>
75  void RecurseOnChildren(Return(Implementation::* Function)())
76  {
77  for (auto Child : Children)
78  (Child->*Function)();
79  }
80 
81  template <typename Return, typename P1>
82  void RecurseOnChildren(Return(Implementation::* Function)(P1), P1 p1)
83  {
84  for (auto Child : Children)
85  (Child->*Function)(p1);
86  }
87 
88  template <typename Return, typename P1, typename P2>
89  void RecurseOnChildren(Return(Implementation::* Function)(P1, P2), P1 p1, P2 p2)
90  {
91  for (auto Child : Children)
92  (Child->*Function)(p1, p2);
93  }
94 
95  protected:
96 
98  : Parent()
99  {}
100 
101  Implementation * Parent;
102  set<Implementation *> Children;
103 
104  };
105 
106 }
void RecurseOnChildren(Return(Implementation::*Function)(P1), P1 p1)
Definition: ITreeNode.h:82
void RecurseOnChildren(Return(Implementation::*Function)())
Definition: ITreeNode.h:75
ITreeNode()
Definition: ITreeNode.h:97
void RecurseOnChildren(Return(Implementation::*Function)(P1, P2), P1 p1, P2 p2)
Definition: ITreeNode.h:89
set< Implementation * > const & GetChildren() const
Definition: ITreeNode.h:30
Interface for a Node in a generic tree structure.Note that a static_cast to TreeNode<Implementation> ...
Definition: ITreeNode.h:20
void RemoveAllChildren()
Definition: ITreeNode.h:57
set< Implementation * > Children
Definition: ITreeNode.h:102
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
Implementation * Parent
Definition: ITreeNode.h:101
Implementation const *const GetParent() const
Definition: ITreeNode.h:25
Defines typedefs for integer and floating point types.
void Remove()
Definition: ITreeNode.h:64
void SetParent(Implementation *parent)
Definition: ITreeNode.h:46
void RemoveChild(Implementation *child)
Definition: ITreeNode.h:40
virtual ~ITreeNode()
Definition: ITreeNode.h:69
void AddChild(Implementation *child)
Definition: ITreeNode.h:35