ezEngine Release 26.3
Loading...
Searching...
No Matches
ezRTTI Class Reference

Core class of ezEngine's reflection system that holds complete runtime type information. More...

#include <RTTI.h>

Inheritance diagram for ezRTTI:

Classes

struct  ForEachOptions
 

Public Types

using PredicateFunc = ezDelegate< bool(const ezRTTI *), 48 >
 
using VisitorFunc = ezDelegate< void(const ezRTTI *), 48 >
 

Public Member Functions

 ezRTTI (ezStringView sName, const ezRTTI *pParentType, ezUInt32 uiTypeSize, ezUInt32 uiTypeVersion, ezUInt8 uiVariantType, ezBitflags< ezTypeFlags > flags, ezRTTIAllocator *pAllocator, ezArrayPtr< const ezAbstractProperty * > properties, ezArrayPtr< const ezAbstractFunctionProperty * > functions, ezArrayPtr< const ezPropertyAttribute * > attributes, ezArrayPtr< ezAbstractMessageHandler * > messageHandlers, ezArrayPtr< ezMessageSenderInfo > messageSenders, const ezRTTI *(*fnVerifyParent)())
 The constructor requires all the information about the type that this object represents.
 
void VerifyCorrectness () const
 Can be called in debug builds to check that all reflected objects are correctly set up.
 
EZ_ALWAYS_INLINE ezStringView GetTypeName () const
 Returns the name of this type.
 
EZ_ALWAYS_INLINE ezUInt64 GetTypeNameHash () const
 Returns the hash of the name of this type.
 
EZ_ALWAYS_INLINE const ezRTTIGetParentType () const
 Returns the type that is the base class of this type. May be nullptr if this type has no base class.
 
EZ_ALWAYS_INLINE ezVariantType::Enum GetVariantType () const
 Returns the corresponding variant type for this type or Invalid if there is none.
 
EZ_ALWAYS_INLINE bool IsDerivedFrom (const ezRTTI *pBaseType) const
 Fast O(1) check if this type is derived from the given type (or is the same type).
 
template<typename BASE >
EZ_ALWAYS_INLINE bool IsDerivedFrom () const
 Returns true if this type is derived from or identical to the given type.
 
EZ_ALWAYS_INLINE ezRTTIAllocatorGetAllocator () const
 Returns the object through which instances of this type can be allocated.
 
EZ_ALWAYS_INLINE ezArrayPtr< const ezAbstractProperty *const > GetProperties () const
 Returns the array of properties that this type has. Does NOT include properties from base classes.
 
EZ_ALWAYS_INLINE ezArrayPtr< const ezAbstractFunctionProperty *const > GetFunctions () const
 
EZ_ALWAYS_INLINE ezArrayPtr< const ezPropertyAttribute *const > GetAttributes () const
 
template<typename Type >
const Type * GetAttributeByType () const
 Returns the first attribute that derives from the given type, or nullptr if nothing is found.
 
void GetAllProperties (ezDynamicArray< const ezAbstractProperty * > &out_properties) const
 Returns the list of properties that this type has, including derived properties from all base classes.
 
EZ_ALWAYS_INLINE ezUInt32 GetTypeSize () const
 Returns the size (in bytes) of an instance of this type.
 
EZ_ALWAYS_INLINE ezUInt32 GetTypeVersion () const
 Returns the version number of this type.
 
EZ_ALWAYS_INLINE const ezBitflags< ezTypeFlags > & GetTypeFlags () const
 Returns the type flags.
 
const ezAbstractPropertyFindPropertyByName (ezStringView sName, bool bSearchBaseTypes=true) const
 Will iterate over all properties of this type and (optionally) the base types to search for a property with the given name.
 
EZ_ALWAYS_INLINE ezStringView GetPluginName () const
 Returns the name of the plugin which this type is declared in.
 
EZ_ALWAYS_INLINE const ezArrayPtr< ezAbstractMessageHandler * > & GetMessageHandlers () const
 Returns the array of message handlers that this type has.
 
bool DispatchMessage (void *pInstance, ezMessage &ref_msg) const
 Dispatches a message to the appropriate handler for this type.
 
bool DispatchMessage (const void *pInstance, ezMessage &ref_msg) const
 Dispatches a message to the appropriate handler (const version).
 
template<typename MessageType >
EZ_ALWAYS_INLINE bool CanHandleMessage () const
 Returns whether this type can handle the given message type.
 
bool CanHandleMessage (ezMessageId id) const
 Returns whether this type can handle the message type with the given id.
 
EZ_ALWAYS_INLINE const ezArrayPtr< ezMessageSenderInfo > & GetMessageSender () const
 

Static Public Member Functions

static void VerifyCorrectnessForAllTypes ()
 Calls VerifyCorrectness() on all ezRTTI objects.
 
static const ezRTTIFindTypeByName (ezStringView sName)
 Searches all ezRTTI instances for the one with the given name, or nullptr if no such type exists.
 
static const ezRTTIFindTypeByNameHash (ezUInt64 uiNameHash)
 Searches all ezRTTI instances for the one with the given hashed name, or nullptr if no such type exists.
 
static const ezRTTIFindTypeByNameHash32 (ezUInt32 uiNameHash)
 
static const ezRTTIFindTypeIf (PredicateFunc func)
 Searches all ezRTTI instances for one where the given predicate function returns true.
 
static void ForEachType (VisitorFunc func, ezBitflags< ForEachOptions > options=ForEachOptions::Default)
 
static void ForEachDerivedType (const ezRTTI *pBaseType, VisitorFunc func, ezBitflags< ForEachOptions > options=ForEachOptions::Default)
 
template<typename T >
static EZ_ALWAYS_INLINE void ForEachDerivedType (VisitorFunc func, ezBitflags< ForEachOptions > options=ForEachOptions::Default)
 

Protected Member Functions

void UpdateType (const ezRTTI *pParentType, ezUInt32 uiTypeSize, ezUInt32 uiTypeVersion, ezUInt8 uiVariantType, ezBitflags< ezTypeFlags > flags)
 
void RegisterType ()
 
void UnregisterType ()
 
void GatherDynamicMessageHandlers ()
 
void SetupParentHierarchy ()
 

Protected Attributes

ezStringView m_sPluginName
 
ezStringView m_sTypeName
 
ezArrayPtr< const ezAbstractProperty *const > m_Properties
 
ezArrayPtr< const ezAbstractFunctionProperty *const > m_Functions
 
ezArrayPtr< const ezPropertyAttribute *const > m_Attributes
 
const ezRTTIm_pParentType = nullptr
 
ezRTTIAllocatorm_pAllocator = nullptr
 
ezUInt32 m_uiTypeSize = 0
 
ezUInt32 m_uiTypeVersion = 0
 
ezUInt64 m_uiTypeNameHash = 0
 
ezUInt32 m_uiTypeIndex = 0
 
ezBitflags< ezTypeFlagsm_TypeFlags
 
ezUInt8 m_uiVariantType = 0
 
ezUInt16 m_uiMsgIdOffset = ezSmallInvalidIndex
 
const ezRTTI *(* m_VerifyParent )()
 
ezArrayPtr< ezAbstractMessageHandler * > m_MessageHandlers
 
ezSmallArray< ezAbstractMessageHandler *, 1, ezStaticsAllocatorWrapperm_DynamicMessageHandlers
 
ezArrayPtr< ezMessageSenderInfom_MessageSenders
 
ezSmallArray< const ezRTTI *, 7, ezStaticsAllocatorWrapperm_ParentHierarchy
 

Detailed Description

Core class of ezEngine's reflection system that holds complete runtime type information.

Each ezRTTI instance represents one reflected type and contains all metadata needed for runtime introspection, serialization, and object creation. The reflection system enables:

  • Runtime type queries and inheritance checks
  • Dynamic property access and modification
  • Object serialization and deserialization
  • Message dispatching and handling
  • Dynamic object creation and destruction
  • Editor property grids and tools

Key features:

  • Complete type hierarchy information with fast inheritance checks
  • Property metadata including types, attributes, and access methods
  • Message handling system for decoupled communication
  • Allocator integration for controlled object creation
  • Plugin-aware type registration for modular systems
  • Version tracking for data migration and compatibility

Performance considerations:

  • Type lookups are O(log n) using hash tables
  • Inheritance checks are O(1) using pre-computed hierarchy arrays
  • Property access involves virtual calls and type conversions
  • Message dispatching uses optimized jump tables

Usage: Types are typically registered using macros (EZ_BEGIN_STATIC_REFLECTED_TYPE, etc.) rather than creating ezRTTI instances manually.

Member Function Documentation

◆ DispatchMessage() [1/2]

bool ezRTTI::DispatchMessage ( const void *  pInstance,
ezMessage ref_msg 
) const

Dispatches a message to the appropriate handler (const version).

Same as the non-const version but for read-only message handlers. Some messages may only be handled by const handlers for safety reasons.

◆ DispatchMessage() [2/2]

bool ezRTTI::DispatchMessage ( void *  pInstance,
ezMessage ref_msg 
) const

Dispatches a message to the appropriate handler for this type.

Uses optimized message dispatch tables for fast O(1) message routing. Returns true if a handler was found and the message was processed, false if no handler exists for this message type. The message system enables decoupled communication between components.

◆ IsDerivedFrom()

EZ_ALWAYS_INLINE bool ezRTTI::IsDerivedFrom ( const ezRTTI pBaseType) const
inline

Fast O(1) check if this type is derived from the given type (or is the same type).

Uses pre-computed parent hierarchy arrays for constant-time inheritance checks. Returns true if this type inherits from pBaseType or if they are the same type. This is the preferred method for inheritance testing in performance-critical code.


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