Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SerializableAttributeTyped.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
7#ifdef JPH_OBJECT_STREAM
8
12
14
16// Macros to add properties to be serialized
18
19template <class MemberType>
20inline void AddSerializableAttributeTyped(RTTI &inRTTI, uint inOffset, const char *inName)
21{
22 inRTTI.AddAttribute(SerializableAttribute(inName, inOffset,
23 []()
24 {
25 return GetPrimitiveTypeOfType((MemberType *)nullptr);
26 },
27 [](int inArrayDepth, EOSDataType inDataType, const char *inClassName)
28 {
29 return OSIsType((MemberType *)nullptr, inArrayDepth, inDataType, inClassName);
30 },
31 [](IObjectStreamIn &ioStream, void *inObject)
32 {
33 return OSReadData(ioStream, *reinterpret_cast<MemberType *>(inObject));
34 },
35 [](IObjectStreamOut &ioStream, const void *inObject)
36 {
37 OSWriteData(ioStream, *reinterpret_cast<const MemberType *>(inObject));
38 },
39 [](IObjectStreamOut &ioStream)
40 {
41 OSWriteDataType(ioStream, (MemberType *)nullptr);
42 }));
43}
44
45// JPH_ADD_ATTRIBUTE
46#define JPH_ADD_ATTRIBUTE_WITH_ALIAS(class_name, member_name, alias_name) \
47 AddSerializableAttributeTyped<decltype(class_name::member_name)>(inRTTI, offsetof(class_name, member_name), alias_name);
48
49// JPH_ADD_ATTRIBUTE
50#define JPH_ADD_ATTRIBUTE(class_name, member_name) \
51 JPH_ADD_ATTRIBUTE_WITH_ALIAS(class_name, member_name, #member_name)
52
54
55#else
56
57#define JPH_ADD_ATTRIBUTE_WITH_ALIAS(...)
58#define JPH_ADD_ATTRIBUTE(...)
59
60#endif // JPH_OBJECT_STREAM
unsigned int uint
Definition Core.h:446
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
JPH_NAMESPACE_BEGIN const RTTI * GetPrimitiveTypeOfType(T *)
Helper functions to get the underlying RTTI type of a type (so e.g. Array<sometype> will return somet...
Definition GetPrimitiveTypeOfType.h:13
bool OSIsType(Array< T, A > *, int inArrayDepth, EOSDataType inDataType, const char *inClassName)
Definition ObjectStream.h:125
bool OSReadData(IObjectStreamIn &ioStream, Array< T, A > &inArray)
Define serialization templates for dynamic arrays.
Definition ObjectStream.h:156
void OSWriteData(IObjectStreamOut &ioStream, const Array< T, A > &inArray)
Definition ObjectStream.h:243
void OSWriteDataType(IObjectStreamOut &ioStream, Array< T, A > *)
Definition ObjectStream.h:236
EOSDataType
Data type.
Definition SerializableAttribute.h:17
JPH_NAMESPACE_BEGIN void AddSerializableAttributeTyped(RTTI &inRTTI, uint inOffset, const char *inName)
Definition SerializableAttributeTyped.h:20
Interface class for reading from an object stream.
Definition ObjectStream.h:42
Interface class for writing to an object stream.
Definition ObjectStream.h:76
Definition RTTI.h:122
void AddAttribute(const SerializableAttribute &inAttribute)
Attribute access.
Definition RTTI.cpp:132
Attributes are members of classes that need to be serialized.
Definition SerializableAttribute.h:37