ezEngine  Milestone 7
DynamicRTTI.h
Go to the documentation of this file.
1 #pragma once
2 
4 
7 
13 #define EZ_ADD_DYNAMIC_REFLECTION(SELF) \
14  EZ_ALLOW_PRIVATE_PROPERTIES(SELF); \
15  public: \
16  EZ_FORCE_INLINE static const ezRTTI* GetStaticRTTI() \
17  { \
18  return &SELF::s_RTTI; \
19  } \
20  virtual const ezRTTI* GetDynamicRTTI() const \
21  { \
22  return &SELF::s_RTTI; \
23  } \
24  private: \
25  static ezRTTI s_RTTI; \
26  EZ_REFLECTION_DEBUG_CODE
27 
28 #if EZ_ENABLED(EZ_COMPILE_FOR_DEBUG) && EZ_ENABLED(EZ_COMPILER_MSVC)
29  #define EZ_REFLECTION_DEBUG_CODE \
30  static const ezRTTI* ReflectionDebug_GetParentType()\
31  {\
32  return __super::GetStaticRTTI();\
33  }
34  #define EZ_REFLECTION_DEBUG_GETPARENTFUNC &OwnType::ReflectionDebug_GetParentType
35 
36 #else
37  #define EZ_REFLECTION_DEBUG_CODE /*empty*/
38  #define EZ_REFLECTION_DEBUG_GETPARENTFUNC nullptr
39 #endif
40 
41 
53 #define EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(Type, BaseType, Version, AllocatorType) \
54  EZ_RTTIINFO_DECL(Type, BaseType, Version) \
55  ezRTTI Type::s_RTTI = ezRTTInfo_##Type::GetRTTI(); \
56  EZ_RTTIINFO_GETRTTI_IMPL_BEGIN(Type, AllocatorType)
57 
59 #define EZ_END_DYNAMIC_REFLECTED_TYPE() \
60  return ezRTTI(GetTypeName(), \
61  ezGetStaticRTTI<OwnBaseType>(), \
62  sizeof(OwnType), \
63  GetTypeVersion(), \
64  ezVariant::TypeDeduction<OwnType>::value, \
65  flags, \
66  &Allocator, Properties, MessageHandlers, EZ_REFLECTION_DEBUG_GETPARENTFUNC); \
67  }
68 
69 class ezArchiveWriter;
70 class ezArchiveReader;
71 
75 class EZ_FOUNDATION_DLL ezReflectedClass : public ezNoBase
76 {
78 public:
79  EZ_FORCE_INLINE ezReflectedClass()
80  {
81  }
82 
83  virtual ~ezReflectedClass() {}
84 
86  EZ_FORCE_INLINE bool IsInstanceOf(const ezRTTI* pType) const
87  {
88  return GetDynamicRTTI()->IsDerivedFrom(pType);
89  }
90 
92  template<typename T>
93  EZ_FORCE_INLINE bool IsInstanceOf() const
94  {
95  return GetDynamicRTTI()->IsDerivedFrom<T>();
96  }
97 
103  virtual void Serialize(ezArchiveWriter& stream) const
104  {
105  EZ_REPORT_FAILURE("Serialize is not overridden by deriving class.");
106  }
107 
116  virtual void Deserialize(ezArchiveReader& stream)
117  {
118  EZ_REPORT_FAILURE("Deserialize is not overridden by deriving class.");
119  }
120 
128  virtual void OnDeserialized()
129  {
130  EZ_REPORT_FAILURE("OnDeserialized is not overridden by deriving class.");
131  }
132 };