Skip to content

EntropyCanvas::Schema::TypeInfo

Runtime type information container with field introspection. More…

#include <Reflection.h>

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_viewgetName() const
Get the human-readable type name.
TypeIDgetID() 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.
Name
struct_EntropyTypeRegistrar
class EntropyCanvas::Schema::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.

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;
}
}
}
inline std::string_view getName() const

Get the human-readable type name.

Return: Type name as string_view (zero allocation)

inline TypeID getID() const

Get the unique type identifier.

Return: TypeID for this type

inline const std::vector< FieldInfo > & getFields() const

Get 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.

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 type
const auto* info = TypeInfo::get<MyClass>();
if (info) {
std::cout << "Type: " << info->getName() << std::endl;
std::cout << "Fields: " << info->getFields().size() << std::endl;
}
friend struct _EntropyTypeRegistrar(
_EntropyTypeRegistrar
);

Updated on 2026-01-26 at 17:14:35 -0500