CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Type Class Referencefinal

Represents a reflected C++ type. Can be used to get metadata from a C++ type. More...

#include <CeresEngine/Reflection/Type.hpp>

Public Member Functions

 Type () noexcept=default
 
 Type (const TypeInfo &typeInfo)
 
 Type (StringView name) noexcept
 Finds a type by it's name.
 
 Type (TypeID typeID) noexcept
 Finds a type by it's id.
 
TypeID getTypeID () const noexcept
 Gets the type ID.
 
StringView getTypeName () const noexcept
 
StringView getName () const noexcept
 
std::size_t getTypeSize () const noexcept
 
std::align_val_t getTypeAlignment () const noexcept
 
TypeIdentityHash getIdentityHash () const noexcept
 Gets the type identity hash.
 
bool isDecayed () const noexcept
 Determines if the type is decayed, that is, this->getDecayedType() == this.
 
Type getDecayType () const noexcept
 Gets the decayed type.
 
TypeID getDecayTypeID () const noexcept
 Gets the decayed type.
 
Type getUnderlyingType () const noexcept
 If an enum, gets the underlying type of the enum.
 
TypeID getUnderlyingTypeID () const noexcept
 If an enum, gets the underlying type of the enum.
 
bool isConst () const noexcept
 Returns true if the type is const, false otherwise.
 
bool isLvalueReference () const noexcept
 Returns true if the type is an lvalue reference, false otherwise.
 
bool isRvalueReference () const noexcept
 Returns true if the type is an rvalue reference, false otherwise.
 
bool isReference () const noexcept
 Returns true if the type is a reference (lvalue or rvalue), false otherwise.
 
bool isClass () const noexcept
 Returns true if the type is a class, false otherwise.
 
bool isPointer () const noexcept
 Returns true if the type is a pointer, false otherwise.
 
bool isVoidPtr () const noexcept
 Returns true if the type is a void pointer, false otherwise.
 
bool isClassPtr () const noexcept
 Returns true if the type is a class pointer, false otherwise.
 
bool isFunctionPtr () const noexcept
 Returns true if the type is a function pointer, false otherwise.
 
bool isArray () const noexcept
 Returns true if the type is an array, false otherwise.
 
uint16_t getPointerArity () const noexcept
 Returns the pointer arity of the type. Returns 0 if the type is not a pointer.
 
template<typename T >
bool is () const
 
template<typename T >
const Tas () const
 
const ClassgetClass () const noexcept
 Gets the Class instance associated with the type.
 
const EnumgetMetaEnum () const noexcept
 Gets the MetaEnum instance associated with the type.
 
bool compatible (const Type &other) const noexcept
 Determines if the fromType is compatible with the toType.
 
template<typename T >
bool compatible () const noexcept
 Determines if the fromType is compatible with the toType.
 
Box construct () const
 Constructs a new value from the type, if default constructible.
 
void destruct (void *instance) const
 Destroys an instance of the type. Calls the C++ destructor.
 
bool isValid () const noexcept
 Determines if the Type object points to a valid type or not.
 
 operator bool () const noexcept
 Determines if the Type object points to a valid type or not.
 

Static Public Member Functions

static Type fromName (StringView name) noexcept
 Finds a type by it's name.
 
static Type fromID (TypeID id) noexcept
 Finds a type by it's id.
 
static bool compatible (Type fromType, Type toType) noexcept
 Determines if the fromType is compatible with the toType.
 
static bool hasConverter (Type fromType, Type toType) noexcept
 Determines if there is a converter available to convert a value from fromType to toType.
 
static bool hasConverter (TypeID fromTypeID, TypeID toTypeID) noexcept
 Determines if there is a converter available to convert a value from fromType to toType.
 
template<typename From , typename To >
static bool hasConverter () noexcept
 Determines if there is a converter available to convert a value from From to To.
 
template<typename From , typename To , typename Func >
static bool registerConverter (Func &&func)
 
template<typename From , typename To >
static bool registerConverter (To(*func)(From))
 
template<typename From , typename To >
static bool registerConverter ()
 
template<typename From , typename To >
static bool registerConverter (To(From::*func)() const)
 
template<typename From , typename To >
static bool registerConverter (To(From::*func)(bool &) const)
 
static void unregisterConverter (TypeID fromTypeID, TypeID toTypeID)
 
template<typename From , typename To >
static void unregisterConverter ()
 

Private Member Functions

voidallocate () const
 
void deallocate (void *ptr) const
 
void defaultConstruct (void *where) const
 
void copyConstruct (const void *source, void *where) const
 
void moveConstruct (void *source, void *where) const
 
void moveOrCopy (void *source, void *where) const
 
void destroy (void *ptr) const noexcept
 
bool compareEquality (const void *lhs, const void *rhs) const
 

Static Private Member Functions

template<typename From , typename To , typename Func >
static bool registerConverterInternal (Func &&func)
 
template<typename From , typename To >
static bool registerConverterInternal (To(From::*func)() const)
 
template<typename From , typename To >
static bool registerConverterInternal (To(From::*func)(bool &) const)
 
static bool registerConverter (TypeID fromTypeID, TypeID toTypeID, const internal::ConvertFunctionBase &converter)
 
template<typename From , typename To >
static bool registerConverterInternalNonChecked ()
 
static bool registerConverterInternalNonChecked (TypeID fromTypeID, TypeID toTypeID, const internal::ConvertFunctionBase &converter)
 
static bool convert (const void *from, Type fromType, void *to, Type toType)
 
static bool convert (const void *from, TypeID fromTypeID, void *to, TypeID toTypeID)
 

Private Attributes

const TypeInfomTypeInfo = nullptr
 The TypeInfo structure that describes the reflected type.
 

Friends

class Class
 
class Enum
 
class Box
 
bool operator== (const Type &type, std::nullptr_t) noexcept
 Determines if the Type object points to a valid type or not.
 
bool operator!= (const Type &type, std::nullptr_t) noexcept
 Determines if the Type object points to a valid type or not.
 
bool operator== (std::nullptr_t, const Type &type) noexcept
 Determines if the Type object points to a valid type or not.
 
bool operator!= (std::nullptr_t, const Type &type) noexcept
 Determines if the Type object points to a valid type or not.
 
bool operator== (const Type &lhs, const Type &rhs) noexcept
 
bool operator!= (const Type &lhs, const Type &rhs) noexcept
 
bool operator< (const Type &lhs, const Type &rhs) noexcept
 
bool operator<= (const Type &lhs, const Type &rhs) noexcept
 
bool operator> (const Type &lhs, const Type &rhs) noexcept
 
bool operator>= (const Type &lhs, const Type &rhs) noexcept
 

Detailed Description

Represents a reflected C++ type. Can be used to get metadata from a C++ type.

Constructor & Destructor Documentation

◆ Type() [1/4]

CeresEngine::Type::Type ( )
defaultnoexcept

◆ Type() [2/4]

CeresEngine::Type::Type ( const TypeInfo typeInfo)
inlineexplicit

◆ Type() [3/4]

CeresEngine::Type::Type ( StringView  name)
explicitnoexcept

Finds a type by it's name.

If the type is not found, the returned Type::isValid method retuns false.

◆ Type() [4/4]

CeresEngine::Type::Type ( TypeID  typeID)
explicitnoexcept

Finds a type by it's id.

If the type is not found, the returned Type::isValid method retuns false.

Member Function Documentation

◆ allocate()

void * CeresEngine::Type::allocate ( ) const
private

◆ as()

template<typename T >
const T * CeresEngine::Type::as ( ) const

◆ compareEquality()

bool CeresEngine::Type::compareEquality ( const void lhs,
const void rhs 
) const
private

◆ compatible() [1/3]

template<typename T >
bool CeresEngine::Type::compatible ( ) const
noexcept

Determines if the fromType is compatible with the toType.

Compatibility is defined as the types are either the same, toType is a base class of fromType or there is a converter from fromType to toType available.

◆ compatible() [2/3]

bool CeresEngine::Type::compatible ( const Type other) const
inlinenoexcept

Determines if the fromType is compatible with the toType.

Compatibility is defined as the types are either the same, toType is a base class of fromType or there is a converter from fromType to toType available.

◆ compatible() [3/3]

static bool CeresEngine::Type::compatible ( Type  fromType,
Type  toType 
)
staticnoexcept

Determines if the fromType is compatible with the toType.

Compatibility is defined as the types are either the same, toType is a base class of fromType or there is a converter from fromType to toType available.

◆ construct()

Box CeresEngine::Type::construct ( ) const

Constructs a new value from the type, if default constructible.

Returns
A new MetaValue that contains the newly constructed type.

◆ convert() [1/2]

static bool CeresEngine::Type::convert ( const void from,
Type  fromType,
void to,
Type  toType 
)
staticprivate

◆ convert() [2/2]

static bool CeresEngine::Type::convert ( const void from,
TypeID  fromTypeID,
void to,
TypeID  toTypeID 
)
staticprivate

◆ copyConstruct()

void CeresEngine::Type::copyConstruct ( const void source,
void where 
) const
private

◆ deallocate()

void CeresEngine::Type::deallocate ( void ptr) const
private

◆ defaultConstruct()

void CeresEngine::Type::defaultConstruct ( void where) const
private

◆ destroy()

void CeresEngine::Type::destroy ( void ptr) const
privatenoexcept

◆ destruct()

void CeresEngine::Type::destruct ( void instance) const

Destroys an instance of the type. Calls the C++ destructor.

◆ fromID()

static Type CeresEngine::Type::fromID ( TypeID  id)
staticnoexcept

Finds a type by it's id.

If the type is not found, the returned Type::isValid method retuns false.

◆ fromName()

static Type CeresEngine::Type::fromName ( StringView  name)
staticnoexcept

Finds a type by it's name.

If the type is not found, the returned Type::isValid method retuns false.

◆ getClass()

const Class * CeresEngine::Type::getClass ( ) const
noexcept

Gets the Class instance associated with the type.

Can be nullptr if there is not class definition associated to the type.

◆ getDecayType()

Type CeresEngine::Type::getDecayType ( ) const
noexcept

Gets the decayed type.

Decayed is defined as std::decay, being: "Applies lvalue-to-rvalue, array-to-pointer, and function-to-pointer implicit conversions to the type T, removes cv-qualifiers."

◆ getDecayTypeID()

TypeID CeresEngine::Type::getDecayTypeID ( ) const
noexcept

Gets the decayed type.

Decayed is defined as std::decay, being: "Applies lvalue-to-rvalue, array-to-pointer, and function-to-pointer implicit conversions to the type T, removes cv-qualifiers."

◆ getIdentityHash()

TypeIdentityHash CeresEngine::Type::getIdentityHash ( ) const
noexcept

Gets the type identity hash.

Can be used to implement a switch-case statement by using the values returned by Type::getIdentityHash<T>().

◆ getMetaEnum()

const Enum * CeresEngine::Type::getMetaEnum ( ) const
noexcept

Gets the MetaEnum instance associated with the type.

Can be nullptr if there is not enum definition associated to the type.

◆ getName()

StringView CeresEngine::Type::getName ( ) const
inlinenoexcept

Returns
The fully qualified name of the name. Usually extracted from compiler data and uniform across multiple compilers.

◆ getPointerArity()

uint16_t CeresEngine::Type::getPointerArity ( ) const
noexcept

Returns the pointer arity of the type. Returns 0 if the type is not a pointer.

◆ getTypeAlignment()

std::align_val_t CeresEngine::Type::getTypeAlignment ( ) const
noexcept
Returns
The alignment of the type, in bytes. Useful when allocating memory to construct an instance.

◆ getTypeID()

TypeID CeresEngine::Type::getTypeID ( ) const
noexcept

Gets the type ID.

The type ID is a small integer value that can be used to quickly check a type for equality. This value is not a constant though and may vary betwee runs or instances of an app, but is guaranteed to be constant for a single run of the app.

◆ getTypeName()

StringView CeresEngine::Type::getTypeName ( ) const
noexcept
Returns
The fully qualified name of the name. Usually extracted from compiler data and uniform across multiple compilers.

◆ getTypeSize()

std::size_t CeresEngine::Type::getTypeSize ( ) const
noexcept
Returns
The size of the type, in bytes. Useful when allocating memory to construct an instance.

◆ getUnderlyingType()

Type CeresEngine::Type::getUnderlyingType ( ) const
noexcept

If an enum, gets the underlying type of the enum.

◆ getUnderlyingTypeID()

TypeID CeresEngine::Type::getUnderlyingTypeID ( ) const
noexcept

If an enum, gets the underlying type of the enum.

◆ hasConverter() [1/3]

template<typename From , typename To >
bool CeresEngine::Type::hasConverter ( )
inlinestaticnoexcept

Determines if there is a converter available to convert a value from From to To.

◆ hasConverter() [2/3]

static bool CeresEngine::Type::hasConverter ( Type  fromType,
Type  toType 
)
staticnoexcept

Determines if there is a converter available to convert a value from fromType to toType.

◆ hasConverter() [3/3]

static bool CeresEngine::Type::hasConverter ( TypeID  fromTypeID,
TypeID  toTypeID 
)
staticnoexcept

Determines if there is a converter available to convert a value from fromType to toType.

◆ is()

template<typename T >
bool CeresEngine::Type::is ( ) const

◆ isArray()

bool CeresEngine::Type::isArray ( ) const
noexcept

Returns true if the type is an array, false otherwise.

◆ isClass()

bool CeresEngine::Type::isClass ( ) const
noexcept

Returns true if the type is a class, false otherwise.

◆ isClassPtr()

bool CeresEngine::Type::isClassPtr ( ) const
noexcept

Returns true if the type is a class pointer, false otherwise.

◆ isConst()

bool CeresEngine::Type::isConst ( ) const
noexcept

Returns true if the type is const, false otherwise.

◆ isDecayed()

bool CeresEngine::Type::isDecayed ( ) const
inlinenoexcept

Determines if the type is decayed, that is, this->getDecayedType() == this.

◆ isFunctionPtr()

bool CeresEngine::Type::isFunctionPtr ( ) const
noexcept

Returns true if the type is a function pointer, false otherwise.

◆ isLvalueReference()

bool CeresEngine::Type::isLvalueReference ( ) const
noexcept

Returns true if the type is an lvalue reference, false otherwise.

◆ isPointer()

bool CeresEngine::Type::isPointer ( ) const
noexcept

Returns true if the type is a pointer, false otherwise.

◆ isReference()

bool CeresEngine::Type::isReference ( ) const
noexcept

Returns true if the type is a reference (lvalue or rvalue), false otherwise.

◆ isRvalueReference()

bool CeresEngine::Type::isRvalueReference ( ) const
noexcept

Returns true if the type is an rvalue reference, false otherwise.

◆ isValid()

bool CeresEngine::Type::isValid ( ) const
inlinenoexcept

Determines if the Type object points to a valid type or not.

◆ isVoidPtr()

bool CeresEngine::Type::isVoidPtr ( ) const
noexcept

Returns true if the type is a void pointer, false otherwise.

◆ moveConstruct()

void CeresEngine::Type::moveConstruct ( void source,
void where 
) const
private

◆ moveOrCopy()

void CeresEngine::Type::moveOrCopy ( void source,
void where 
) const
private

◆ operator bool()

CeresEngine::Type::operator bool ( ) const
inlineexplicitnoexcept

Determines if the Type object points to a valid type or not.

◆ registerConverter() [1/6]

template<typename From , typename To >
bool CeresEngine::Type::registerConverter ( )
inlinestatic

◆ registerConverter() [2/6]

bool CeresEngine::Type::registerConverter ( Func &&  func)
inlinestatic

◆ registerConverter() [3/6]

template<typename From , typename To >
bool CeresEngine::Type::registerConverter ( To(*)(From func)
inlinestatic

◆ registerConverter() [4/6]

template<typename From , typename To >
bool CeresEngine::Type::registerConverter ( To(From::*)() const  func)
inlinestatic

◆ registerConverter() [5/6]

template<typename From , typename To >
bool CeresEngine::Type::registerConverter ( To(From::*)(bool &) const  func)
inlinestatic

◆ registerConverter() [6/6]

static bool CeresEngine::Type::registerConverter ( TypeID  fromTypeID,
TypeID  toTypeID,
const internal::ConvertFunctionBase converter 
)
staticprivate

◆ registerConverterInternal() [1/3]

bool CeresEngine::Type::registerConverterInternal ( Func &&  func)
inlinestaticprivate

◆ registerConverterInternal() [2/3]

template<typename From , typename To >
bool CeresEngine::Type::registerConverterInternal ( To(From::*)() const  func)
inlinestaticprivate

◆ registerConverterInternal() [3/3]

template<typename From , typename To >
bool CeresEngine::Type::registerConverterInternal ( To(From::*)(bool &) const  func)
inlinestaticprivate

◆ registerConverterInternalNonChecked() [1/2]

template<typename From , typename To >
bool CeresEngine::Type::registerConverterInternalNonChecked ( )
inlinestaticprivate

◆ registerConverterInternalNonChecked() [2/2]

static bool CeresEngine::Type::registerConverterInternalNonChecked ( TypeID  fromTypeID,
TypeID  toTypeID,
const internal::ConvertFunctionBase converter 
)
staticprivate

◆ unregisterConverter() [1/2]

template<typename From , typename To >
void CeresEngine::Type::unregisterConverter ( )
inlinestatic

◆ unregisterConverter() [2/2]

static void CeresEngine::Type::unregisterConverter ( TypeID  fromTypeID,
TypeID  toTypeID 
)
static

Friends And Related Symbol Documentation

◆ Box

friend class Box
friend

◆ Class

friend class Class
friend

◆ Enum

friend class Enum
friend

◆ operator!= [1/3]

bool operator!= ( const Type lhs,
const Type rhs 
)
friend

◆ operator!= [2/3]

bool operator!= ( const Type type,
std::nullptr_t   
)
friend

Determines if the Type object points to a valid type or not.

◆ operator!= [3/3]

bool operator!= ( std::nullptr_t  ,
const Type type 
)
friend

Determines if the Type object points to a valid type or not.

◆ operator<

bool operator< ( const Type lhs,
const Type rhs 
)
friend

◆ operator<=

bool operator<= ( const Type lhs,
const Type rhs 
)
friend

◆ operator== [1/3]

bool operator== ( const Type lhs,
const Type rhs 
)
friend

◆ operator== [2/3]

bool operator== ( const Type type,
std::nullptr_t   
)
friend

Determines if the Type object points to a valid type or not.

◆ operator== [3/3]

bool operator== ( std::nullptr_t  ,
const Type type 
)
friend

Determines if the Type object points to a valid type or not.

◆ operator>

bool operator> ( const Type lhs,
const Type rhs 
)
friend

◆ operator>=

bool operator>= ( const Type lhs,
const Type rhs 
)
friend

Member Data Documentation

◆ mTypeInfo

const TypeInfo* CeresEngine::Type::mTypeInfo = nullptr
private

The TypeInfo structure that describes the reflected type.


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