| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#ifdef JPH_OBJECT_STREAM |
| 8 |
|
| 9 |
#include <Jolt/ObjectStream/SerializableAttribute.h> |
| 10 |
#include <Jolt/ObjectStream/ObjectStream.h> |
| 11 |
|
| 12 |
JPH_NAMESPACE_BEGIN |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
template <class MemberType> |
| 19 |
inline void AddSerializableAttributeEnum(RTTI &inRTTI, uint inOffset, const char *inName) |
| 20 |
{ |
| 21 |
inRTTI.AddAttribute(SerializableAttribute(inName, inOffset, |
| 22 |
[]() -> const RTTI * |
| 23 |
{ |
| 24 |
return nullptr; |
| 25 |
}, |
| 26 |
[](int inArrayDepth, EOSDataType inDataType, [[maybe_unused]] const char *inClassName) |
| 27 |
{ |
| 28 |
return inArrayDepth == 0 && inDataType == EOSDataType::T_uint32; |
| 29 |
}, |
| 30 |
[](IObjectStreamIn &ioStream, void *inObject) |
| 31 |
{ |
| 32 |
uint32 temporary; |
| 33 |
if (OSReadData(ioStream, temporary)) |
| 34 |
{ |
| 35 |
*reinterpret_cast<MemberType *>(inObject) = static_cast<MemberType>(temporary); |
| 36 |
return true; |
| 37 |
} |
| 38 |
return false; |
| 39 |
}, |
| 40 |
[](IObjectStreamOut &ioStream, const void *inObject) |
| 41 |
{ |
| 42 |
static_assert(sizeof(MemberType) <= sizeof(uint32)); |
| 43 |
uint32 temporary = uint32(*reinterpret_cast<const MemberType *>(inObject)); |
| 44 |
OSWriteData(ioStream, temporary); |
| 45 |
}, |
| 46 |
[](IObjectStreamOut &ioStream) |
| 47 |
{ |
| 48 |
ioStream.WriteDataType(EOSDataType::T_uint32); |
| 49 |
})); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
#define JPH_ADD_ENUM_ATTRIBUTE_WITH_ALIAS(class_name, member_name, alias_name) \ |
| 54 |
AddSerializableAttributeEnum<decltype(class_name::member_name)>(inRTTI, offsetof(class_name, member_name), alias_name); |
| 55 |
|
| 56 |
|
| 57 |
#define JPH_ADD_ENUM_ATTRIBUTE(class_name, member_name) \ |
| 58 |
JPH_ADD_ENUM_ATTRIBUTE_WITH_ALIAS(class_name, member_name, #member_name); |
| 59 |
|
| 60 |
JPH_NAMESPACE_END |
| 61 |
|
| 62 |
#else |
| 63 |
|
| 64 |
#define JPH_ADD_ENUM_ATTRIBUTE_WITH_ALIAS(...) |
| 65 |
#define JPH_ADD_ENUM_ATTRIBUTE(...) |
| 66 |
|
| 67 |
#endif |