20 #include <unordered_map>
25 enum class component_status
63 using time_ordered_priority_key::operator<;
83 template<std::derived_from<rtti_pure_base> base_component_t>
87 using pointer_type = std::unique_ptr<base_component_t>;
92 std::unordered_map<class_id, std::unique_ptr<class_data>> derivedClasses;
94 std::multimap<component_status_key, base_component_t*> priorityCache;
96 [[nodiscard]] class_data& get_or_add_class_data(
class_id id) noexcept;
108 template<std::derived_from<base_component_t> component_t>
109 [[maybe_unused]] component_t*
add(
110 std::unique_ptr<component_t> pComponent,
111 priority ePriority = priority::normal,
119 [[maybe_unused]] std::unique_ptr<base_component_t>
remove(
const base_component_t* pRawComponent) noexcept;
127 template<std::derived_from<base_component_t> component_t>
128 [[nodiscard]] component_t*
try_get(
bool bIncludeDisabled =
false) noexcept;
136 template<std::derived_from<base_component_t> component_t>
137 [[nodiscard]]
const component_t*
try_get(
bool bIncludeDisabled =
false)
const noexcept;
146 template<std::derived_from<base_component_t> component_t = base_component_t>
147 [[nodiscard]] component_t*
try_get(
class_id id,
bool bIncludeDisabled =
false) noexcept;
156 template<std::derived_from<base_component_t> component_t = base_component_t>
157 [[nodiscard]]
const component_t*
try_get(
class_id id,
bool bIncludeDisabled =
false)
const noexcept;
165 template<std::derived_from<base_component_t> component_t>
166 [[nodiscard]] component_t&
get(
bool bIncludeDisabled =
false) noexcept;
174 template<std::derived_from<base_component_t> component_t>
175 [[nodiscard]]
const component_t&
get(
bool bIncludeDisabled =
false)
const noexcept;
184 template<std::derived_from<base_component_t> component_t = base_component_t>
185 [[nodiscard]] base_component_t&
get(
class_id id,
bool bIncludeDisabled =
false) noexcept;
194 template<std::derived_from<base_component_t> component_t = base_component_t>
195 [[nodiscard]]
const base_component_t&
get(
class_id id,
bool bIncludeDisabled =
false)
const noexcept;
202 template<std::derived_from<base_component_t> component_t = base_component_t>
203 [[nodiscard]]
auto view() noexcept;
210 template<std::derived_from<base_component_t> component_t = base_component_t>
211 [[nodiscard]]
auto view()
const noexcept;
219 const base_component_t* pRawComponent)
const noexcept;
228 const base_component_t* pRawComponent,
238 const base_component_t* pRawComponent,
248 const base_component_t* pRawComponent,
256 [[nodiscard]] std::optional<priority>
get_component_priority(
const base_component_t* pRawComponent)
const noexcept;
265 const base_component_t* pRawComponent,
266 priority eNewComponentPriority) noexcept;
272 [[nodiscard]]
bool empty()
const noexcept;
277 void clear() noexcept;
285 [[nodiscard]] std::optional<component_status_key> get_status(
const base_component_t* pRawComponent)
const noexcept;
294 [[maybe_unused]]
bool set_status(
const base_component_t* pRawComponent,
component_status_key status) noexcept;
304 std::derived_from<base_component_t> component_t,
305 callable_c<void, typename components<base_component_t>::class_data&> callable_t>
306 class_data& iterate_class_data(callable_t iterateClassDataFunction) noexcept;
316 std::derived_from<base_component_t> component_t,
317 callable_c<void, typename components<base_component_t>::class_data&> callable_t>
318 const class_data& iterate_class_data(callable_t iterateClassDataFunction)
const noexcept;
325 template<std::derived_from<base_component_t> component_t>
326 class_data& get_or_add_class_data() noexcept;
333 template<std::derived_from<base_component_t> component_t>
334 const class_data& get_or_add_class_data()
const noexcept;
343 template<callable_c<void, typename components<base_component_t>::class_data&> callable_t>
344 class_data& iterate_class_data(
const base_component_t* pRawComponent, callable_t iterateClassDataFunction) noexcept;
353 template<callable_c<void, typename components<base_component_t>::class_data&> callable_t>
354 const class_data& iterate_class_data(
const base_component_t* pRawComponent, callable_t iterateClassDataFunction)
362 class_data& get_or_add_class_data(
const base_component_t* pRawComponent) noexcept;
369 const class_data& get_or_add_class_data(
const base_component_t* pRawComponent)
const noexcept;
372 class_data m_RootClass;
378 struct std::hash<qx::component_status_key>
382 size_t nHash = qx::get_hash<qx::time_ordered_priority_key>(status);
Class id, unique for each class using qx rtti system.
A class that acts like time_ordered_priority_key but has a status field.
constexpr void set_status_flags(flags< component_status > eStatusFlags) noexcept
Set object status.
constexpr flags< component_status > get_status_flags() const noexcept
Get object status.
Container for components system.
component_t & get(bool bIncludeDisabled=false) noexcept
Get a component of the given type with the highest priority (no existence checks are performed)
std::unique_ptr< base_component_t > remove(const base_component_t *pRawComponent) noexcept
Remove the component from the container.
bool add_component_status(const base_component_t *pRawComponent, flags< component_status > newStatuses) noexcept
Add new component status flags to the current ones.
bool set_component_priority(const base_component_t *pRawComponent, priority eNewComponentPriority) noexcept
Set component priority.
void clear() noexcept
Clear the container, e.g. remove all the components.
component_t * try_get(bool bIncludeDisabled=false) noexcept
Try to get a component of the given type with the highest priority.
bool set_component_status(const base_component_t *pRawComponent, flags< component_status > newStatus) noexcept
Set (override) a component status.
auto view() noexcept
Get a view which may be used in a ranged-based for loop and consists of components of a given type wi...
bool empty() const noexcept
Check if container doesn't have any components.
bool remove_component_status(const base_component_t *pRawComponent, flags< component_status > statusesToRemove) noexcept
Add component status flags from the current ones.
component_t * add(std::unique_ptr< component_t > pComponent, priority ePriority=priority::normal, flags< component_status > statusFlags=component_status::default_value) noexcept
Add a component.
std::optional< flags< component_status > > get_component_status(const base_component_t *pRawComponent) const noexcept
Get component status.
std::optional< priority > get_component_priority(const base_component_t *pRawComponent) const noexcept
Get component priority.
A class that can be used as a key in ordered containers so that items are ordered in descending order...
priority
User may use the predefined values or the custom ones, for ex. "normal - 1", this type is supposed to...
RTTI system based on polymorphism.