ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::Registry::EntityBuilder Class Reference

Entity Builder using the registry storages. More...

#include <Registry.hpp>

Collaboration diagram for ecstasy::Registry::EntityBuilder:

Public Member Functions

 EntityBuilder (const EntityBuilder &other)=delete
 Copy constructor is deleted.
 
template<typename C , typename... Qs, typename... Args>
EntityBuilderwith (Args &&...args)
 Add a component to the builder target entity.
 
template<typename C >
requires requires() { typename C::value_type; }
EntityBuilderwith (std::initializer_list< typename C::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.
 
constexpr const RegistrygetRegistry () const noexcept
 Get a const reference to the registry.
 
constexpr RegistrygetRegistry () noexcept
 Get a reference to the registry.
 

Private Member Functions

 EntityBuilder (Registry &registry) noexcept
 Construct a new EntityBuilder, this method can only be called by a Registry.
 

Private Attributes

Registry_registry
 Owning registry.
 
Entities::Builder _builder
 Entities builder.
 
friend Registry
 

Detailed Description

Entity Builder using the registry storages.

Note
Use Registry::entityBuilder() to create an instance.
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 537 of file Registry.hpp.

Constructor & Destructor Documentation

◆ EntityBuilder() [1/2]

ecstasy::Registry::EntityBuilder::EntityBuilder ( const EntityBuilder other)
delete

Copy constructor is deleted.

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)

◆ EntityBuilder() [2/2]

ecstasy::Registry::EntityBuilder::EntityBuilder ( Registry registry)
privatenoexcept

Construct a new EntityBuilder, this method can only be called by a Registry.

Parameters
[in]registryParent registry.
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 17 of file Registry.cpp.

18 : _registry(registry), _builder(registry.getResource<Entities>().get().builder())
19 {
20 }
Entities::Builder _builder
Entities builder.
Definition Registry.hpp:643
Registry & _registry
Owning registry.
Definition Registry.hpp:641

Member Function Documentation

◆ build()

Entity ecstasy::Registry::EntityBuilder::build ( )

Finalize the entity, making it alive.

Note
The builder is consumed after this call. Any further with/build call will throw an exception.
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 22 of file Registry.cpp.

23 {
24 return _builder.build();
25 }
Entity build()
Finalize the entity, making it alive.
Definition Entities.cpp:28

◆ getEntity()

const Entity & ecstasy::Registry::EntityBuilder::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 610 of file Registry.hpp.

611 {
612 return _builder.getEntity();
613 }
const Entity & getEntity() const noexcept
Get a const reference to the entity being built.
Definition Entities.hpp:124

◆ getRegistry() [1/2]

constexpr const Registry & ecstasy::Registry::EntityBuilder::getRegistry ( ) const
inlineconstexprnoexcept

Get a const reference to the registry.

Returns
const Registry& Const reference to the registry
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-08-27)

Definition at line 622 of file Registry.hpp.

623 {
624 return _registry;
625 }

◆ getRegistry() [2/2]

constexpr Registry & ecstasy::Registry::EntityBuilder::getRegistry ( )
inlineconstexprnoexcept

Get a reference to the registry.

Returns
Registry& reference to the registry
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-08-27)

Definition at line 634 of file Registry.hpp.

635 {
636 return _registry;
637 }

◆ with() [1/2]

template<typename C , typename... Qs, typename... Args>
EntityBuilder & ecstasy::Registry::EntityBuilder::with ( Args &&...  args)
inline

Add a component to the builder target entity.

Template Parameters
CComponent type.
ArgsType of the Component constructor parameters
Parameters
[in]argsArguments to forward to the component constructor.
Returns
EntityBuilder& 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 566 of file Registry.hpp.

567 {
568 _builder.with(_registry.getStorageSafe<C>(), _registry.getFromType<Qs>()..., std::forward<Args>(args)...);
569 return *this;
570 }
Builder & with(S &storage, Args &&...args)
Add a component to the builder target entity.
Definition Entities.hpp:68
getStorageType< C > & getStorageSafe() noexcept
Get the Storage of a component and create it if not found.
constexpr getStorageType< C > & getFromType()
Get a registry object reference (storage, resource, system, or the registry itself) from its type.
Definition Registry.hpp:131

◆ with() [2/2]

template<typename C >
requires requires() { typename C::value_type; }
EntityBuilder & ecstasy::Registry::EntityBuilder::with ( std::initializer_list< typename C::value_type >  list)
inline

Add a component to the builder target entity.

Template Parameters
CComponent type.
Parameters
[in]listInitializer list to forward to the component constructor.
Returns
EntityBuilder& 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 589 of file Registry.hpp.

590 {
592 return *this;
593 }

Member Data Documentation

◆ _builder

Entities::Builder ecstasy::Registry::EntityBuilder::_builder
private

Entities builder.

Definition at line 643 of file Registry.hpp.

◆ _registry

Registry& ecstasy::Registry::EntityBuilder::_registry
private

Owning registry.

Definition at line 641 of file Registry.hpp.

◆ Registry

friend ecstasy::Registry::EntityBuilder::Registry
private

Definition at line 655 of file Registry.hpp.


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