7.0 KiB
VlppReflection Knowledge Base
Project introduction remains in Index.md.
Choosing APIs
Reflection Compilation Levels
Three different compilation modes for reflection support with varying runtime capabilities.
The reflection system supports three compilation levels:
- Full reflection: Complete metadata and runtime support for type registration and function calls
- Metadata-only (
VCZH_DESCRIPTABLEOBJECT_WITH_METADATA): Type metadata without runtime support - No reflection (
VCZH_DEBUG_NO_REFLECTION): Reflection disabled entirely Always prefer code compatible withVCZH_DEBUG_NO_REFLECTIONwhen possible.
Type Metadata Access
Runtime type information retrieval and manipulation through the reflection system.
- Use
vl::reflection::description::GetTypeDescriptor<T>for type metadata access when reflection is enabled - Use
vl::reflection::description::Valuefor boxing any value type similar to C# object or std::any - Use
Description<T>base class for making classes reflectable - Use
AggregatableDescription<T>for classes that can be inherited in Workflow scripts - Use
IDescriptableinterface for reflectable interfaces without other base interfaces
Type Registration Structure
Organized approach for registering types with proper file organization and macro usage.
All type registration must occur in vl::reflection::description namespace with specific file organization:
- Type lists and interface proxies in
.hfiles - Type metadata registration in
.cppfiles - Registration code in dedicated files
- Follow established patterns from existing source code examples
Enum Registration
Registration patterns for enumeration types with support for simple lists and combinable flags.
- Use
BEGIN_ENUM_ITEMandEND_ENUM_ITEMfor simple enumeration lists - Use
BEGIN_ENUM_ITEM_MERGABLEandEND_ENUM_ITEMfor combinable flag enumerations - Use
ENUM_CLASS_ITEMfor enum class members - Use
ENUM_ITEMfor enum members - Use
ENUM_ITEM_NAMESPACEandENUM_NAMESPACE_ITEMfor enums defined inside other types
Struct Registration
Registration patterns for structure types with field access capabilities.
- Use
BEGIN_STRUCT_MEMBERandEND_STRUCT_MEMBERfor struct registration - Use
STRUCT_MEMBERto register each accessible field - Use
ATTRIBUTE_TYPE,ATTRIBUTE_MEMBERto attach attributes to the struct or its fields
Class and Interface Registration
Comprehensive registration system for classes and interfaces with methods, properties, and events.
- Use
BEGIN_CLASS_MEMBERandEND_CLASS_MEMBERfor class registration - Use
BEGIN_INTERFACE_MEMBERandEND_INTERFACE_MEMBERfor inheritable interfaces - Use
BEGIN_INTERFACE_MEMBER_NOPROXYandEND_INTERFACE_MEMBERfor non-inheritable interfaces - Use
CLASS_MEMBER_BASEfor reflectable base class declaration - Use
CLASS_MEMBER_FIELDfor member field registration - Use
CLASS_MEMBER_CONSTRUCTORfor constructor registration withPtr<Class>(types...)orClass*(types...) - Use
CLASS_MEMBER_EXTERNALCTOR,CLASS_MEMBER_EXTERNALCTOR_TEMPLATEfor external function constructors - Use
CLASS_MEMBER_METHOD,CLASS_MEMBER_METHOD_RENAMEfor method registration with parameter names - Use
CLASS_MEMBER_METHOD_OVERLOAD,CLASS_MEMBER_METHOD_OVERLOAD_RENAMEfor overloaded method registration - Use
CLASS_MEMBER_EXTERNALMETHOD,CLASS_MEMBER_EXTERNALMETHOD_TEMPLATEfor external function methods - Use
CLASS_MEMBER_STATIC_METHOD,CLASS_MEMBER_STATIC_METHOD_OVERLOADfor static method registration - Use
CLASS_MEMBER_STATIC_EXTERNALMETHOD,CLASS_MEMBER_STATIC_EXTERNALMETHOD_TEMPLATEfor global functions registered as static methods - Use
CLASS_MEMBER_EVENTfor event registration - Use
CLASS_MEMBER_PROPERTY_READONLY,CLASS_MEMBER_PROPERTYfor property registration - Use
CLASS_MEMBER_PROPERTY_EVENT_READONLY,CLASS_MEMBER_PROPERTY_EVENTfor properties with explicit getter/setter/event methods - Use
CLASS_MEMBER_PROPERTY_REFERENCETEMPLATEfor properties with custom generated C++ reference code - Use
CLASS_MEMBER_PROPERTY_READONLY_FAST,CLASS_MEMBER_PROPERTY_FASTfor standard getter/setter patterns - Use
CLASS_MEMBER_PROPERTY_EVENT_READONLY_FAST,CLASS_MEMBER_PROPERTY_EVENT_FASTfor properties with change events - Use
NO_PARAMETERfor parameterless functions - Use
{ L"arg1" _ L"arg2" ... }for parameter name lists - Use
ATTRIBUTE_TYPE,ATTRIBUTE_MEMBER,ATTRIBUTE_PARAMETERto attach attributes to types, members, and parameters
Interface Proxy Implementation
Proxy generation for interfaces to enable inheritance in Workflow scripts.
- Use
BEGIN_INTERFACE_PROXY_NOPARENT_RAWPTRfor interfaces without base interfaces using raw pointers - Use
BEGIN_INTERFACE_PROXY_NOPARENT_SHAREDPTRfor interfaces without base interfaces using Ptr - Use
BEGIN_INTERFACE_PROXY_RAWPTRfor interfaces with base interfaces using raw pointers - Use
BEGIN_INTERFACE_PROXY_SHAREDPTRfor interfaces with base interfaces using Ptr - Use
END_INTERFACE_PROXYto complete proxy definition - Use
INVOKE_INTERFACE_PROXY_NOPARAMSfor void methods without parameters - Use
INVOKEGET_INTERFACE_PROXY_NOPARAMSfor return value methods without parameters - Use
INVOKE_INTERFACE_PROXYfor void methods with parameters - Use
INVOKEGET_INTERFACE_PROXYfor return value methods with parameters
Attribute Registration
Attach metadata attributes to types, members, and method parameters during reflection registration.
Attributes are instances of reflectable structs whose constructor arguments are serializable values, with ITypeDescriptor* as the explicit descriptor-reference exception.
They are stored centrally in the owning type descriptor and can be queried at runtime via the IAttributeBag / IAttributeInfo interfaces.
Attributes survive metaonly metadata serialization and deserialization, and appear in the logged text output.
- Use
ATTRIBUTE_TYPE(TYPE, ...)to attach an attribute to the enclosing type descriptor - Use
ATTRIBUTE_MEMBER(TYPE, ...)to attach an attribute to the most recently registered member (field, property, event, method, or constructor) - Use
ATTRIBUTE_PARAMETER(PARAMETER_NAME, TYPE, ...)to attach an attribute to a named parameter of the most recently registered method or constructor - Use
IAttributeBag::GetAttributeCountandIAttributeBag::GetAttributeto query attributes at runtime - Use
IAttributeInfo::GetAttributeType,IAttributeInfo::GetAttributeValueCount,IAttributeInfo::GetAttributeValueType,IAttributeInfo::GetAttributeValueto inspect attribute content