3#include "structure/design_pattern/spk_inherence_object.hpp"
12 template <
typename TType>
46 std::stable_sort(childs.begin(), childs.end(), [](
const TType *a,
const TType *b) {
47 return a->priority() > b->priority();
56 if (
auto *p = this->
parent(); p !=
nullptr)
69 std::is_base_of_v<InherenceWithPriorityObject<TType>, TType>,
70 "TType must inherit from InherenceWithPriorityObject<TType> to use priority() sorting.");
89 if (_priority == p_priority)
94 _priority = p_priority;
Provides parent/child ownership links for tree structures.
Definition spk_inherence_object.hpp:22
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 void addChild(TType *p_child)
Adds a child to this node, handling reparenting as needed.
Definition spk_inherence_object.hpp:46
InherenceWithPriorityObject()
Builds a priority-aware inherence object.
Definition spk_inherence_with_priority_object.hpp:66
void addChild(TType *p_child) override
Adds a child and re-sorts by priority.
Definition spk_inherence_with_priority_object.hpp:77
void setPriority(const Priority &p_priority)
Sets this node's priority and refreshes parent ordering.
Definition spk_inherence_with_priority_object.hpp:87
void _sortChildByPriority()
Sorts children by descending priority.
Definition spk_inherence_with_priority_object.hpp:42
std::size_t Priority
Priority value type used for sorting.
Definition spk_inherence_with_priority_object.hpp:33
void _notifyParentPriorityChanged()
Notifies the parent that this node's priority changed.
Definition spk_inherence_with_priority_object.hpp:54
const Priority & priority() const
Returns the current priority value.
Definition spk_inherence_with_priority_object.hpp:102