ECSTASY
All in the name
Loading...
Searching...
No Matches
AType.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_RTTI_ATYPE_HPP_
13#define ECSTASY_RTTI_ATYPE_HPP_
14
15#include <optional>
16#include <typeindex>
17#include <string_view>
18#include <type_traits>
19#include <unordered_map>
20
22
23namespace ecstasy
24{
25 namespace serialization
26 {
28 }
29
30 namespace rtti
31 {
46 class AType {
47 public:
54 virtual ~AType() noexcept = default;
55
64 [[nodiscard]] virtual const std::type_info &getStorageTypeInfo() const noexcept = 0;
65
74 [[nodiscard]] virtual const std::type_info &getTypeInfo() const noexcept = 0;
75
86 [[nodiscard]] virtual size_t getHash() const noexcept = 0;
87
98 [[nodiscard]] virtual std::string_view getTypeName() const noexcept = 0;
99
106 [[nodiscard]] std::strong_ordering operator<=>(const AType &rhs) const noexcept;
107
120 [[nodiscard]] bool operator==(const AType &rhs) const noexcept;
121
132 [[nodiscard]] bool operator==(const std::type_info &rhs) const noexcept;
133
144 [[nodiscard]] bool operator==(const std::string_view &rhs) const noexcept;
145
156 template <std::derived_from<ecstasy::serialization::ISerializer> Serializer>
157 [[nodiscard]] bool hasSerializer() const noexcept
158 {
159 return _serializers.contains(std::type_index(typeid(Serializer)));
160 }
161
174 template <std::derived_from<ecstasy::serialization::ISerializer> Serializer>
176 {
177 return *_serializers.at(std::type_index(typeid(Serializer)));
178 }
179
191 template <std::derived_from<ecstasy::serialization::ISerializer> Serializer>
193 tryGetSerializer() const noexcept
194 {
195 auto res = _serializers.find(std::type_index(typeid(Serializer)));
196 if (res != _serializers.end())
197 return std::ref(*res->second);
198 return std::nullopt;
199 }
200
201 protected:
205 };
206
215 template <typename T>
216 concept is_comparable_with_atype = requires(AType &a, T t) {
217 {
218 a == t
219 } -> std::convertible_to<bool>; // Ensure a == t returns a boolean-like result
220 };
221
222 } // namespace rtti
223} // namespace ecstasy
224
225#endif /* !ECSTASY_RTTI_ATYPE_HPP_ */
Interface for all serializer classes.
T at(T... args)
Type erased interface for cross-platform type information.
Definition AType.hpp:46
virtual size_t getHash() const noexcept=0
Get the cross-platform hash of the type name.
ecstasy::serialization::IEntityComponentSerializer & getSerializer() const noexcept
Get a reference to the entity component serializer for the given serializer type.
Definition AType.hpp:175
std::optional< std::reference_wrapper< ecstasy::serialization::IEntityComponentSerializer > > tryGetSerializer() const noexcept
Try to get a reference to the entity component serializer for the given serializer type.
Definition AType.hpp:193
virtual const std::type_info & getTypeInfo() const noexcept=0
Get the type info of T.
bool hasSerializer() const noexcept
Check if a serializer is registered for the component type.
Definition AType.hpp:157
std::unordered_map< std::type_index, std::unique_ptr< ecstasy::serialization::IEntityComponentSerializer > > _serializers
Hash of the type name.
Definition AType.hpp:204
virtual std::string_view getTypeName() const noexcept=0
Get the name of T.
virtual const std::type_info & getStorageTypeInfo() const noexcept=0
Get the type info of T storage type, as find by getStorageType<T>().
virtual ~AType() noexcept=default
Destroy the AType instance.
Type erased interface for serializing entity components.
Concept to check if a type is comparable with AType.
Definition AType.hpp:216
T contains(T... args)
T end(T... args)
T find(T... args)
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
T ref(T... args)