ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::serialization::EntityComponentSerializer< Component, Serializer > Class Template Reference

Entity component serializer class bound to a specific component and a serializer type. More...

#include <EntityComponentSerializer.hpp>

Inheritance diagram for ecstasy::serialization::EntityComponentSerializer< Component, Serializer >:
Collaboration diagram for ecstasy::serialization::EntityComponentSerializer< Component, Serializer >:

Public Types

using StorageType = getStorageType< Component >
 Type of the storage used to store the component.
 

Public Member Functions

 EntityComponentSerializer () noexcept
 Construct a new Component Rtti.
 
 ~EntityComponentSerializer () noexcept override=default
 Destroy the Component Rtti.
 
ISerializersave (ISerializer &serializer, const IStorage &storage, const RegistryEntity &entity) const override final
 Save the component to the serializer.
 
ISerializerload (ISerializer &serializer, IStorage &storage, RegistryEntity &entity) const override final
 Load an entity component from the serializer.
 
const std::type_infogetType () const noexcept override final
 Get the type info of the component.
 
- Public Member Functions inherited from ecstasy::serialization::IEntityComponentSerializer
virtual ~IEntityComponentSerializer () noexcept=default
 Destroy the IEntityComponentSerializer.
 
virtual ISerializersave (ISerializer &serializer, const IStorage &storage, const RegistryEntity &entity) const =0
 Save the component to the serializer.
 
virtual ISerializerload (ISerializer &serializer, IStorage &storage, RegistryEntity &entity) const =0
 Load an entity component from the serializer.
 
virtual const std::type_infogetType () const noexcept=0
 Get the type info of the component.
 

Detailed Description

template<typename Component, std::derived_from< ISerializer > Serializer>
class ecstasy::serialization::EntityComponentSerializer< Component, Serializer >

Entity component serializer class bound to a specific component and a serializer type.

The class instance doesn't contains any data except its vtable.

Template Parameters
ComponentType of the component to serialize.
SerializerType of the serializer to use to serialize 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 (2024-10-04)

Definition at line 33 of file EntityComponentSerializer.hpp.

Member Typedef Documentation

◆ StorageType

template<typename Component , std::derived_from< ISerializer > Serializer>
using ecstasy::serialization::EntityComponentSerializer< Component, Serializer >::StorageType = getStorageType<Component>

Type of the storage used to store the component.

Definition at line 36 of file EntityComponentSerializer.hpp.

Constructor & Destructor Documentation

◆ EntityComponentSerializer()

template<typename Component , std::derived_from< ISerializer > Serializer>
ecstasy::serialization::EntityComponentSerializer< Component, Serializer >::EntityComponentSerializer ( )
inlinenoexcept

Construct a new Component Rtti.

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-10-04)

Definition at line 44 of file EntityComponentSerializer.hpp.

44 : IEntityComponentSerializer()
45 {
46 }

◆ ~EntityComponentSerializer()

template<typename Component , std::derived_from< ISerializer > Serializer>
ecstasy::serialization::EntityComponentSerializer< Component, Serializer >::~EntityComponentSerializer ( )
overridedefaultnoexcept

Destroy the Component Rtti.

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-10-04)

Member Function Documentation

◆ getType()

template<typename Component , std::derived_from< ISerializer > Serializer>
const std::type_info & ecstasy::serialization::EntityComponentSerializer< Component, Serializer >::getType ( ) const
inlinefinaloverridevirtualnoexcept

Get the type info of the component.

Returns
const std::type_info& Reference to the type info of 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 (2024-10-25)

Implements ecstasy::serialization::IEntityComponentSerializer.

Definition at line 77 of file EntityComponentSerializer.hpp.

78 {
79 return typeid(Component);
80 }

◆ load()

template<typename Component , std::derived_from< ISerializer > Serializer>
ISerializer & ecstasy::serialization::EntityComponentSerializer< Component, Serializer >::load ( ISerializer serializer,
IStorage storage,
RegistryEntity entity 
) const
inlinefinaloverridevirtual

Load an entity component from the serializer.

Parameters
[in]serializerReference to the serializer to load the component from.
[in]storageReference to the storage to load the component to.
[in]entityReference to the entity to load/update the component to.
Returns
ISerializer& Reference to the serializer for chaining.
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-10-04)

Implements ecstasy::serialization::IEntityComponentSerializer.

Definition at line 65 of file EntityComponentSerializer.hpp.

66 {
67 if (!storage.contains(entity.getIndex())) {
68 dynamic_cast<StorageType &>(storage).insert(
69 entity.getIndex(), dynamic_cast<Serializer &>(serializer).template load<Component>());
70 return serializer;
71 } else
72 return dynamic_cast<Serializer &>(serializer)
73 .template update<Component>(dynamic_cast<StorageType &>(storage).at(entity.getIndex()));
74 }
getStorageType< Component > StorageType
Type of the storage used to store the component.

◆ save()

template<typename Component , std::derived_from< ISerializer > Serializer>
ISerializer & ecstasy::serialization::EntityComponentSerializer< Component, Serializer >::save ( ISerializer serializer,
const IStorage storage,
const RegistryEntity entity 
) const
inlinefinaloverridevirtual

Save the component to the serializer.

Parameters
[in]serializerReference to the serializer to save the component to.
[in]storageConst reference to the storage containing the component.
[in]entityConst reference to the entity associated with the component.
Returns
ISerializer& Reference to the serializer for chaining.
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-10-04)

Implements ecstasy::serialization::IEntityComponentSerializer.

Definition at line 56 of file EntityComponentSerializer.hpp.

58 {
59 return dynamic_cast<Serializer &>(serializer)
60 .template saveEntityComponent<Component>(
61 dynamic_cast<const StorageType &>(storage).at(entity.getIndex()));
62 }

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