ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::rtti::Type< T > Class Template Reference

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

#include <Type.hpp>

Inheritance diagram for ecstasy::rtti::Type< T >:
Collaboration diagram for ecstasy::rtti::Type< T >:

Public Types

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

Public Member Functions

 Type () noexcept
 Construct a new Type instance.
 
 Type (std::string_view name) noexcept
 Construct a new Type instance with a custom name.
 
 ~Type () noexcept override final=default
 Destroy the AType instance.
 
const std::type_infogetStorageTypeInfo () const noexcept override final
 Get the type info of T storage type, as find by getStorageType<T>().
 
const std::type_infogetTypeInfo () const noexcept override final
 Get the type info of T.
 
size_t getHash () const noexcept override final
 Get the cross-platform hash of the type name.
 
std::string_view getTypeName () const noexcept override final
 Get the name of T.
 
template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
serialization::IEntityComponentSerializerregisterSerializer () noexcept
 Register a new serializer for the component type.
 
- Public Member Functions inherited from ecstasy::rtti::AType
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.
 

Private Member Functions

void setTypeName (std::string_view name) noexcept
 Set the Type name.
 

Private Attributes

std::string_view _name
 Name of the component type.
 
std::size_t _hash
 Hash of the component type name. Should be cross-platform.
 

Additional Inherited Members

- Protected Attributes inherited from ecstasy::rtti::AType
std::unordered_map< std::type_index, std::unique_ptr< ecstasy::serialization::IEntityComponentSerializer > > _serializers
 Hash of the type name.
 

Detailed Description

template<typename T>
class ecstasy::rtti::Type< T >

Type erased interface for cross-platform type information.

Template Parameters
TType to get the type information from.
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 35 of file Type.hpp.

Member Typedef Documentation

◆ StorageType

template<typename T >
using ecstasy::rtti::Type< T >::StorageType = getStorageType<T>

Type of the storage used to store the component.

Definition at line 38 of file Type.hpp.

Constructor & Destructor Documentation

◆ Type() [1/2]

template<typename T >
ecstasy::rtti::Type< T >::Type ( )
inlinenoexcept

Construct a new Type instance.

Warning
The name 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 48 of file Type.hpp.

48 : AType()
49 {
50 setTypeName(typeid(T).name());
51 }
void setTypeName(std::string_view name) noexcept
Set the Type name.
Definition Type.hpp:132

◆ Type() [2/2]

template<typename T >
ecstasy::rtti::Type< T >::Type ( std::string_view  name)
inlinenoexcept

Construct a new Type instance with a custom name.

Warning
The name life time must be greater than the Type instance life time, as it is stored as a reference.
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 62 of file Type.hpp.

62 : AType()
63 {
64 setTypeName(name);
65 }

◆ ~Type()

template<typename T >
ecstasy::rtti::Type< T >::~Type ( )
finaloverridedefaultnoexcept

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

template<typename T >
size_t ecstasy::rtti::Type< T >::getHash ( ) const
inlinefinaloverridevirtualnoexcept

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)

Implements ecstasy::rtti::AType.

Definition at line 83 of file Type.hpp.

84 {
85 return _hash;
86 }
std::size_t _hash
Hash of the component type name. Should be cross-platform.
Definition Type.hpp:122

◆ getStorageTypeInfo()

template<typename T >
const std::type_info & ecstasy::rtti::Type< T >::getStorageTypeInfo ( ) const
inlinefinaloverridevirtualnoexcept

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)

Implements ecstasy::rtti::AType.

Definition at line 71 of file Type.hpp.

72 {
73 return typeid(StorageType);
74 }
getStorageType< T > StorageType
Type of the storage used to store the component.
Definition Type.hpp:38

◆ getTypeInfo()

template<typename T >
const std::type_info & ecstasy::rtti::Type< T >::getTypeInfo ( ) const
inlinefinaloverridevirtualnoexcept

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)

Implements ecstasy::rtti::AType.

Definition at line 77 of file Type.hpp.

78 {
79 return typeid(T);
80 }

◆ getTypeName()

template<typename T >
std::string_view ecstasy::rtti::Type< T >::getTypeName ( ) const
inlinefinaloverridevirtualnoexcept

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)

Implements ecstasy::rtti::AType.

Definition at line 89 of file Type.hpp.

90 {
91 return _name;
92 }
std::string_view _name
Name of the component type.
Definition Type.hpp:120

◆ registerSerializer()

template<typename T >
template<std::derived_from< ecstasy::serialization::ISerializer > Serializer>
serialization::IEntityComponentSerializer & ecstasy::rtti::Type< T >::registerSerializer ( )
inlinenoexcept

Register a new serializer for the component type.

Template Parameters
SerializerType of the serializer to register.
Returns
serialization::IEntityComponentSerializer& Reference to the registered serializer.
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)

Definition at line 105 of file Type.hpp.

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
114 .emplace(index, std::make_unique<serialization::EntityComponentSerializer<T, Serializer>>())
115 .first->second;
116 }
std::unordered_map< std::type_index, std::unique_ptr< ecstasy::serialization::IEntityComponentSerializer > > _serializers
Hash of the type name.
Definition AType.hpp:204
T emplace(T... args)
T end(T... args)
T find(T... args)
T make_unique(T... args)

◆ setTypeName()

template<typename T >
void ecstasy::rtti::Type< T >::setTypeName ( std::string_view  name)
inlineprivatenoexcept

Set the Type name.

This will also update the hash.

Parameters
[in]nameNew name of the 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)

Definition at line 132 of file Type.hpp.

133 {
134 _name = name;
136 }

Member Data Documentation

◆ _hash

template<typename T >
std::size_t ecstasy::rtti::Type< T >::_hash
private

Hash of the component type name. Should be cross-platform.

Definition at line 122 of file Type.hpp.

◆ _name

template<typename T >
std::string_view ecstasy::rtti::Type< T >::_name
private

Name of the component type.

Definition at line 120 of file Type.hpp.


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