ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::rtti::AType Class Referenceabstract

Type erased interface for cross-platform type information. More...

#include <AType.hpp>

Inheritance diagram for ecstasy::rtti::AType:
Collaboration diagram for ecstasy::rtti::AType:

Public Member Functions

virtual ~AType () noexcept=default
 Destroy the AType instance.
 
virtual const std::type_infogetStorageTypeInfo () const noexcept=0
 Get the type info of T storage type, as find by getStorageType<T>().
 
virtual const std::type_infogetTypeInfo () const noexcept=0
 Get the type info of T.
 
virtual size_t getHash () const noexcept=0
 Get the cross-platform hash of the type name.
 
virtual std::string_view getTypeName () const noexcept=0
 Get the name of T.
 
std::strong_ordering operator<=> (const AType &rhs) const noexcept
 Compare two AType instances by their hash.
 
bool operator== (const AType &rhs) const noexcept
 Compare if two AType instances are equal by their hash.
 
bool operator== (const std::type_info &rhs) const noexcept
 Compare if an AType instance is matching a type info.
 
bool operator== (const std::string_view &rhs) const noexcept
 Compare if an AType instance is matching a type name.
 
template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
bool hasSerializer () const noexcept
 Check if a serializer is registered for the component type.
 
template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
ecstasy::serialization::IEntityComponentSerializergetSerializer () const noexcept
 Get a reference to the entity component serializer for the given serializer type.
 
template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
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.
 

Protected Attributes

std::unordered_map< std::type_index, std::unique_ptr< ecstasy::serialization::IEntityComponentSerializer > > _serializers
 Hash of the type name.
 

Detailed Description

Type erased interface for cross-platform type information.

The cross-platform hash is computed by hashing the name string, which must be the same on all platforms.

Note
The associated type will be referred as T in the documentation.
Warning
If you don't set an explicit name, it will fallback on the type name, which is not guaranteed to be cross-platform.
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-24)

Definition at line 46 of file AType.hpp.

Constructor & Destructor Documentation

◆ ~AType()

virtual ecstasy::rtti::AType::~AType ( )
virtualdefaultnoexcept

Destroy the AType 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 (2024-10-24)

Member Function Documentation

◆ getHash()

virtual size_t ecstasy::rtti::AType::getHash ( ) const
pure virtualnoexcept

Get the cross-platform hash of the type name.

Note
Expected to be the same on all platforms.
Returns
size_t Cross-platform hash of the type name.
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-24)

Implemented in ecstasy::rtti::Type< T >.

◆ getSerializer()

template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
ecstasy::serialization::IEntityComponentSerializer & ecstasy::rtti::AType::getSerializer ( ) const
inlinenoexcept

Get a reference to the entity component serializer for the given serializer type.

Template Parameters
SerializerType of the serializer to use.
Returns
ecstasy::serialization::IEntityComponentSerializer& Reference to the serializer.
Exceptions
std::out_of_rangeIf the serializer is not registered.
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-31)

Definition at line 175 of file AType.hpp.

176 {
177 return *_serializers.at(std::type_index(typeid(Serializer)));
178 }
T at(T... args)
std::unordered_map< std::type_index, std::unique_ptr< ecstasy::serialization::IEntityComponentSerializer > > _serializers
Hash of the type name.
Definition AType.hpp:204

◆ getStorageTypeInfo()

virtual const std::type_info & ecstasy::rtti::AType::getStorageTypeInfo ( ) const
pure virtualnoexcept

Get the type info of T storage type, as find by getStorageType<T>().

Returns
const std::type_info& Type info of T storage type.
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-24)

Implemented in ecstasy::rtti::Type< T >.

◆ getTypeInfo()

virtual const std::type_info & ecstasy::rtti::AType::getTypeInfo ( ) const
pure virtualnoexcept

Get the type info of T.

Returns
const std::type_info& Type info of T.
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-24)

Implemented in ecstasy::rtti::Type< T >.

◆ getTypeName()

virtual std::string_view ecstasy::rtti::AType::getTypeName ( ) const
pure virtualnoexcept

Get the name of T.

Note
Expected to be the same on all platforms.
Returns
std::string_view Name of T.
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-24)

Implemented in ecstasy::rtti::Type< T >.

◆ hasSerializer()

template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
bool ecstasy::rtti::AType::hasSerializer ( ) const
inlinenoexcept

Check if a serializer is registered for the component type.

Template Parameters
SerializerType of the serializer to check.
Returns
bool Whether the serializer is registered or not.
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-31)

Definition at line 157 of file AType.hpp.

158 {
159 return _serializers.contains(std::type_index(typeid(Serializer)));
160 }
T contains(T... args)

◆ operator<=>()

std::strong_ordering ecstasy::rtti::AType::operator<=> ( const AType rhs) const
noexcept

Compare two AType instances by their hash.

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-24)

Definition at line 16 of file AType.cpp.

17 {
18 return getHash() <=> rhs.getHash();
19 }
virtual size_t getHash() const noexcept=0
Get the cross-platform hash of the type name.

◆ operator==() [1/3]

bool ecstasy::rtti::AType::operator== ( const AType rhs) const
noexcept

Compare if two AType instances are equal by their hash.

Note
This is required because <=> is not enough for unordered containers 🤡.
Parameters
[in]rhsAType instance to compare with.
Returns
bool True if the AType instances are equal, false otherwise.
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-24)

Definition at line 21 of file AType.cpp.

22 {
23 return getHash() == rhs.getHash();
24 }

◆ operator==() [2/3]

bool ecstasy::rtti::AType::operator== ( const std::string_view rhs) const
noexcept

Compare if an AType instance is matching a type name.

Parameters
[in]rhsType name to compare with.
Returns
bool True if the AType instance is matching the type name, false otherwise.
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-24)

Definition at line 31 of file AType.cpp.

32 {
33 return getTypeName() == rhs;
34 }
virtual std::string_view getTypeName() const noexcept=0
Get the name of T.

◆ operator==() [3/3]

bool ecstasy::rtti::AType::operator== ( const std::type_info rhs) const
noexcept

Compare if an AType instance is matching a type info.

Parameters
[in]rhsType info to compare with.
Returns
bool True if the AType instance is matching the type info, false otherwise.
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-24)

Definition at line 26 of file AType.cpp.

27 {
28 return getTypeInfo() == rhs;
29 }
virtual const std::type_info & getTypeInfo() const noexcept=0
Get the type info of T.

◆ tryGetSerializer()

template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
std::optional< std::reference_wrapper< ecstasy::serialization::IEntityComponentSerializer > > ecstasy::rtti::AType::tryGetSerializer ( ) const
inlinenoexcept

Try to get a reference to the entity component serializer for the given serializer type.

Template Parameters
SerializerType of the serializer to use.
Returns
std::optional<std::reference_wrapper<ecstasy::serialization::IEntityComponentSerializer>> Reference to the serializer if found, std::nullopt otherwise.
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-31)

Definition at line 193 of file AType.hpp.

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 }
T end(T... args)
T find(T... args)
T ref(T... args)

Member Data Documentation

◆ _serializers

Hash of the type name.

Definition at line 204 of file AType.hpp.


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