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;
203 template<std::derived_from<base_component_t> component_t = base_component_t>
204 [[nodiscard]]
auto view(
bool bIncludeDisabled =
false) noexcept;
212 template<std::derived_from<base_component_t> component_t = base_component_t>
213 [[nodiscard]]
auto view(
bool bIncludeDisabled =
false)
const noexcept;
221 const base_component_t* pRawComponent)
const noexcept;
230 const base_component_t* pRawComponent,
240 const base_component_t* pRawComponent,
250 const base_component_t* pRawComponent,
258 [[nodiscard]] std::optional<priority>
get_component_priority(
const base_component_t* pRawComponent)
const noexcept;
267 const base_component_t* pRawComponent,
268 priority eNewComponentPriority) noexcept;
274 [[nodiscard]]
bool empty()
const noexcept;
279 void clear() noexcept;
287 [[nodiscard]] std::optional<component_status_key> get_status(
const base_component_t* pRawComponent)
const noexcept;
296 [[maybe_unused]]
bool set_status(
const base_component_t* pRawComponent,
component_status_key status) noexcept;
306 std::derived_from<base_component_t> component_t,
307 callable_c<void, typename components<base_component_t>::class_data&> callable_t>
308 class_data& iterate_class_data(callable_t iterateClassDataFunction) noexcept;
318 std::derived_from<base_component_t> component_t,
319 callable_c<void, typename components<base_component_t>::class_data&> callable_t>
320 const class_data& iterate_class_data(callable_t iterateClassDataFunction)
const noexcept;
327 template<std::derived_from<base_component_t> component_t>
328 class_data& get_or_add_class_data() noexcept;
335 template<std::derived_from<base_component_t> component_t>
336 const class_data& get_or_add_class_data()
const noexcept;
345 template<callable_c<void, typename components<base_component_t>::class_data&> callable_t>
346 class_data& iterate_class_data(
const base_component_t* pRawComponent, callable_t iterateClassDataFunction) noexcept;
355 template<callable_c<void, typename components<base_component_t>::class_data&> callable_t>
356 const class_data& iterate_class_data(
const base_component_t* pRawComponent, callable_t iterateClassDataFunction)
364 class_data& get_or_add_class_data(
const base_component_t* pRawComponent) noexcept;
371 const class_data& get_or_add_class_data(
const base_component_t* pRawComponent)
const noexcept;
374 class_data m_RootClass;
380 struct std::hash<qx::component_status_key>
384 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.
bool empty() const noexcept
Check if container doesn't have any components.
auto view(bool bIncludeDisabled=false) noexcept
Get a view which may be used in a ranged-based for loop and consists of components of a given type wi...
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.