Plasma Engine  2.0
Loading...
Searching...
No Matches
DynamicRTTI.h
1#pragma once
2
4
5#include <Foundation/Reflection/Implementation/StaticRTTI.h>
6
12#define PL_ADD_DYNAMIC_REFLECTION_NO_GETTER(SELF, BASE_TYPE) \
13 PL_ALLOW_PRIVATE_PROPERTIES(SELF); \
14 \
15public: \
16 using OWNTYPE = SELF; \
17 using SUPER = BASE_TYPE; \
18 PL_ALWAYS_INLINE static const plRTTI* GetStaticRTTI() \
19 { \
20 return &SELF::s_RTTI; \
21 } \
22 \
23private: \
24 static plRTTI s_RTTI; \
25 PL_REFLECTION_DEBUG_CODE
26
27
28#define PL_ADD_DYNAMIC_REFLECTION(SELF, BASE_TYPE) \
29 PL_ADD_DYNAMIC_REFLECTION_NO_GETTER(SELF, BASE_TYPE) \
30public: \
31 virtual const plRTTI* GetDynamicRTTI() const override \
32 { \
33 return &SELF::s_RTTI; \
34 }
35
36
37#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT) && PL_ENABLED(PL_COMPILER_MSVC)
38
39# define PL_REFLECTION_DEBUG_CODE \
40 static const plRTTI* ReflectionDebug_GetParentType() \
41 { \
42 return __super::GetStaticRTTI(); \
43 }
44
45# define PL_REFLECTION_DEBUG_GETPARENTFUNC &OwnType::ReflectionDebug_GetParentType
46
47#else
48# define PL_REFLECTION_DEBUG_CODE /*empty*/
49# define PL_REFLECTION_DEBUG_GETPARENTFUNC nullptr
50#endif
51
52
64#define PL_BEGIN_DYNAMIC_REFLECTED_TYPE(Type, Version, AllocatorType) \
65 PL_RTTIINFO_DECL(Type, Type::SUPER, Version) \
66 plRTTI Type::s_RTTI = GetRTTI((Type*)0); \
67 PL_RTTIINFO_GETRTTI_IMPL_BEGIN(Type, Type::SUPER, AllocatorType)
68
70#define PL_END_DYNAMIC_REFLECTED_TYPE \
71 return plRTTI(GetTypeName((OwnType*)0), plGetStaticRTTI<OwnBaseType>(), sizeof(OwnType), GetTypeVersion((OwnType*)0), \
72 plVariant::TypeDeduction<OwnType>::value, flags, &Allocator, Properties, Functions, Attributes, MessageHandlers, MessageSenders, \
73 PL_REFLECTION_DEBUG_GETPARENTFUNC); \
74 }
75
78#define PL_BEGIN_ABSTRACT_DYNAMIC_REFLECTED_TYPE(Type, Version) \
79 PL_BEGIN_DYNAMIC_REFLECTED_TYPE(Type, Version, plRTTINoAllocator) \
80 flags.Add(plTypeFlags::Abstract);
81
82#define PL_END_ABSTRACT_DYNAMIC_REFLECTED_TYPE PL_END_DYNAMIC_REFLECTED_TYPE
83
85class PL_FOUNDATION_DLL plReflectedClass : public plNoBase
86{
87 PL_ADD_DYNAMIC_REFLECTION_NO_GETTER(plReflectedClass, plNoBase);
88
89public:
90 virtual const plRTTI* GetDynamicRTTI() const { return &plReflectedClass::s_RTTI; }
91
92public:
93 PL_ALWAYS_INLINE plReflectedClass() = default;
94 PL_ALWAYS_INLINE virtual ~plReflectedClass() = default;
95
97 bool IsInstanceOf(const plRTTI* pType) const;
98
100 template <typename T>
101 PL_ALWAYS_INLINE bool IsInstanceOf() const
102 {
103 const plRTTI* pType = plGetStaticRTTI<T>();
104 return IsInstanceOf(pType);
105 }
106};
Dummy type to pass to templates and macros that expect a base type for a class that has no base.
Definition Types.h:133
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
PL_ALWAYS_INLINE bool IsInstanceOf() const
Returns whether the type of this instance is of the given type or derived from it.
Definition DynamicRTTI.h:101