EntropyEngine::Core::TypeSystem::TypeInfo
EntropyEngine::Core::TypeSystem::TypeInfo
Section titled “EntropyEngine::Core::TypeSystem::TypeInfo”Runtime type information container with field introspection. More…
#include <Reflection.h>
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| template <typename T > std::optional< T > | get_field_value(const void * obj, const FieldInfo & field) Safely retrieve a field value from an object instance. |
| std::string_view | getName() const Get the human-readable type name. |
| TypeID | getID() const Get the unique type identifier. |
| const std::vector< FieldInfo > & | getFields() const Get all reflected fields for this type. |
| template <typename T > const TypeInfo * | get() Get TypeInfo for a specific type T. |
Friends
Section titled “Friends”| Name | |
|---|---|
| struct | _EntropyTypeRegistrar |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Core::TypeSystem::TypeInfo;Runtime type information container with field introspection.
Primary interface for runtime reflection. Features static instance caching, type-safe field access, and automatic offset calculation.
Public Functions Documentation
Section titled “Public Functions Documentation”function get_field_value
Section titled “function get_field_value”template <typename T >static inline std::optional< T > get_field_value( const void * obj, const FieldInfo & field)Safely retrieve a field value from an object instance.
Parameters:
- obj Pointer to the object instance (must not be null)
- field FieldInfo describing the field to access
Template Parameters:
- T The expected type of the field value
Return: Optional containing the field value, or nullopt if type mismatch
Warning: The object pointer must be valid and point to an instance of the type that owns the field. No bounds checking is performed.
This function provides type-safe access to field values using the field offset information. Type safety is enforced by comparing the requested type T with the field’s registered type.
Safety Features:
- Type validation prevents incorrect casts
- Uses std::optional to handle type mismatches gracefully
- Direct memory access
MyClass instance;const auto* typeInfo = TypeInfo::get<MyClass>();
for (const auto& field : typeInfo->getFields()) { if (field.name == "myIntField") { auto value = TypeInfo::get_field_value<int>(&instance, field); if (value) { std::cout << "Field value: " << *value << std::endl; } else { std::cout << "Type mismatch!" << std::endl; } }}function getName
Section titled “function getName”inline std::string_view getName() constGet the human-readable type name.
Return: Type name as string_view (zero allocation)
function getID
Section titled “function getID”inline TypeID getID() constGet the unique type identifier.
Return: TypeID for this type
function getFields
Section titled “function getFields”inline const std::vector< FieldInfo > & getFields() constGet all reflected fields for this type.
Return: Const reference to vector of FieldInfo objects
Fields are returned in declaration order. The vector is constructed once per type and cached for efficiency.
function get
Section titled “function get”template <typename T >static inline const TypeInfo * get()Get TypeInfo for a specific type T.
Template Parameters:
- T The type to get reflection information for
Return: Pointer to TypeInfo instance, or nullptr if not registered
This is the primary entry point for accessing type reflection information. For types registered with ENTROPY_REGISTER_TYPE, this function uses a compile-time path with static instance caching. Legacy types fall back to the runtime registration system.
// Get reflection info for a registered typeconst auto* info = TypeInfo::get<MyClass>();if (info) { std::cout << "Type: " << info->getName() << std::endl; std::cout << "Fields: " << info->getFields().size() << std::endl;}Friends
Section titled “Friends”friend _EntropyTypeRegistrar
Section titled “friend _EntropyTypeRegistrar”friend struct _EntropyTypeRegistrar( _EntropyTypeRegistrar);Updated on 2026-01-26 at 17:14:35 -0500