qxLib
Classes | Public Member Functions | List of all members
qx::components< base_component_t > Class Template Reference

Container for components system. More...

#include <components.h>

Public Member Functions

template<std::derived_from< base_component_t > component_t>
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. More...
 
std::unique_ptr< base_component_t > remove (const base_component_t *pRawComponent) noexcept
 Remove the component from the container. More...
 
template<std::derived_from< base_component_t > component_t>
component_t * try_get (bool bIncludeDisabled=false) noexcept
 Try to get a component of the given type with the highest priority. More...
 
template<std::derived_from< base_component_t > component_t>
const component_t * try_get (bool bIncludeDisabled=false) const noexcept
 Try to get a component of the given type with the highest priority. More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
component_t * try_get (class_id id, bool bIncludeDisabled=false) noexcept
 Try to get a component of the given type id with the highest priority. More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
const component_t * try_get (class_id id, bool bIncludeDisabled=false) const noexcept
 Try to get a component of the given type id with the highest priority. More...
 
template<std::derived_from< base_component_t > component_t>
component_t & get (bool bIncludeDisabled=false) noexcept
 Get a component of the given type with the highest priority (no existence checks are performed) More...
 
template<std::derived_from< base_component_t > component_t>
const component_t & get (bool bIncludeDisabled=false) const noexcept
 Get a component of the given type with the highest priority (no existence checks are performed) More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
base_component_t & get (class_id id, bool bIncludeDisabled=false) noexcept
 Get a component of the given type with the highest priority (no existence checks are performed) More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
const base_component_t & get (class_id id, bool bIncludeDisabled=false) const noexcept
 Get a component of the given type with the highest priority (no existence checks are performed) More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
auto view () noexcept
 Get a view which may be used in a ranged-based for loop and consists of components of a given type with decreasing non-disabled priority. More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
auto view () const noexcept
 Get a view which may be used in a ranged-based for loop and consists of components of a given type with decreasing non-disabled priority. More...
 
std::optional< flags< component_status > > get_component_status (const base_component_t *pRawComponent) const noexcept
 Get component status. More...
 
bool set_component_status (const base_component_t *pRawComponent, flags< component_status > newStatus) noexcept
 Set (override) a component status. More...
 
bool add_component_status (const base_component_t *pRawComponent, flags< component_status > newStatuses) noexcept
 Add new component status flags to the current ones. More...
 
bool remove_component_status (const base_component_t *pRawComponent, flags< component_status > statusesToRemove) noexcept
 Add component status flags from the current ones. More...
 
std::optional< priorityget_component_priority (const base_component_t *pRawComponent) const noexcept
 Get component priority. More...
 
bool set_component_priority (const base_component_t *pRawComponent, priority eNewComponentPriority) noexcept
 Set component priority. More...
 
bool empty () const noexcept
 Check if container doesn't have any components. More...
 
void clear () noexcept
 Clear the container, e.g. remove all the components.
 

Detailed Description

template<std::derived_from< rtti_pure_base > base_component_t>
class qx::components< base_component_t >

Container for components system.

Stores components and allows them to be accessed by a template argument or a class id. Each component has a priority, which is used to iterate through a sequence of objects of a type (final or any super type) or to use getter methods, where a component with the highest priority will be given. You can use qx::priority::disabled to exclude the component from iteration or getters result.

Template Parameters
base_component_t- base component type
Author
Khrapov
Date
9.03.2021

Definition at line 45 of file components.h.

Member Function Documentation

◆ add()

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
component_t * qx::components< base_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.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
pComponent- component object
ePriority- initial component priority
statusFlags- initial component status
Return values
-raw component pointer which acts like a component's handle

Definition at line 28 of file components.inl.

◆ add_component_status()

template<std::derived_from< rtti_pure_base > base_component_t>
bool qx::components< base_component_t >::add_component_status ( const base_component_t *  pRawComponent,
flags< component_status >  newStatuses 
)
noexcept

Add new component status flags to the current ones.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
newStatuses- new component status flags
Return values
-true if a component has been found and a new value has been set

Definition at line 217 of file components.inl.

◆ empty()

template<std::derived_from< rtti_pure_base > base_component_t>
bool qx::components< base_component_t >::empty
noexcept

Check if container doesn't have any components.

Return values
-true if container doesn't have any components

Definition at line 264 of file components.inl.

◆ get() [1/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
const component_t & qx::components< base_component_t >::get ( bool  bIncludeDisabled = false) const
noexcept

Get a component of the given type with the highest priority (no existence checks are performed)

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
bIncludeDisabled- true if a search should include disabled components
Return values
-component reference

Definition at line 138 of file components.inl.

◆ get() [2/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
component_t & qx::components< base_component_t >::get ( bool  bIncludeDisabled = false)
noexcept

Get a component of the given type with the highest priority (no existence checks are performed)

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
bIncludeDisabled- true if a search should include disabled components
Return values
-component reference

Definition at line 131 of file components.inl.

◆ get() [3/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
const base_component_t & qx::components< base_component_t >::get ( class_id  id,
bool  bIncludeDisabled = false 
) const
noexcept

Get a component of the given type with the highest priority (no existence checks are performed)

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
id- type id
bIncludeDisabled- true if a search should include disabled components
Return values
-component reference

Definition at line 152 of file components.inl.

◆ get() [4/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
base_component_t & qx::components< base_component_t >::get ( class_id  id,
bool  bIncludeDisabled = false 
)
noexcept

Get a component of the given type with the highest priority (no existence checks are performed)

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
id- type id
bIncludeDisabled- true if a search should include disabled components
Return values
-component reference

Definition at line 145 of file components.inl.

◆ get_component_priority()

template<std::derived_from< rtti_pure_base > base_component_t>
std::optional< priority > qx::components< base_component_t >::get_component_priority ( const base_component_t *  pRawComponent) const
noexcept

Get component priority.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
Return values
-component priority

Definition at line 243 of file components.inl.

◆ get_component_status()

template<std::derived_from< rtti_pure_base > base_component_t>
std::optional< flags< component_status > > qx::components< base_component_t >::get_component_status ( const base_component_t *  pRawComponent) const
noexcept

Get component status.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
Return values
-component status

Definition at line 196 of file components.inl.

◆ remove()

template<std::derived_from< rtti_pure_base > base_component_t>
std::unique_ptr< base_component_t > qx::components< base_component_t >::remove ( const base_component_t *  pRawComponent)
noexcept

Remove the component from the container.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
Return values
-component object

Definition at line 51 of file components.inl.

◆ remove_component_status()

template<std::derived_from< rtti_pure_base > base_component_t>
bool qx::components< base_component_t >::remove_component_status ( const base_component_t *  pRawComponent,
flags< component_status >  statusesToRemove 
)
noexcept

Add component status flags from the current ones.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
statusesToRemove- component status flags to remove
Return values
-true if a component has been found and a new value has been set

Definition at line 230 of file components.inl.

◆ set_component_priority()

template<std::derived_from< rtti_pure_base > base_component_t>
bool qx::components< base_component_t >::set_component_priority ( const base_component_t *  pRawComponent,
priority  eNewComponentPriority 
)
noexcept

Set component priority.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
eNewComponentPriority- new component priority
Return values
-true if a component has been found and a new value has been set

Definition at line 251 of file components.inl.

◆ set_component_status()

template<std::derived_from< rtti_pure_base > base_component_t>
bool qx::components< base_component_t >::set_component_status ( const base_component_t *  pRawComponent,
flags< component_status >  newStatus 
)
noexcept

Set (override) a component status.

Parameters
pRawComponent- raw component pointer which acts like a component's handle
newStatus- new component status
Return values
-true if a component has been found and a new value has been set

Definition at line 204 of file components.inl.

◆ try_get() [1/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
const component_t * qx::components< base_component_t >::try_get ( bool  bIncludeDisabled = false) const
noexcept

Try to get a component of the given type with the highest priority.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
bIncludeDisabled- true if a search should include disabled components
Return values
-component pointer or nullptr

Definition at line 100 of file components.inl.

◆ try_get() [2/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
component_t * qx::components< base_component_t >::try_get ( bool  bIncludeDisabled = false)
noexcept

Try to get a component of the given type with the highest priority.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
bIncludeDisabled- true if a search should include disabled components
Return values
-component pointer or nullptr

Definition at line 85 of file components.inl.

◆ try_get() [3/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
const component_t * qx::components< base_component_t >::try_get ( class_id  id,
bool  bIncludeDisabled = false 
) const
noexcept

Try to get a component of the given type id with the highest priority.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
id- type id
bIncludeDisabled- true if a search should include disabled components
Return values
-component pointer or nullptr

Definition at line 124 of file components.inl.

◆ try_get() [4/4]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
component_t * qx::components< base_component_t >::try_get ( class_id  id,
bool  bIncludeDisabled = false 
)
noexcept

Try to get a component of the given type id with the highest priority.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Parameters
id- type id
bIncludeDisabled- true if a search should include disabled components
Return values
-component pointer or nullptr

Definition at line 107 of file components.inl.

◆ view() [1/2]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
auto qx::components< base_component_t >::view
noexcept

Get a view which may be used in a ranged-based for loop and consists of components of a given type with decreasing non-disabled priority.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Return values
-view of components

Definition at line 178 of file components.inl.

◆ view() [2/2]

template<std::derived_from< rtti_pure_base > base_component_t>
template<std::derived_from< base_component_t > component_t>
auto qx::components< base_component_t >::view
noexcept

Get a view which may be used in a ranged-based for loop and consists of components of a given type with decreasing non-disabled priority.

Template Parameters
component_t- component type which doesn't have to be a final class type, may be any base or super type
Return values
-view of components

Definition at line 159 of file components.inl.


The documentation for this class was generated from the following files: