ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::Entities::Builder Class Reference

Entities builder to add multiple component to an entity on creation. More...

#include <Entities.hpp>

Collaboration diagram for ecstasy::Entities::Builder:

Public Member Functions

 Builder (const Builder &other)=delete
 Cannot copy a builder.
 
template<IsStorage S, typename... Args>
Builderwith (S &storage, Args &&...args)
 Add a component to the builder target entity.
 
template<IsContainerStorage S>
Builderwith (S &storage, std::initializer_list< typename S::Component::value_type > list)
 Add a component to the builder target entity.
 
Entity build ()
 Finalize the entity, making it alive.
 
const EntitygetEntity () const noexcept
 Get a const reference to the entity being built.
 

Private Member Functions

 Builder (Entities &parent, Entity entity) noexcept
 Construct a new Builder, this method can only be called by an Entities.
 
void assertNotBuilt () const
 Verify if the builder has not already been consumed.
 

Private Attributes

Entities_parent
 Reference to the parent Entities.
 
Entity _entity
 Entity being built.
 
bool _built
 Whether the builder has been consumed.
 
friend Entities
 

Detailed Description

Entities builder to add multiple component to an entity on creation.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 38 of file Entities.hpp.

Constructor & Destructor Documentation

◆ Builder() [1/2]

ecstasy::Entities::Builder::Builder ( const Builder other)
delete

Cannot copy a builder.

Parameters
[in]otherbuilder to copy.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

◆ Builder() [2/2]

ecstasy::Entities::Builder::Builder ( Entities parent,
Entity  entity 
)
privatenoexcept

Construct a new Builder, this method can only be called by an Entities.

Parameters
[in]parentEntities object creating this builder.
[in]entityEntity target (modified by the builder).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 16 of file Entities.cpp.

17 : _parent(parent), _entity(entity), _built(false)
18 {
19 }
Entity _entity
Entity being built.
Definition Entities.hpp:133
Entities & _parent
Reference to the parent Entities.
Definition Entities.hpp:131
bool _built
Whether the builder has been consumed.
Definition Entities.hpp:135

Member Function Documentation

◆ assertNotBuilt()

void ecstasy::Entities::Builder::assertNotBuilt ( ) const
private

Verify if the builder has not already been consumed.

Exceptions
std::logic_errorif _built is true.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 21 of file Entities.cpp.

22 {
23 if (_built) [[unlikely]]
24 throw std::logic_error(
25 "Try to change entity using an Entities::Builder already consumed (build() has been called)");
26 }

◆ build()

Entity ecstasy::Entities::Builder::build ( )

Finalize the entity, making it alive.

Note
This method can only be called once.
Returns
Entity Newly created entity.
Exceptions
std::logic_errorIf the builder was already consumed.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 28 of file Entities.cpp.

29 {
31 _built = true;
33 return _entity;
34 }
void assertNotBuilt() const
Verify if the builder has not already been consumed.
Definition Entities.cpp:21
util::BitSet _alive
Mask of alive entities.
Definition Entities.hpp:303
constexpr Index getIndex() const noexcept
Get the entity identifier,.
Definition Entity.hpp:50

◆ getEntity()

const Entity & ecstasy::Entities::Builder::getEntity ( ) const
inlinenoexcept

Get a const reference to the entity being built.

Warning
This method is here in case you need the entity id before calling build(). For example if you need it inside a component constructor.
Returns
const Entity& Entity being built.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-06-07)

Definition at line 124 of file Entities.hpp.

125 {
126 return _entity;
127 }

◆ with() [1/2]

template<IsStorage S, typename... Args>
Builder & ecstasy::Entities::Builder::with ( S &  storage,
Args &&...  args 
)
inline

Add a component to the builder target entity.

Template Parameters
SComponent storage type.
ArgsType of the Component constructor parameters
Parameters
[in]storageComponent storage.
[in]argsArguments to forward to the component constructor.
Returns
Builder& this.
Exceptions
std::logic_errorIf the builder was already consumed or if the entity already has the component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 68 of file Entities.hpp.

69 {
71 _entity.add(storage, std::forward<Args>(args)...);
72 return *this;
73 }
S::Component & add(S &storage, Args &&...args)
Add a component to the entity.
Definition Entity.hpp:111

◆ with() [2/2]

template<IsContainerStorage S>
Builder & ecstasy::Entities::Builder::with ( S &  storage,
std::initializer_list< typename S::Component::value_type >  list 
)
inline

Add a component to the builder target entity.

Template Parameters
SComponent storage type.
Parameters
[in]storageComponent storage.
[in]listInitializer list to forward to the component constructor.
Returns
Builder& this.
Exceptions
std::logic_errorIf the builder was already consumed or if the entity already has the component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2023-01-31)

Definition at line 92 of file Entities.hpp.

93 {
95 _entity.add(storage, list);
96 return *this;
97 }

Member Data Documentation

◆ _built

bool ecstasy::Entities::Builder::_built
private

Whether the builder has been consumed.

Definition at line 135 of file Entities.hpp.

◆ _entity

Entity ecstasy::Entities::Builder::_entity
private

Entity being built.

Definition at line 133 of file Entities.hpp.

◆ _parent

Entities& ecstasy::Entities::Builder::_parent
private

Reference to the parent Entities.

Definition at line 131 of file Entities.hpp.

◆ Entities

friend ecstasy::Entities::Builder::Entities
private

Definition at line 158 of file Entities.hpp.


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