GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::execution::EntityBuilder< EntReg > Class Template Reference

Temporary reference to an incomplete entity that is currently being built inside of an EntityRegistry and will be automatically destroyed and cleaned up if EntityBuilder::build() is not successfully called by the end of the scope. More...

#include <GREM/execution/EntityRegistry.hpp>

Public Member Functions

GREM_ALWAYS_INLINE constexpr EntityBuilder (EntReg &registry, EntityID entityID) noexcept
 Construct an entity builder.
 ~EntityBuilder ()
 Destructor.
 EntityBuilder (const EntityBuilder &)=delete
 Copying an entity builder is not allowed.
 EntityBuilder (EntityBuilder &&other) noexcept
 Move constructor.
EntityBuilder & operator= (const EntityBuilder &)=delete
 Copying an entity builder is not allowed.
EntityBuilder & operator= (EntityBuilder &&)=delete
 Relocating an entity builder is not allowed.
EntityID setEntityFlags (EntityID::Flags newFlags)
 Update the flags embedded in the entity's handle.
GREM_ALWAYS_INLINE EntReg & getRegistry () noexcept
 Get the underlying entity registry containing the entity being built.
GREM_ALWAYS_INLINE const EntReg & getRegistry () const noexcept
 Get the underlying entity registry containing the entity being built.
GREM_ALWAYS_INLINE EntityID getEntityID () const noexcept
 Get the entity handle of the entity being built.
template<component T, typename... Args>
T & addComponent (Args &&... args)
 Add a component to the entity being built.
template<component T, typename... Args>
T * addComponentIfMissing (Args &&... args)
 Add a component to the entity being built if it doesn't already have it.
template<component T>
T & addOrAssignComponent (T &&value)
 Add a component to the entity being built, or assign to it if it already has one.
template<component T>
T & addOrAssignComponent (const T &value)
 Add a component to the entity being built, or assign to it if it already has one.
template<component T>
bool removeComponent () noexcept
 Erase a component from the entity being built.
bool removeAllComponents () noexcept
 Erase all components from the entity being built.
template<component T>
bool hasComponent () const noexcept
 Check if the entity being built has a specific component.
template<component T>
T & getComponent ()
 Get a specific component of the entity being built.
template<component T>
const T & getComponent () const
 Get a specific component of the entity being built.
template<component T, typename U>
T getComponentOr (U &&defaultValue) const
 Get a specific component of the entity being built, or a default value in case the entity doesn't exist or doesn't have the specified component.
template<component T>
T * findComponent () noexcept
 Try to get a specific component of the entity being built.
template<component T>
const T * findComponent () const noexcept
 Try to get a specific component of the entity being built.
GREM_ALWAYS_INLINE EntityID build ()
 Finish building the entity, allowing it to persist.

Detailed Description

template<typename EntReg>
class grem::execution::EntityBuilder< EntReg >

Temporary reference to an incomplete entity that is currently being built inside of an EntityRegistry and will be automatically destroyed and cleaned up if EntityBuilder::build() is not successfully called by the end of the scope.

Template Parameters
EntRegconcrete specialization of EntityRegistry being referenced.

Constructor & Destructor Documentation

◆ EntityBuilder() [1/3]

template<typename EntReg>
GREM_ALWAYS_INLINE constexpr grem::execution::EntityBuilder< EntReg >::EntityBuilder ( EntReg & registry,
EntityID entityID )
inlinenodiscardconstexprnoexcept

Construct an entity builder.

Parameters
registryentity registry containing the entity being built.
entityIDentity handle of the entity being built.

◆ ~EntityBuilder()

template<typename EntReg>
grem::execution::EntityBuilder< EntReg >::~EntityBuilder ( )
inline

Destructor.

◆ EntityBuilder() [2/3]

template<typename EntReg>
grem::execution::EntityBuilder< EntReg >::EntityBuilder ( const EntityBuilder< EntReg > & )
delete

Copying an entity builder is not allowed.

◆ EntityBuilder() [3/3]

template<typename EntReg>
grem::execution::EntityBuilder< EntReg >::EntityBuilder ( EntityBuilder< EntReg > && other)
inlinenoexcept

Move constructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename EntReg>
EntityBuilder & grem::execution::EntityBuilder< EntReg >::operator= ( const EntityBuilder< EntReg > & )
delete

Copying an entity builder is not allowed.

◆ operator=() [2/2]

template<typename EntReg>
EntityBuilder & grem::execution::EntityBuilder< EntReg >::operator= ( EntityBuilder< EntReg > && )
delete

Relocating an entity builder is not allowed.

◆ setEntityFlags()

template<typename EntReg>
EntityID grem::execution::EntityBuilder< EntReg >::setEntityFlags ( EntityID::Flags newFlags)
inline

Update the flags embedded in the entity's handle.

Parameters
newFlagsnew flags to set.
Returns
the new entity handle with the updated flags, or an invalid default-constructed handle if the internal entity handle was not valid.

◆ getRegistry() [1/2]

template<typename EntReg>
GREM_ALWAYS_INLINE EntReg & grem::execution::EntityBuilder< EntReg >::getRegistry ( )
inlinenodiscardnoexcept

Get the underlying entity registry containing the entity being built.

Returns
a reference to the underlying entity registry.

◆ getRegistry() [2/2]

template<typename EntReg>
GREM_ALWAYS_INLINE const EntReg & grem::execution::EntityBuilder< EntReg >::getRegistry ( ) const
inlinenodiscardnoexcept

Get the underlying entity registry containing the entity being built.

Returns
a read-only reference to the underlying entity registry.

◆ getEntityID()

template<typename EntReg>
GREM_ALWAYS_INLINE EntityID grem::execution::EntityBuilder< EntReg >::getEntityID ( ) const
inlinenodiscardnoexcept

Get the entity handle of the entity being built.

Returns
the underlying entity handle.

◆ addComponent()

template<typename EntReg>
template<component T, typename... Args>
T & grem::execution::EntityBuilder< EntReg >::addComponent ( Args &&... args)
inline

Add a component to the entity being built.

Template Parameters
Tcomponent type to add.
Parameters
argsarguments to forward to the component constructor.
Returns
a reference to the newly created component.
Exceptions
std::logic_errorif the entity already has the specified component.
std::out_of_rangeif the underlying handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the component constructor.

◆ addComponentIfMissing()

template<typename EntReg>
template<component T, typename... Args>
T * grem::execution::EntityBuilder< EntReg >::addComponentIfMissing ( Args &&... args)
inline

Add a component to the entity being built if it doesn't already have it.

Template Parameters
Tcomponent type to add.
Parameters
argsarguments to forward to the component constructor.
Returns
a pointer to the newly created component, or nullptr if the entity already has the specified component.
Exceptions
std::out_of_rangeif the underlying handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the component constructor.

◆ addOrAssignComponent() [1/2]

template<typename EntReg>
template<component T>
T & grem::execution::EntityBuilder< EntReg >::addOrAssignComponent ( T && value)
inline

Add a component to the entity being built, or assign to it if it already has one.

Template Parameters
Tcomponent type to add or assign.
Parameters
valuecomponent value to add or assign.
Returns
a reference to the newly created component, or to the existing component if the entity already had one.
Exceptions
std::out_of_rangeif the underlying handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the move constructor or move assignment operator of the component type.

◆ addOrAssignComponent() [2/2]

template<typename EntReg>
template<component T>
T & grem::execution::EntityBuilder< EntReg >::addOrAssignComponent ( const T & value)
inline

Add a component to the entity being built, or assign to it if it already has one.

Template Parameters
Tcomponent type to add or assign.
Parameters
valuecomponent value to add or assign.
Returns
a reference to the newly created component, or to the existing component if the entity already had one.
Exceptions
std::out_of_rangeif the underlying handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the copy constructor or copy assignment operator of the component type.

◆ removeComponent()

template<typename EntReg>
template<component T>
bool grem::execution::EntityBuilder< EntReg >::removeComponent ( )
inlinenoexcept

Erase a component from the entity being built.

Template Parameters
Tcomponent type to remove.
Returns
true if the underlying entity handle corresponded to a valid entity with the specified component that was successfully removed, false otherwise.

◆ removeAllComponents()

template<typename EntReg>
bool grem::execution::EntityBuilder< EntReg >::removeAllComponents ( )
inlinenoexcept

Erase all components from the entity being built.

Returns
true if the underlying entity handle corresponded to a valid entity, false otherwise.

◆ hasComponent()

template<typename EntReg>
template<component T>
bool grem::execution::EntityBuilder< EntReg >::hasComponent ( ) const
inlinenodiscardnoexcept

Check if the entity being built has a specific component.

Template Parameters
Tcomponent type to check for.
Returns
true if the underlying entity handle corresponds to a valid entity with the specified component, false otherwise.

◆ getComponent() [1/2]

template<typename EntReg>
template<component T>
T & grem::execution::EntityBuilder< EntReg >::getComponent ( )
inlinenodiscard

Get a specific component of the entity being built.

Template Parameters
Tcomponent type to get.
Returns
a reference to the specified component.
Exceptions
std::out_of_rangeif the underlying entity handle does not correspond to a valid entity with the specified component.

◆ getComponent() [2/2]

template<typename EntReg>
template<component T>
const T & grem::execution::EntityBuilder< EntReg >::getComponent ( ) const
inlinenodiscard

Get a specific component of the entity being built.

Template Parameters
Tcomponent type to get.
Returns
a read-only reference to the specified component.
Exceptions
std::out_of_rangeif the underlying entity handle does not correspond to a valid entity with the specified component.

◆ getComponentOr()

template<typename EntReg>
template<component T, typename U>
T grem::execution::EntityBuilder< EntReg >::getComponentOr ( U && defaultValue) const
inlinenodiscard

Get a specific component of the entity being built, or a default value in case the entity doesn't exist or doesn't have the specified component.

Template Parameters
Tcomponent type to get.
Parameters
defaultValuedefault value to return in case the underlying entity handle does not correspond to a valid entity with the specified component.
Returns
a copy of the specified component, or the specified default value if the underlying entity handle does not correspond to a valid entity with the specified component.

◆ findComponent() [1/2]

template<typename EntReg>
template<component T>
T * grem::execution::EntityBuilder< EntReg >::findComponent ( )
inlinenodiscardnoexcept

Try to get a specific component of the entity being built.

Template Parameters
Tcomponent type to get.
Returns
a pointer to the specified component, or nullptr if the underlying entity handle does not correspond to a valid entity with the specified component.

◆ findComponent() [2/2]

template<typename EntReg>
template<component T>
const T * grem::execution::EntityBuilder< EntReg >::findComponent ( ) const
inlinenodiscardnoexcept

Try to get a specific component of the entity being built.

Template Parameters
Tcomponent type to get.
Returns
a read-only pointer to the specified component, or nullptr if the underlying entity handle does not correspond to a valid entity with the specified component.

◆ build()

template<typename EntReg>
GREM_ALWAYS_INLINE EntityID grem::execution::EntityBuilder< EntReg >::build ( )
inline

Finish building the entity, allowing it to persist.

This will set the entity builder's underlying entity handle to an invalid default-constructed handle, meaning the entity builder can no longer be used, and the entity will no longer get destroyed and cleaned up when the entity builder goes out of scope.

Returns
the entity handle of the completed entity that was built.

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