20 template <
typename TType>
25 TType *_parent =
nullptr;
26 std::vector<TType *> _children;
31 static_assert(std::is_base_of_v<InherenceObject<TType>, TType>,
"TType must inherit from InherenceObject<TType>");
34 virtual ~InherenceObject()
36 if (_parent !=
nullptr)
38 _parent->removeChild(
static_cast<TType *
>(
this));
48 if (p_child ==
nullptr || p_child ==
static_cast<TType *
>(
this))
53 if (p_child->_parent !=
nullptr)
55 p_child->_parent->removeChild(p_child);
58 p_child->_parent =
static_cast<TType *
>(
this);
59 _children.emplace_back(p_child);
68 if (p_child ==
nullptr)
73 auto it = std::find(_children.begin(), _children.end(), p_child);
74 if (it != _children.end())
77 p_child->_parent =
nullptr;
103 virtual const std::vector<TType *> &
children()
const
113 for (TType *child : _children)
115 child->_parent =
nullptr;
TType * parent() const
Returns the parent pointer.
Definition spk_inherence_object.hpp:85
virtual std::vector< TType * > & children()
Returns the children vector.
Definition spk_inherence_object.hpp:94
virtual const std::vector< TType * > & children() const
Returns the children vector.
Definition spk_inherence_object.hpp:103
virtual void addChild(TType *p_child)
Adds a child to this node, handling reparenting as needed.
Definition spk_inherence_object.hpp:46
virtual void removeChild(TType *p_child)
Removes a child from this node.
Definition spk_inherence_object.hpp:66
void clearChildren()
Clears the children list and resets each child's parent pointer.
Definition spk_inherence_object.hpp:111