Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::Type Class Reference

Utility class providing static methods for runtime type identification and safe casting. More...

#include <TypeId.h>

Static Public Member Functions

template<class T>
static type_id getTypeId ()
 Get the unique type identifier for a given type T.
 
template<typename T>
static T * safeStaticCast (IWithType *obj)
 Safely cast a pointer to type T if the runtime type matches.
 

Detailed Description

Utility class providing static methods for runtime type identification and safe casting.

This class leverages the address of static variables to generate unique type identifiers without requiring RTTI or additional memory overhead per instance.

Member Function Documentation

◆ getTypeId()

template<class T>
static type_id uniot::Type::getTypeId ( )
inlinestatic

Get the unique type identifier for a given type T.

This method creates a static variable whose address serves as a unique identifier for the template parameter type T.

Template Parameters
TThe type to get an identifier for.
Return values
type_idThe unique identifier for the type.

◆ safeStaticCast()

template<typename T>
static T * uniot::Type::safeStaticCast ( IWithType * obj)
inlinestatic

Safely cast a pointer to type T if the runtime type matches.

This method performs a runtime type check before casting, providing type-safe downcasting without using dynamic_cast.

Template Parameters
TThe target type to cast to.
Parameters
objPointer to an object implementing IWithType.
Return values
T*Pointer to the object as type T.
nullptrThe cast failed (the object is not of type T).

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