ECSTASY
All in the name
Loading...
Searching...
No Matches
Type.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_RTTI_TYPE_HPP_
13#define ECSTASY_RTTI_TYPE_HPP_
14
15#include <typeindex>
16#include <string_view>
17
21
22namespace ecstasy
23{
24 namespace rtti
25 {
34 template <typename T>
35 class Type : public AType {
36 public:
39
48 Type() noexcept : AType()
49 {
50 setTypeName(typeid(T).name());
51 }
52
62 Type(std::string_view name) noexcept : AType()
63 {
64 setTypeName(name);
65 }
66
68 ~Type() noexcept override final = default;
69
71 [[nodiscard]] const std::type_info &getStorageTypeInfo() const noexcept override final
72 {
73 return typeid(StorageType);
74 }
75
77 [[nodiscard]] const std::type_info &getTypeInfo() const noexcept override final
78 {
79 return typeid(T);
80 }
81
83 [[nodiscard]] size_t getHash() const noexcept override final
84 {
85 return _hash;
86 }
87
89 [[nodiscard]] std::string_view getTypeName() const noexcept override final
90 {
91 return _name;
92 }
93
104 template <std::derived_from<ecstasy::serialization::ISerializer> Serializer>
106 {
107 std::type_index index = std::type_index(typeid(Serializer));
108 auto iter = _serializers.find(index);
109
110 if (iter != _serializers.end())
111 return *iter->second;
112
113 return *_serializers
115 .first->second;
116 }
117
118 private:
123
132 void setTypeName(std::string_view name) noexcept
133 {
134 _name = name;
136 }
137 };
138
139 } // namespace rtti
140} // namespace ecstasy
141
142#endif /* !ECSTASY_RTTI_TYPE_HPP_ */
File containing the AType interface for cross-platform type information.
Entity component serializer class bound to a specific component and a serializer type.
Storage concepts and utilities.
Type erased interface for cross-platform type information.
Definition AType.hpp:46
std::unordered_map< std::type_index, std::unique_ptr< ecstasy::serialization::IEntityComponentSerializer > > _serializers
Hash of the type name.
Definition AType.hpp:204
Type erased interface for cross-platform type information.
Definition Type.hpp:35
std::string_view _name
Name of the component type.
Definition Type.hpp:120
~Type() noexcept override final=default
Destroy the AType instance.
std::string_view getTypeName() const noexcept override final
Get the name of T.
Definition Type.hpp:89
std::size_t _hash
Hash of the component type name. Should be cross-platform.
Definition Type.hpp:122
size_t getHash() const noexcept override final
Get the cross-platform hash of the type name.
Definition Type.hpp:83
getStorageType< T > StorageType
Type of the storage used to store the component.
Definition Type.hpp:38
const std::type_info & getTypeInfo() const noexcept override final
Get the type info of T.
Definition Type.hpp:77
serialization::IEntityComponentSerializer & registerSerializer() noexcept
Register a new serializer for the component type.
Definition Type.hpp:105
Type(std::string_view name) noexcept
Construct a new Type instance with a custom name.
Definition Type.hpp:62
void setTypeName(std::string_view name) noexcept
Set the Type name.
Definition Type.hpp:132
const std::type_info & getStorageTypeInfo() const noexcept override final
Get the type info of T storage type, as find by getStorageType<T>().
Definition Type.hpp:71
Type() noexcept
Construct a new Type instance.
Definition Type.hpp:48
Entity component serializer class bound to a specific component and a serializer type.
Type erased interface for serializing entity components.
T emplace(T... args)
T end(T... args)
T find(T... args)
T make_unique(T... args)
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
typename getStorageTypeImpl< C >::type getStorageType
Get the storage type to use for a component.