34 result.
SetError(
"Failed to read type hash");
42 result.
SetError(
"Failed to create instance of type");
48 (
object->*inRestoreBinaryStateFunction)(inStream);
51 result.
SetError(
"Failed to restore object");
63 if (ioObjectToIDMap ==
nullptr || inObject ==
nullptr)
71 if (
id != ioObjectToIDMap->end())
74 inStream.
Write(id->second);
80 (*ioObjectToIDMap)[inObject] = new_id;
81 inStream.
Write(new_id);
84 inObject->SaveBinaryState(inStream);
107 if (
id >= ioIDToObjectMap.
size())
110 result = Type::sRestoreFromBinaryState(inStream);
119 result.
Set(ioIDToObjectMap[
id].GetPtr());
126template <
class ArrayType,
class ValueType>
131 for (
const ValueType *value: inArray)
136template <
class ArrayType,
class ValueType>
145 result.
SetError(
"Failed to read stream");
151 for (
size_t i = 0; i < len; ++i)
159 values.push_back(std::move(value.
Get()));
#define JPH_NAMESPACE_END
Definition: Core.h:378
std::uint32_t uint32
Definition: Core.h:455
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
std::unordered_map< Key, T, Hash, KeyEqual, STLAllocator< pair< const Key, T > > > UnorderedMap
Definition: UnorderedMap.h:13
size_type size() const
Returns amount of elements in the array.
Definition: Array.h:318
void push_back(const T &inValue)
Add element to the back of the array.
Definition: Array.h:275
const RTTI * Find(const char *inName)
Find type info for a specific class by name.
Definition: Factory.cpp:19
static Factory * sInstance
Singleton factory instance.
Definition: Factory.h:40
void * CreateObject() const
Create an object of this type (returns nullptr if the object is abstract)
Definition: RTTI.cpp:53
Definition: Reference.h:107
Helper class that either contains a valid result or an error.
Definition: Result.h:12
void SetError(const char *inError)
Set an error value.
Definition: Result.h:152
void Set(const Type &inResult)
Set the result value.
Definition: Result.h:140
bool HasError() const
Check if we had an error.
Definition: Result.h:146
const String & GetError() const
Get the error value.
Definition: Result.h:149
const Type & Get() const
Get the result value.
Definition: Result.h:137
Simple binary input stream.
Definition: StreamIn.h:13
void Read(T &outT)
Read a primitive (e.g. float, int, etc.) from the binary stream.
Definition: StreamIn.h:29
virtual bool IsEOF() const =0
Returns true when an attempt has been made to read past the end of the file.
virtual bool IsFailed() const =0
Returns true if there was an IO failure.
Simple binary output stream.
Definition: StreamOut.h:13
void Write(const T &inT)
Write a primitive (e.g. float, int, etc.) to the binary stream.
Definition: StreamOut.h:26
Definition: StreamUtils.h:15
Result< ArrayType > RestoreObjectArray(StreamIn &inStream, IDToObjectMap< ValueType > &ioIDToObjectMap)
Definition: StreamUtils.h:137
Result< Ref< Type > > RestoreObject(StreamIn &inStream, void(Type::*inRestoreBinaryStateFunction)(StreamIn &))
Definition: StreamUtils.h:25
Result< Ref< Type > > RestoreObjectReference(StreamIn &inStream, IDToObjectMap< Type > &ioIDToObjectMap)
Restore an object reference from stream.
Definition: StreamUtils.h:91
void SaveObjectArray(StreamOut &inStream, const ArrayType &inArray, ObjectToIDMap< ValueType > *ioObjectToIDMap)
Definition: StreamUtils.h:127
UnorderedMap< const Type *, uint32 > ObjectToIDMap
Definition: StreamUtils.h:18
void SaveObjectReference(StreamOut &inStream, const Type *inObject, ObjectToIDMap< Type > *ioObjectToIDMap)
Save an object reference to a stream. Uses a map to map objects to IDs which is also used to prevent ...
Definition: StreamUtils.h:61