Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SerializableAttributeEnum.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
13// Macros to add properties to be serialized
15
16template <class MemberType>
17inline void AddSerializableAttributeEnum(RTTI &inRTTI, uint inOffset, const char *inName)
18{
19 inRTTI.AddAttribute(SerializableAttribute(inName, inOffset,
20 []() -> const RTTI *
21 {
22 return nullptr;
23 },
24 [](int inArrayDepth, EOSDataType inDataType, [[maybe_unused]] const char *inClassName)
25 {
26 return inArrayDepth == 0 && inDataType == EOSDataType::T_uint32;
27 },
28 [](IObjectStreamIn &ioStream, void *inObject)
29 {
30 uint32 temporary;
31 if (OSReadData(ioStream, temporary))
32 {
33 *reinterpret_cast<MemberType *>(inObject) = static_cast<MemberType>(temporary);
34 return true;
35 }
36 return false;
37 },
38 [](IObjectStreamOut &ioStream, const void *inObject)
39 {
40 static_assert(sizeof(MemberType) <= sizeof(uint32));
41 uint32 temporary = uint32(*reinterpret_cast<const MemberType *>(inObject));
42 OSWriteData(ioStream, temporary);
43 },
44 [](IObjectStreamOut &ioStream)
45 {
46 ioStream.WriteDataType(EOSDataType::T_uint32);
47 }));
48}
49
50// JPH_ADD_ENUM_ATTRIBUTE_WITH_ALIAS
51#define JPH_ADD_ENUM_ATTRIBUTE_WITH_ALIAS(class_name, member_name, alias_name) \
52 AddSerializableAttributeEnum<decltype(class_name::member_name)>(inRTTI, offsetof(class_name, member_name), alias_name);
53
54// JPH_ADD_ENUM_ATTRIBUTE
55#define JPH_ADD_ENUM_ATTRIBUTE(class_name, member_name) \
56 JPH_ADD_ENUM_ATTRIBUTE_WITH_ALIAS(class_name, member_name, #member_name);
57
unsigned int uint
Definition: Core.h:439
#define JPH_NAMESPACE_END
Definition: Core.h:367
std::uint32_t uint32
Definition: Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
void OSWriteData(IObjectStreamOut &ioStream, const Array< T > &inArray)
Definition: ObjectStream.h:241
bool OSReadData(IObjectStreamIn &ioStream, Array< T > &inArray)
Define serialization templates for dynamic arrays.
Definition: ObjectStream.h:154
EOSDataType
Data type.
Definition: SerializableAttribute.h:15
JPH_NAMESPACE_BEGIN void AddSerializableAttributeEnum(RTTI &inRTTI, uint inOffset, const char *inName)
Definition: SerializableAttributeEnum.h:17
Interface class for reading from an object stream.
Definition: ObjectStream.h:40
Interface class for writing to an object stream.
Definition: ObjectStream.h:74
Definition: RTTI.h:122
void AddAttribute(const SerializableAttribute &inAttribute)
Attribute access.
Definition: RTTI.cpp:128
Attributes are members of classes that need to be serialized.
Definition: SerializableAttribute.h:35