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
10
12
14// Macros to add properties to be serialized
16
17template <class MemberType>
18inline void AddSerializableAttributeTyped(RTTI &inRTTI, uint inOffset, const char *inName)
19{
20 inRTTI.AddAttribute(SerializableAttribute(inName, inOffset,
21 []()
22 {
23 return GetPrimitiveTypeOfType((MemberType *)nullptr);
24 },
25 [](int inArrayDepth, EOSDataType inDataType, const char *inClassName)
26 {
27 return OSIsType((MemberType *)nullptr, inArrayDepth, inDataType, inClassName);
28 },
29 [](IObjectStreamIn &ioStream, void *inObject)
30 {
31 return OSReadData(ioStream, *reinterpret_cast<MemberType *>(inObject));
32 },
33 [](IObjectStreamOut &ioStream, const void *inObject)
34 {
35 OSWriteData(ioStream, *reinterpret_cast<const MemberType *>(inObject));
36 },
37 [](IObjectStreamOut &ioStream)
38 {
39 OSWriteDataType(ioStream, (MemberType *)nullptr);
40 }));
41}
42
43// JPH_ADD_ATTRIBUTE
44#define JPH_ADD_ATTRIBUTE_WITH_ALIAS(class_name, member_name, alias_name) \
45 AddSerializableAttributeTyped<decltype(class_name::member_name)>(inRTTI, offsetof(class_name, member_name), alias_name);
46
47// JPH_ADD_ATTRIBUTE
48#define JPH_ADD_ATTRIBUTE(class_name, member_name) \
49 JPH_ADD_ATTRIBUTE_WITH_ALIAS(class_name, member_name, #member_name)
50
unsigned int uint
Definition: Core.h:439
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
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 > *, int inArrayDepth, EOSDataType inDataType, const char *inClassName)
Definition: ObjectStream.h:123
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
void OSWriteDataType(IObjectStreamOut &ioStream, Array< T > *)
Definition: ObjectStream.h:234
EOSDataType
Data type.
Definition: SerializableAttribute.h:15
JPH_NAMESPACE_BEGIN void AddSerializableAttributeTyped(RTTI &inRTTI, uint inOffset, const char *inName)
Definition: SerializableAttributeTyped.h:18
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