138 inline const char *
GetName()
const {
return mName; }
139 void SetName(
const char *inName) { mName = inName; }
141 bool IsAbstract()
const {
return mCreate ==
nullptr || mDestruct ==
nullptr; }
142 int GetBaseClassCount()
const;
143 const RTTI * GetBaseClass(
int inIdx)
const;
147 void * CreateObject()
const;
150 void DestructObject(
void *inObject)
const;
153 void AddBaseClass(
const RTTI *inRTTI,
int inOffset);
156 bool operator == (
const RTTI &inRHS)
const;
157 bool operator != (
const RTTI &inRHS)
const {
return !(*
this == inRHS); }
163 const void * CastTo(
const void *inObject,
const RTTI *inRTTI)
const;
165#ifdef JPH_OBJECT_STREAM
168 int GetAttributeCount()
const;
185#ifdef JPH_OBJECT_STREAM
195#define JPH_DECLARE_RTTI_NON_VIRTUAL(linkage, class_name) \
197 JPH_OVERRIDE_NEW_DELETE \
198 friend linkage RTTI * GetRTTIOfType(class_name *); \
199 friend inline const RTTI * GetRTTI([[maybe_unused]] const class_name *inObject) { return GetRTTIOfType(static_cast<class_name *>(nullptr)); }\
200 static void sCreateRTTI(RTTI &inRTTI); \
203#define JPH_IMPLEMENT_RTTI_NON_VIRTUAL(class_name) \
204 RTTI * GetRTTIOfType(class_name *) \
206 static RTTI rtti(#class_name, sizeof(class_name), []() -> void * { return new class_name; }, [](void *inObject) { delete (class_name *)inObject; }, &class_name::sCreateRTTI); \
209 void class_name::sCreateRTTI(RTTI &inRTTI) \
217#define JPH_DECLARE_RTTI_OUTSIDE_CLASS(linkage, class_name) \
218 linkage RTTI * GetRTTIOfType(class_name *); \
219 inline const RTTI * GetRTTI(const class_name *inObject) { return GetRTTIOfType((class_name *)nullptr); }\
220 void CreateRTTI##class_name(RTTI &inRTTI); \
223#define JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(class_name) \
224 RTTI * GetRTTIOfType(class_name *) \
226 static RTTI rtti((const char *)#class_name, sizeof(class_name), []() -> void * { return new class_name; }, [](void *inObject) { delete (class_name *)inObject; }, &CreateRTTI##class_name); \
229 void CreateRTTI##class_name(RTTI &inRTTI)
235#define JPH_DECLARE_RTTI_HELPER(linkage, class_name, modifier) \
237 JPH_OVERRIDE_NEW_DELETE \
238 friend linkage RTTI * GetRTTIOfType(class_name *); \
239 friend inline const RTTI * GetRTTI(const class_name *inObject) { return inObject->GetRTTI(); } \
240 virtual const RTTI * GetRTTI() const modifier; \
241 virtual const void * CastTo(const RTTI *inRTTI) const modifier; \
242 static void sCreateRTTI(RTTI &inRTTI); \
245#define JPH_DECLARE_RTTI_VIRTUAL(linkage, class_name) \
246 JPH_DECLARE_RTTI_HELPER(linkage, class_name, override)
249#define JPH_IMPLEMENT_RTTI_VIRTUAL(class_name) \
250 RTTI * GetRTTIOfType(class_name *) \
252 static RTTI rtti(#class_name, sizeof(class_name), []() -> void * { return new class_name; }, [](void *inObject) { delete (class_name *)inObject; }, &class_name::sCreateRTTI); \
255 const RTTI * class_name::GetRTTI() const \
257 return JPH_RTTI(class_name); \
259 const void * class_name::CastTo(const RTTI *inRTTI) const \
261 return JPH_RTTI(class_name)->CastTo((const void *)this, inRTTI); \
263 void class_name::sCreateRTTI(RTTI &inRTTI) \
266#define JPH_DECLARE_RTTI_VIRTUAL_BASE(linkage, class_name) \
267 JPH_DECLARE_RTTI_HELPER(linkage, class_name, )
270#define JPH_IMPLEMENT_RTTI_VIRTUAL_BASE(class_name) \
271 JPH_IMPLEMENT_RTTI_VIRTUAL(class_name)
274#define JPH_DECLARE_RTTI_ABSTRACT(linkage, class_name) \
275 JPH_DECLARE_RTTI_HELPER(linkage, class_name, override)
278#define JPH_IMPLEMENT_RTTI_ABSTRACT(class_name) \
279 RTTI * GetRTTIOfType(class_name *) \
281 static RTTI rtti(#class_name, sizeof(class_name), nullptr, [](void *inObject) { delete (class_name *)inObject; }, &class_name::sCreateRTTI); \
284 const RTTI * class_name::GetRTTI() const \
286 return JPH_RTTI(class_name); \
288 const void * class_name::CastTo(const RTTI *inRTTI) const \
290 return JPH_RTTI(class_name)->CastTo((const void *)this, inRTTI); \
292 void class_name::sCreateRTTI(RTTI &inRTTI) \
295#define JPH_DECLARE_RTTI_ABSTRACT_BASE(linkage, class_name) \
296 JPH_DECLARE_RTTI_HELPER(linkage, class_name, )
299#define JPH_IMPLEMENT_RTTI_ABSTRACT_BASE(class_name) \
300 JPH_IMPLEMENT_RTTI_ABSTRACT(class_name)
306#define JPH_DECLARE_RTTI_FOR_FACTORY(linkage, class_name) \
307 linkage RTTI * GetRTTIOfType(class class_name *);
309#define JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(linkage, name_space, class_name) \
310 namespace name_space { \
312 linkage RTTI * GetRTTIOfType(class class_name *); \
319#define JPH_RTTI(class_name) GetRTTIOfType(static_cast<class_name *>(nullptr))
330#define JPH_RENAME_CLASS(class_name, new_name) \
331 inRTTI.SetName(#new_name);
338#define JPH_BASE_CLASS_OFFSET(inClass, inBaseClass) ((int(uint64((inBaseClass *)((inClass *)0x10000))))-0x10000)
341#define JPH_ADD_BASE_CLASS(class_name, base_class_name) \
342 inRTTI.AddBaseClass(JPH_RTTI(base_class_name), JPH_BASE_CLASS_OFFSET(class_name, base_class_name));
352 return inObject ==
nullptr || *inObject->GetRTTI() == *inRTTI;
358 return inObject ==
nullptr || *inObject->GetRTTI() == *inRTTI;
364 return inObject ==
nullptr || *inObject->GetRTTI() == *inRTTI;
371 return inObject ==
nullptr || inObject->GetRTTI()->
IsKindOf(inRTTI);
377 return inObject ==
nullptr || inObject->GetRTTI()->IsKindOf(inRTTI);
383 return inObject ==
nullptr || inObject->GetRTTI()->IsKindOf(inRTTI);
387template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
390 return static_cast<const DstType *
>(inObject);
393template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
396 return static_cast<DstType *
>(inObject);
399template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
402 return static_cast<const DstType *
>(inObject.
GetPtr());
405template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
408 return static_cast<DstType *
>(inObject.
GetPtr());
412template <
class DstType,
class SrcType>
415 return inObject !=
nullptr?
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType))) :
nullptr;
418template <
class DstType,
class SrcType>
421 return inObject !=
nullptr?
const_cast<DstType *
>(
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType)))) :
nullptr;
424template <
class DstType,
class SrcType>
427 return inObject !=
nullptr?
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType))) :
nullptr;
430template <
class DstType,
class SrcType>
433 return inObject !=
nullptr?
const_cast<DstType *
>(
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType)))) :
nullptr;
#define JPH_EXPORT
Definition Core.h:271
#define JPH_NAMESPACE_END
Definition Core.h:414
std::uint32_t uint32
Definition Core.h:484
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
const DstType * StaticCast(const SrcType *inObject)
Cast inObject to DstType, asserts on failure.
Definition RTTI.h:388
bool IsType(const Type *inObject, const RTTI *inRTTI)
Check if inObject is of DstType.
Definition RTTI.h:350
bool IsKindOf(const Type *inObject, const RTTI *inRTTI)
Check if inObject is or is derived from DstType.
Definition RTTI.h:369
#define JPH_RTTI(class_name)
Definition RTTI.h:319
const DstType * DynamicCast(const SrcType *inObject)
Cast inObject to DstType, returns nullptr on failure.
Definition RTTI.h:413
pDestructObjectFunction mDestruct
Pointer to a function that will destruct an object of this class.
Definition RTTI.h:184
pCreateObjectFunction mCreate
Pointer to a function that will create a new instance of this class.
Definition RTTI.h:183
const char * GetName() const
Definition RTTI.h:138
StaticArray< SerializableAttribute, 32 > mAttributes
All attributes of this class.
Definition RTTI.h:186
void *(*)() pCreateObjectFunction
Function to create an object.
Definition RTTI.h:125
StaticArray< BaseClass, 4 > mBaseClasses
Names of base classes.
Definition RTTI.h:182
int GetSize() const
Definition RTTI.h:140
bool IsAbstract() const
Definition RTTI.h:141
bool IsKindOf(const RTTI *inRTTI) const
Test if this class is derived from class of type inRTTI.
Definition RTTI.cpp:92
void(*)(RTTI &inRTTI) pCreateRTTIFunction
Function to initialize the runtime type info structure.
Definition RTTI.h:131
void(*)(void *inObject) pDestructObjectFunction
Function to destroy an object.
Definition RTTI.h:128
void SetName(const char *inName)
Definition RTTI.h:139
const char * mName
Class name.
Definition RTTI.h:180
int mSize
Class size.
Definition RTTI.h:181
Definition Reference.h:163
const T * GetPtr() const
Get pointer.
Definition Reference.h:197
Definition Reference.h:107
T * GetPtr() const
Get pointer.
Definition Reference.h:135
Attributes are members of classes that need to be serialized.
Definition SerializableAttribute.h:37
Simple variable length array backed by a fixed size buffer.
Definition StaticArray.h:14
Base class information.
Definition RTTI.h:175
const RTTI * mRTTI
Definition RTTI.h:176
int mOffset
Definition RTTI.h:177