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;
176 #ifdef JPH_DISABLE_CUSTOM_ALLOCATOR
184 return ::new (
object) T;
192 #ifdef JPH_DISABLE_CUSTOM_ALLOCATOR
193 delete static_cast<T *
>(inObject);
195 static_cast<T *
>(inObject)->~T();
216#ifdef JPH_OBJECT_STREAM
226#define JPH_DECLARE_RTTI_NON_VIRTUAL(linkage, class_name) \
228 JPH_OVERRIDE_NEW_DELETE \
229 friend linkage JPH::RTTI * GetRTTIOfType(class_name *); \
230 friend inline const JPH::RTTI *GetRTTI([[maybe_unused]] const class_name *inObject) { return GetRTTIOfType(static_cast<class_name *>(nullptr)); } \
231 static void sCreateRTTI(JPH::RTTI &inRTTI); \
234#define JPH_IMPLEMENT_RTTI_NON_VIRTUAL(class_name) \
235 JPH::RTTI * GetRTTIOfType(class_name *) \
237 static JPH::RTTI rtti(#class_name, sizeof(class_name), []() -> void * { return new class_name; }, [](void *inObject) { delete (class_name *)inObject; }, &class_name::sCreateRTTI); \
240 void class_name::sCreateRTTI(JPH::RTTI &inRTTI) \
248#define JPH_DECLARE_RTTI_OUTSIDE_CLASS(linkage, class_name) \
249 linkage JPH::RTTI * GetRTTIOfType(class_name *); \
250 inline const JPH::RTTI * GetRTTI(const class_name *inObject) { return GetRTTIOfType((class_name *)nullptr); }\
251 void CreateRTTI##class_name(JPH::RTTI &inRTTI); \
254#define JPH_IMPLEMENT_RTTI_OUTSIDE_CLASS(class_name) \
255 JPH::RTTI * GetRTTIOfType(class_name *) \
257 static JPH::RTTI rtti((const char *)#class_name, sizeof(class_name), &JPH::RTTI::sCreateObjectInternal<class_name>, &JPH::RTTI::sDestructObjectInternal<class_name>, &CreateRTTI##class_name); \
260 void CreateRTTI##class_name(JPH::RTTI &inRTTI)
266#define JPH_DECLARE_RTTI_HELPER(linkage, class_name, modifier) \
268 JPH_OVERRIDE_NEW_DELETE \
269 friend linkage JPH::RTTI * GetRTTIOfType(class_name *); \
270 friend inline const JPH::RTTI *GetRTTI(const class_name *inObject) { return inObject->GetRTTI(); } \
271 virtual const JPH::RTTI * GetRTTI() const modifier; \
272 virtual const void * CastTo(const JPH::RTTI *inRTTI) const modifier; \
273 static void sCreateRTTI(JPH::RTTI &inRTTI); \
276#define JPH_DECLARE_RTTI_VIRTUAL(linkage, class_name) \
277 JPH_DECLARE_RTTI_HELPER(linkage, class_name, override)
280#define JPH_IMPLEMENT_RTTI_VIRTUAL(class_name) \
281 JPH::RTTI * GetRTTIOfType(class_name *) \
283 static JPH::RTTI rtti(#class_name, sizeof(class_name), []() -> void * { return new class_name; }, [](void *inObject) { delete (class_name *)inObject; }, &class_name::sCreateRTTI); \
286 const JPH::RTTI * class_name::GetRTTI() const \
288 return JPH_RTTI(class_name); \
290 const void * class_name::CastTo(const JPH::RTTI *inRTTI) const \
292 return JPH_RTTI(class_name)->CastTo((const void *)this, inRTTI); \
294 void class_name::sCreateRTTI(JPH::RTTI &inRTTI) \
297#define JPH_DECLARE_RTTI_VIRTUAL_BASE(linkage, class_name) \
298 JPH_DECLARE_RTTI_HELPER(linkage, class_name, )
301#define JPH_IMPLEMENT_RTTI_VIRTUAL_BASE(class_name) \
302 JPH_IMPLEMENT_RTTI_VIRTUAL(class_name)
305#define JPH_DECLARE_RTTI_ABSTRACT(linkage, class_name) \
306 JPH_DECLARE_RTTI_HELPER(linkage, class_name, override)
309#define JPH_IMPLEMENT_RTTI_ABSTRACT(class_name) \
310 JPH::RTTI * GetRTTIOfType(class_name *) \
312 static JPH::RTTI rtti(#class_name, sizeof(class_name), nullptr, [](void *inObject) { delete (class_name *)inObject; }, &class_name::sCreateRTTI); \
315 const JPH::RTTI * class_name::GetRTTI() const \
317 return JPH_RTTI(class_name); \
319 const void * class_name::CastTo(const JPH::RTTI *inRTTI) const \
321 return JPH_RTTI(class_name)->CastTo((const void *)this, inRTTI); \
323 void class_name::sCreateRTTI(JPH::RTTI &inRTTI) \
326#define JPH_DECLARE_RTTI_ABSTRACT_BASE(linkage, class_name) \
327 JPH_DECLARE_RTTI_HELPER(linkage, class_name, )
330#define JPH_IMPLEMENT_RTTI_ABSTRACT_BASE(class_name) \
331 JPH_IMPLEMENT_RTTI_ABSTRACT(class_name)
337#define JPH_DECLARE_RTTI_FOR_FACTORY(linkage, class_name) \
338 linkage JPH::RTTI * GetRTTIOfType(class class_name *);
340#define JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(linkage, name_space, class_name) \
341 namespace name_space { \
343 linkage JPH::RTTI * GetRTTIOfType(class class_name *); \
350#define JPH_RTTI(class_name) GetRTTIOfType(static_cast<class_name *>(nullptr))
361#define JPH_RENAME_CLASS(class_name, new_name) \
362 inRTTI.SetName(#new_name);
369#define JPH_BASE_CLASS_OFFSET(inClass, inBaseClass) ((int(JPH::uint64((inBaseClass *)((inClass *)0x10000))))-0x10000)
372#define JPH_ADD_BASE_CLASS(class_name, base_class_name) \
373 inRTTI.AddBaseClass(JPH_RTTI(base_class_name), JPH_BASE_CLASS_OFFSET(class_name, base_class_name));
383 return inObject ==
nullptr || *inObject->GetRTTI() == *inRTTI;
389 return inObject ==
nullptr || *inObject->GetRTTI() == *inRTTI;
395 return inObject ==
nullptr || *inObject->GetRTTI() == *inRTTI;
402 return inObject ==
nullptr || inObject->GetRTTI()->
IsKindOf(inRTTI);
408 return inObject ==
nullptr || inObject->GetRTTI()->IsKindOf(inRTTI);
414 return inObject ==
nullptr || inObject->GetRTTI()->IsKindOf(inRTTI);
418template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
421 return static_cast<const DstType *
>(inObject);
424template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
427 return static_cast<DstType *
>(inObject);
430template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
433 return static_cast<const DstType *
>(inObject.
GetPtr());
436template <
class DstType,
class SrcType, std::enable_if_t<std::is_base_of_v<DstType, SrcType> || std::is_base_of_v<SrcType, DstType>,
bool> = true>
439 return static_cast<DstType *
>(inObject.
GetPtr());
443template <
class DstType,
class SrcType>
446 return inObject !=
nullptr?
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType))) :
nullptr;
449template <
class DstType,
class SrcType>
452 return inObject !=
nullptr?
const_cast<DstType *
>(
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType)))) :
nullptr;
455template <
class DstType,
class SrcType>
458 return inObject !=
nullptr?
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType))) :
nullptr;
461template <
class DstType,
class SrcType>
464 return inObject !=
nullptr?
const_cast<DstType *
>(
reinterpret_cast<const DstType *
>(inObject->CastTo(
JPH_RTTI(DstType)))) :
nullptr;
#define JPH_DEFAULT_ALLOCATE_ALIGNMENT
Definition Core.h:607
#define JPH_EXPORT
Definition Core.h:303
#define JPH_NAMESPACE_END
Definition Core.h:487
std::uint32_t uint32
Definition Core.h:567
#define JPH_NAMESPACE_BEGIN
Definition Core.h:481
AlignedFreeFunction AlignedFree
Definition Memory.cpp:72
AlignedAllocateFunction AlignedAllocate
Definition Memory.cpp:71
#define JPH_INTERNAL_DEFAULT_FREE(pointer)
Definition Memory.h:47
#define JPH_INTERNAL_DEFAULT_ALLOCATE(size)
Definition Memory.h:46
const DstType * StaticCast(const SrcType *inObject)
Cast inObject to DstType, asserts on failure.
Definition RTTI.h:419
bool IsType(const Type *inObject, const RTTI *inRTTI)
Check if inObject is of DstType.
Definition RTTI.h:381
bool IsKindOf(const Type *inObject, const RTTI *inRTTI)
Check if inObject is or is derived from DstType.
Definition RTTI.h:400
#define JPH_RTTI(class_name)
Definition RTTI.h:350
const DstType * DynamicCast(const SrcType *inObject)
Cast inObject to DstType, returns nullptr on failure.
Definition RTTI.h:444
pDestructObjectFunction mDestruct
Pointer to a function that will destruct an object of this class.
Definition RTTI.h:215
pCreateObjectFunction mCreate
Pointer to a function that will create a new instance of this class.
Definition RTTI.h:214
const char * GetName() const
Definition RTTI.h:138
StaticArray< SerializableAttribute, 32 > mAttributes
All attributes of this class.
Definition RTTI.h:217
void *(*)() pCreateObjectFunction
Function to create an object.
Definition RTTI.h:125
StaticArray< BaseClass, 4 > mBaseClasses
Names of base classes.
Definition RTTI.h:213
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
static void * sCreateObjectInternal()
Create an object of type T for types that cannot use JPH_OVERRIDE_NEW_DELETE (e.g....
Definition RTTI.h:174
const char * mName
Class name.
Definition RTTI.h:211
int mSize
Class size.
Definition RTTI.h:212
RTTI(const char *inName, int inSize, pCreateObjectFunction inCreateObject, pDestructObjectFunction inDestructObject)
Constructor.
Definition RTTI.cpp:16
static void sDestructObjectInternal(void *inObject)
Destruct an object created with sCreateObjectInternal.
Definition RTTI.h:190
Definition Reference.h:166
const T * GetPtr() const
Get pointer.
Definition Reference.h:200
Definition Reference.h:110
T * GetPtr() const
Get pointer.
Definition Reference.h:138
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:206
const RTTI * mRTTI
Definition RTTI.h:207
int mOffset
Definition RTTI.h:208