Utility class providing static methods for runtime type identification and safe casting.
More...
#include <TypeId.h>
|
| 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.
|
| |
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.
◆ 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
-
| T | The type to get an identifier for. |
- Return values
-
| type_id | The 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
-
| T | The target type to cast to. |
- Parameters
-
| obj | Pointer to an object implementing IWithType. |
- Return values
-
| T* | Pointer to the object as type T. |
| nullptr | The cast failed (the object is not of type T). |
The documentation for this class was generated from the following file: