You.i Engine
CYIRTTIRegistry Class Reference

Detailed Description

A registry of all known RTTI types.

This class acts as a central repository for all known RTTI types. Its main use is to allow for runtime instantiation of types by name. In addition to this, the registry provides reflection features to view the list of available types and their relationship to each other.

Only a single instance of this object can exist. That instance is accessed through the GetInstance() function.

#include <utility/YiRttiRegistry.h>

Public Member Functions

void RegisterType (const CYIRuntimeTypeInfo &typeInfo, CYIString name)
 
const CYIRuntimeTypeInfoRegisterTypeHelper (const CYIRuntimeTypeInfo &typeInfo)
 
void UnregisterType (CYIStringView name)
 
const CYIRuntimeTypeInfoGetTypeForName (CYIStringView typeName) const
 
std::map< CYIString, const CYIRuntimeTypeInfo * > GetRegisteredTypes () const
 
std::vector< const CYIRuntimeTypeInfo * > GetSuperclassesTypeInfos (const CYIRuntimeTypeInfo &type, bool directSuperclassesOnly=false) const
 
std::vector< const CYIRuntimeTypeInfo * > GetSubclassesTypeInfos (const CYIRuntimeTypeInfo &type, bool directSubclassesOnly=false) const
 
std::vector< const CYIRuntimeTypeInfo * > GetRootTypeInfos () const
 
CYIString GenerateInheritanceTreeString (const CYIRuntimeTypeInfo &type, bool useASCII=false, CYIStringView textColor="", CYIStringView graphColor="", CYIStringView noticeColor="") const
 

Static Public Member Functions

static CYIRTTIRegistryGetInstance ()
 

Member Function Documentation

◆ GenerateInheritanceTreeString()

CYIString CYIRTTIRegistry::GenerateInheritanceTreeString ( const CYIRuntimeTypeInfo type,
bool  useASCII = false,
CYIStringView  textColor = "",
CYIStringView  graphColor = "",
CYIStringView  noticeColor = "" 
) const

Generates and returns a graph representation of the subclasses of type. If useASCII is true, the returned graph is generated using ASCII characters instead of Unicode characters. Colorization strings can be provided in textColor, graphColor and noticeColor to colorize the output.

Sample generated graph:

├── CYISceneView
│ ├── CYIAbstractButtonView
│ │ ├── CYIPushButtonView
│ │ └── CYIToggleButtonView
│ ├── CYIImageView
│ └── CYIListView
│ └── CYIScrollingTextView
Note
This function is for debugging purposes, and as such is not optimized. This function runs in O(n²) time.
See also
CYIYouIMarkupParser

◆ GetInstance()

static CYIRTTIRegistry& CYIRTTIRegistry::GetInstance ( )
static

Returns the system's instance of this class. Only a single instance can exist on the system, and it is deleted automatically at exit.

◆ GetRegisteredTypes()

std::map<CYIString, const CYIRuntimeTypeInfo *> CYIRTTIRegistry::GetRegisteredTypes ( ) const

Returns a map of all registered RTTI types. The key of the map is the identification string, and the value is the assocaited CYIRuntimeTypeInfo object. Note that the same CYIRuntimeTypeInfo object may be present multiple times in the returned map.

Note
This function runs in O(n) time.

◆ GetRootTypeInfos()

std::vector<const CYIRuntimeTypeInfo *> CYIRTTIRegistry::GetRootTypeInfos ( ) const

Returns a vector containing CYIRuntimeTypeInfo objects for all root types. Root types are types which do not have any RTTI superclasses.

Note
This function runs in O(n) time.

◆ GetSubclassesTypeInfos()

std::vector<const CYIRuntimeTypeInfo *> CYIRTTIRegistry::GetSubclassesTypeInfos ( const CYIRuntimeTypeInfo type,
bool  directSubclassesOnly = false 
) const

Returns a vector containing CYIRuntimeTypeInfo objects for all subclasses of the type identified by type. If directSubclassesOnly is true, only direct subclasses of type are returned. By default, all subclasses of type are returned.

Note
This function runs in O(n) time.

◆ GetSuperclassesTypeInfos()

std::vector<const CYIRuntimeTypeInfo *> CYIRTTIRegistry::GetSuperclassesTypeInfos ( const CYIRuntimeTypeInfo type,
bool  directSuperclassesOnly = false 
) const

Returns a vector containing CYIRuntimeTypeInfo objects for all superclasses of the type identified by type. If directSuperclassesOnly is true, only direct superclasses of type are returned. By default, all superclasses of type are returned.

Note
This function runs in O(n) time.

◆ GetTypeForName()

const CYIRuntimeTypeInfo* CYIRTTIRegistry::GetTypeForName ( CYIStringView  typeName) const

Finds and returns the CYIRuntimeTypeInfo object identified by typeName. If no such type exists, nullptr is returned.

Note
This function runs in O(1) time.

◆ RegisterType()

void CYIRTTIRegistry::RegisterType ( const CYIRuntimeTypeInfo typeInfo,
CYIString  name 
)

Registers type typeInfo and associates it with the name name.

Note
RTTI types are automatically added to the registry. This function does not need to be called manually.
If name differs from the name of typeInfo, a warning is logged.
Warning
If a type is already identified by name, that existing type is unregistered, is replaced with typeInfo and a warning is logged.
Replacing system RTTI types can result in undefined behaviour.

◆ RegisterTypeHelper()

const CYIRuntimeTypeInfo& CYIRTTIRegistry::RegisterTypeHelper ( const CYIRuntimeTypeInfo typeInfo)

An utility function used by the RTTI implementation to automatically register RTTI types at application startup.

See also
RegisterType()

◆ UnregisterType()

void CYIRTTIRegistry::UnregisterType ( CYIStringView  name)

Removes the type identified by name from the registry. Whether the type exists in the registry or not, a warning is logged.

Note
This function is used mostly for debugging and testing purposes.
Warning
Removing system RTTI types can result in undefined behaviour.

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