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 (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 with decreasing priority. More...
 
template<std::derived_from< base_component_t > component_t = base_component_t>
auto view (bool bIncludeDisabled=false) 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 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< priority > get_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 and destroy its components. More...
 

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 84 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
Returns
- raw component pointer which acts like a component's handle

Definition at line 85 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
Returns
- true if a component has been found and a new value has been set

Definition at line 271 of file components.inl.

◆ clear()

template<std::derived_from< rtti_pure_base > base_component_t>
void qx::components< base_component_t >::clear
noexcept

Clear the container and destroy its components.

Components are destroyed in reverse priority order, and in reverse addition order within a priority.

Definition at line 324 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.

Returns
- true if container doesn't have any components

Definition at line 318 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
Returns
- component reference

Definition at line 192 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
Returns
- component reference

Definition at line 185 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
Returns
- component reference

Definition at line 206 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
Returns
- component reference

Definition at line 199 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
Returns
- component priority

Definition at line 297 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
Returns
- component status

Definition at line 250 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
Returns
- component object

Definition at line 105 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
Returns
- true if a component has been found and a new value has been set

Definition at line 284 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
Returns
- true if a component has been found and a new value has been set

Definition at line 305 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
Returns
- true if a component has been found and a new value has been set

Definition at line 258 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
Returns
- component pointer or nullptr

Definition at line 154 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
Returns
- component pointer or nullptr

Definition at line 139 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
Returns
- component pointer or nullptr

Definition at line 178 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
Returns
- component pointer or nullptr

Definition at line 161 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 ( bool  bIncludeDisabled = false) 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 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 the view should include disabled components
Returns
- view of components

Definition at line 232 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 ( 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 with decreasing 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 the view should include disabled components
Returns
- view of components

Definition at line 213 of file components.inl.


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