ECSTASY
All in the name
Loading...
Searching...
No Matches
EntityComponentSerializer.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_SERIALIZATION_ENTITY_COMPONENT_SERIALIZER_HPP_
13#define ECSTASY_SERIALIZATION_ENTITY_COMPONENT_SERIALIZER_HPP_
14
18
20{
32 template <typename Component, std::derived_from<ISerializer> Serializer>
34 public:
37
45 {
46 }
53 ~EntityComponentSerializer() noexcept override = default;
54
57 ISerializer &serializer, const IStorage &storage, const RegistryEntity &entity) const override final
58 {
59 return dynamic_cast<Serializer &>(serializer)
60 .template saveEntityComponent<Component>(
61 dynamic_cast<const StorageType &>(storage).at(entity.getIndex()));
62 }
63
65 ISerializer &load(ISerializer &serializer, IStorage &storage, RegistryEntity &entity) const override final
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 }
75
77 const std::type_info &getType() const noexcept override final
78 {
79 return typeid(Component);
80 }
81 };
82
83} // namespace ecstasy::serialization
84
85#endif /* !ECSTASY_SERIALIZATION_ENTITY_COMPONENT_SERIALIZER_HPP_ */
File containing the IEntityComponentSerializer class, used to serialize entity components from an ISt...
Entity containing a reference to the registry. Allows to find storage implicitly.
Storage concepts and utilities.
Base class of all components storage.
Definition IStorage.hpp:44
Entity containing a reference to the registry.
Entity component serializer class bound to a specific component and a serializer type.
EntityComponentSerializer() noexcept
Construct a new Component Rtti.
~EntityComponentSerializer() noexcept override=default
Destroy the Component Rtti.
getStorageType< Component > StorageType
Type of the storage used to store the component.
ISerializer & save(ISerializer &serializer, const IStorage &storage, const RegistryEntity &entity) const override final
Save the component to the serializer.
const std::type_info & getType() const noexcept override final
Get the type info of the component.
ISerializer & load(ISerializer &serializer, IStorage &storage, RegistryEntity &entity) const override final
Load an entity component from the serializer.
Type erased interface for serializing entity components.
Interface for all serializer classes.
Namespace regrouping the serialization ecstasy classes.
Definition AType.hpp:26
typename getStorageTypeImpl< C >::type getStorageType
Get the storage type to use for a component.