CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::EntityTemplate Class Reference

#include <CeresEngine/Entity/EntityTemplate.hpp>

Classes

class  ComponentData
 
class  TComponentData
 

Public Member Functions

template<CComponent C, typename... Args>
Cadd (Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Adds a new component of the given type.
 
template<CComponent C, typename Block , typename... Args>
CaddWith (Block &&block, Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Adds a new component and calls block with the added component.
 
template<CComponent C, typename... Args>
Cset (Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Sets a component.
 
template<CComponent C>
void remove () noexcept(std::is_nothrow_destructible_v< C >)
 Removes a component of type C from the entity.
 
template<CComponent C>
Cget () noexcept
 Gets a component of type C.
 
template<CComponent C>
const Cget () const noexcept
 Gets a component of type C.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > get () noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 &, const C1 &, const Cs &... > get () const noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C>
CgetOr () noexcept(std::is_nothrow_constructible_v< C >)
 Gets a component of type C.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > getOr () noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C>
CgetIf () noexcept
 Gets a component of type C.
 
template<CComponent C>
const CgetIf () const noexcept
 Gets a component of type C.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 *, C1 *, Cs *... > getIf () noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 *, const C1 *, const Cs *... > getIf () const noexcept
 Gets a set of components of types C0, C1 and Cs.
 
template<CComponent C, CComponent... Cs>
bool has () const noexcept
 Checks if the entity has all components of types Cs.
 
void clear ()
 Removes all components attached to the entity, without destroying the entity itself.
 
bool empty () noexcept
 Checks if the entity is empty (i.e.
 

Private Attributes

FlatMap< ComponentID, UPtr< ComponentData > > mComponents
 
String mName
 

Member Function Documentation

◆ add()

template<CComponent C, typename... Args>
C & CeresEngine::EntityTemplate::add ( Args &&...  args)
inlinenoexcept

Adds a new component of the given type.

If a component of the given type is already present, this method throws.

Parameters
typeThe component type to be added.
Returns
A reference to the added component.

◆ addWith()

template<CComponent C, typename Block , typename... Args>
C & CeresEngine::EntityTemplate::addWith ( Block &&  block,
Args &&...  args 
) const
inlinenoexcept

Adds a new component and calls block with the added component.

If a component of type C is already present, this method throws.

Template Parameters
Cthe component type to be added
Blockthe block type
Argsthe component constructor argument types
Parameters
blockThe block to be called
argsThe component constructor arguments
Returns
A reference to the newly added component

◆ clear()

void CeresEngine::EntityTemplate::clear ( )

Removes all components attached to the entity, without destroying the entity itself.

◆ empty()

bool CeresEngine::EntityTemplate::empty ( )
noexcept

Checks if the entity is empty (i.e.

has no components attached).

Returns
True if the entity has no components

◆ get() [1/4]

template<CComponent C>
const C & CeresEngine::EntityTemplate::get ( ) const
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, this method throws.

Template Parameters
Cthe component type to be retrieved
Returns
A reference to the existing component

◆ get() [2/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 &, const C1 &, const Cs &... > CeresEngine::EntityTemplate::get ( ) const
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, this method throws.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ get() [3/4]

template<CComponent C>
C & CeresEngine::EntityTemplate::get ( )
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, this method throws.

Template Parameters
Cthe component type to be retrieved
Returns
A reference to the existing component

◆ get() [4/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > CeresEngine::EntityTemplate::get ( )
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, this method throws.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing component

◆ getIf() [1/4]

template<CComponent C>
const C * CeresEngine::EntityTemplate::getIf ( ) const
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, nullptr is returned

Template Parameters
Cthe component type to be retrieved
Returns
A pointer to the existing component

◆ getIf() [2/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< const C0 *, const C1 *, const Cs *... > CeresEngine::EntityTemplate::getIf ( ) const
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, nullptr is returned.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ getIf() [3/4]

template<CComponent C>
C * CeresEngine::EntityTemplate::getIf ( )
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, nullptr is returned

Template Parameters
Cthe component type to be retrieved
Returns
A pointer to the existing component

◆ getIf() [4/4]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 *, C1 *, Cs *... > CeresEngine::EntityTemplate::getIf ( )
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, nullptr is returned.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ getOr() [1/2]

template<CComponent C0, CComponent C1, CComponent... Cs>
Tuple< C0 &, C1 &, Cs &... > CeresEngine::EntityTemplate::getOr ( )
inlinenoexcept

Gets a set of components of types C0, C1 and Cs.

If any of the components are not present, a new component is created.

Template Parameters
C0The type of the first component to be retrieved
C1The type of the second component to be retrieved
CsThe remaining types of the components to be retrieved
Returns
A reference to the existing components

◆ getOr() [2/2]

template<CComponent C>
C & CeresEngine::EntityTemplate::getOr ( )
inlinenoexcept

Gets a component of type C.

If a component of type C is not present, a new component is created.

Template Parameters
Cthe component type to be retrieved
Returns
A reference to the existing component

◆ has()

template<CComponent C, CComponent... Cs>
bool CeresEngine::EntityTemplate::has ( ) const
inlinenoexcept

Checks if the entity has all components of types Cs.

Template Parameters
Csthe component types to be checked
Returns
True if the components are present, false otherwise

◆ remove()

template<CComponent C>
void CeresEngine::EntityTemplate::remove ( )
inlinenoexcept

Removes a component of type C from the entity.

Template Parameters
Cthe component type to be removed

◆ set()

template<CComponent C, typename... Args>
C & CeresEngine::EntityTemplate::set ( Args &&...  args) const
inlinenoexcept

Sets a component.

If a component of type C is already present, a new component is created and added. If the component already exists, its contents are replaced.

Template Parameters
Cthe component type to be set
Argsthe component constructor argument types
Parameters
argsthe component constructor arguments
Returns
A reference to the newly added or replaced component

Member Data Documentation

◆ mComponents

FlatMap<ComponentID, UPtr<ComponentData> > CeresEngine::EntityTemplate::mComponents
private

◆ mName

String CeresEngine::EntityTemplate::mName
private

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