You.i Engine
CYIRuntimeTypeInfo Class Referenceabstract

Detailed Description

The abstract runtime representation of a C++ type.

Instances of this class are used to represent a C++ type and manipulate that type at runtime. On types marked as RTTI types, the GetClassTypeInfo() and GetRuntimeTypeInfo() functions can be used to access an object's static or runtime type information.

Note
Instances CYIRuntimeTypeInfo should only be created through the use of the YI_TYPE_BASES(...) macro.
RTTI'ed C++ types have a unique CYIRuntimeTypeInfo instance. For this reason, taking the address of a CYIRuntimeTypeInfo reference (or of a CYIRuntimeTypeInfoTyped reference) is safe, and CYIRuntimeTypeInfo objects can be compared using CYIRuntimeTypeInfo::operator==() and CYIRuntimeTypeInfo::operator!=() .
See also
CYIRuntimeTypeInfoTyped
RTTISampleClass::GetClassTypeInfo()
RTTISampleClass::GetRuntimeTypeInfo()
YI_TYPE_BASES(...)
CYIRTTIRegistry::GetTypeForName
YiGetTypeInfo(CYIStringView)

#include <utility/YiRtti.h>

Inheritance diagram for CYIRuntimeTypeInfo:

Public Member Functions

virtual ~CYIRuntimeTypeInfo ()
 
template<typename T >
std::unique_ptr< T > CreateInstance () const
 
virtual bool CanCastTo (const CYIRuntimeTypeInfo &baseType) const =0
 
template<typename T >
bool CanCastTo () const
 
CYIString GetName () const
 
CYIStringView GetNameAsView () const
 
virtual const std::vector< const CYIRuntimeTypeInfo * > & GetBasesTypeInfos () const =0
 
virtual bool IsInstantiable () const =0
 
void RegisterWithLinker () const
 
template<typename T >
const T * CastVoidPointer (const void *pObject) const
 
bool operator== (const CYIRuntimeTypeInfo &other) const
 
bool operator!= (const CYIRuntimeTypeInfo &other) const
 
bool operator< (const CYIRuntimeTypeInfo &other) const
 

Protected Member Functions

 CYIRuntimeTypeInfo (CYIStringView name)
 

Constructor & Destructor Documentation

◆ ~CYIRuntimeTypeInfo()

virtual CYIRuntimeTypeInfo::~CYIRuntimeTypeInfo ( )
virtual

◆ CYIRuntimeTypeInfo()

CYIRuntimeTypeInfo::CYIRuntimeTypeInfo ( CYIStringView  name)
explicitprotected

Member Function Documentation

◆ CanCastTo() [1/2]

virtual bool CYIRuntimeTypeInfo::CanCastTo ( const CYIRuntimeTypeInfo baseType) const
pure virtual

Checks if the type represented by this object can be cast to the type represented by baseType. In other words, this function checks if baseType represents a base of this object's type.

Implemented in CYIRuntimeTypeInfoTyped< CLASS, BASES >.

◆ CanCastTo() [2/2]

template<typename T >
bool CYIRuntimeTypeInfo::CanCastTo ( ) const
inline

Checks if the type represented by this object can be cast to type T. In other words, this function checks if type T is a base of this object's type.

Note
CV qualifiers of type T are ignored.
Template Parameters
TThe type to check against.

◆ CastVoidPointer()

template<typename T >
const T* CYIRuntimeTypeInfo::CastVoidPointer ( const void *  pObject) const
inline

Casts the pointer pObject to the type T. If pObject cannot be cast to the type T, nullptr is returned.

Warning
This function is an implementation artifact and is not meant to be called by users. Use YiDynamicCast<T>(P*) instead.
The pointer pObject must be a pointer to an object of the type represented by this object. If the pointer points to an object of a different type, a runtime crash may occur.
pObject may not be null.
Template Parameters
TThe type to cast to.
See also
YiDynamicCast

◆ CreateInstance()

template<typename T >
std::unique_ptr<T> CYIRuntimeTypeInfo::CreateInstance ( ) const
inline

Creates and returns a new instance of the type represented by this object using the type's default constructor.

Note
If the type represented by this object cannot be cast to type T, a warning is logged and nullptr is returned without having created a new instance.
If the type represented by this object is not instantiable, a warning is logged and nullptr is returned.
Template Parameters
TThe type to cast the created object to.

◆ GetBasesTypeInfos()

virtual const std::vector<const CYIRuntimeTypeInfo *>& CYIRuntimeTypeInfo::GetBasesTypeInfos ( ) const
pure virtual

Returns a vector containing pointers to the CYIRuntimeTypeInfo objects representing the bases of the type reprensented by this object. If the type represented by this object has no RTTI bases, an empty vector is returned.

Implemented in CYIRuntimeTypeInfoTyped< CLASS, BASES >.

◆ GetName()

CYIString CYIRuntimeTypeInfo::GetName ( ) const

Returns the name of the type represented by this object. This is the name specified in the RTTI macro (either implicitely or explicitly). For namespaced types or inner types, the name is typically the full identifer of the type (e.g. "MyNamespace::MyType").

◆ GetNameAsView()

CYIStringView CYIRuntimeTypeInfo::GetNameAsView ( ) const

Returns the name of the type represented by this object as a CYIStringView. This is the name specified in the RTTI macro (either implicitely or explicitly). For namespaced types or inner types, the name is typically the full identifer of the type (e.g. "MyNamespace::MyType"). Unlike GetName(), this function does not make memory allocations.

◆ IsInstantiable()

virtual bool CYIRuntimeTypeInfo::IsInstantiable ( ) const
pure virtual

Returns true if the type represented by this object can be instantiated using CreateInstance().

Implemented in CYIRuntimeTypeInfoTyped< CLASS, BASES >.

◆ operator!=()

bool CYIRuntimeTypeInfo::operator!= ( const CYIRuntimeTypeInfo other) const
inline

◆ operator<()

bool CYIRuntimeTypeInfo::operator< ( const CYIRuntimeTypeInfo other) const
inline

◆ operator==()

bool CYIRuntimeTypeInfo::operator== ( const CYIRuntimeTypeInfo other) const
inline

◆ RegisterWithLinker()

void CYIRuntimeTypeInfo::RegisterWithLinker ( ) const

Registers the type represented by this object with the linker. When a type is only 'used' through the YiRTTINew<T>() function (such as when a type is referenced only through an external tool such as After Effects), it is necessary to manually call RegisterWithLinker to prevent the linker from removing the type from the executable.


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