2#include <Foundation/IO/Stream.h>
7 return ReadObject(inout_stream, inout_obj,
nullptr);
14 inout_stream >> bIsRealObject;
16 PL_ASSERT_DEV(bIsRealObject,
"Reading an object inplace only works for the first occurrence");
18 PL_SUCCEED_OR_RETURN(plStreamReaderUtil::Deserialize<T>(inout_stream, obj));
29 inout_stream >> bIsRealObject;
33 ref_pObject = PL_NEW(pAllocator, T);
34 PL_SUCCEED_OR_RETURN(plStreamReaderUtil::Deserialize<T>(inout_stream, *ref_pObject));
41 inout_stream >> uiIndex;
45 ref_pObject =
static_cast<T*
>(m_Objects[uiIndex]);
47 else if (uiIndex == plInvalidIndex)
49 ref_pObject =
nullptr;
64 if (
ReadObject(inout_stream, ptr, pAllocator).Succeeded())
76 if (
ReadObject(inout_stream, ptr, pAllocator).Succeeded())
84template <
typename ArrayType,
typename ValueType>
90 PL_ASSERT_DEV(uiCount < std::numeric_limits<plUInt32>::max(),
"Containers currently use 32 bit for counts internally. Value from file is too large.");
96 static_cast<ArrayType&
>(ref_array).Reserve(
static_cast<plUInt32
>(uiCount));
98 for (plUInt32 i = 0; i < static_cast<plUInt32>(uiCount); ++i)
107template <
typename KeyType,
typename Comparer>
110 plUInt64 uiCount = 0;
113 PL_ASSERT_DEV(uiCount < std::numeric_limits<plUInt32>::max(),
"Containers currently use 32 bit for counts internally. Value from file is too large.");
117 for (plUInt32 i = 0; i < static_cast<plUInt32>(uiCount); ++i)
120 PL_SUCCEED_OR_RETURN(
ReadObject(inout_stream, key, pAllocator));
122 ref_set.
Insert(std::move(key));
134 template <
typename T>
135 static auto Deserialize(
plStreamReader& inout_stream, T& ref_obj,
int) ->
decltype(plStreamReaderUtil::Deserialize(inout_stream, ref_obj))
137 return plStreamReaderUtil::Deserialize(inout_stream, ref_obj);
140 template <
typename T>
143 PL_REPORT_FAILURE(
"No deserialize method available");
149template <
typename KeyType,
typename ValueType,
typename Comparer>
152 plUInt64 uiCount = 0;
155 PL_ASSERT_DEV(uiCount < std::numeric_limits<plUInt32>::max(),
"Containers currently use 32 bit for counts internally. Value from file is too large.");
159 if (mode == ReadMapMode::DedupKey)
161 for (plUInt32 i = 0; i < static_cast<plUInt32>(uiCount); ++i)
165 PL_SUCCEED_OR_RETURN(
ReadObject(inout_stream, key, pKeyAllocator));
166 PL_SUCCEED_OR_RETURN(plInternal::DeserializeHelper::Deserialize<ValueType>(inout_stream, value, 0));
168 ref_map.
Insert(std::move(key), std::move(value));
171 else if (mode == ReadMapMode::DedupValue)
173 for (plUInt32 i = 0; i < static_cast<plUInt32>(uiCount); ++i)
177 PL_SUCCEED_OR_RETURN(plInternal::DeserializeHelper::Deserialize<KeyType>(inout_stream, key, 0));
178 PL_SUCCEED_OR_RETURN(
ReadObject(inout_stream, value, pValueAllocator));
180 ref_map.
Insert(std::move(key), std::move(value));
185 for (plUInt32 i = 0; i < static_cast<plUInt32>(uiCount); ++i)
189 PL_SUCCEED_OR_RETURN(
ReadObject(inout_stream, key, pKeyAllocator));
190 PL_SUCCEED_OR_RETURN(
ReadObject(inout_stream, value, pValueAllocator));
192 ref_map.
Insert(std::move(key), std::move(value));
Base class for all memory allocators.
Definition Allocator.h:23
Base class for all array containers. Implements all the basic functionality that only requires a poin...
Definition ArrayBase.h:19
T & ExpandAndGetRef()
Grows the array by one element and returns a reference to the newly created element.
Definition ArrayBase_inl.h:310
void PushBack(const T &value)
Pushes value at the end of the array.
Definition ArrayBase_inl.h:333
void Clear()
Clears the array.
Definition ArrayBase_inl.h:184
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
plResult ReadObjectInplace(plStreamReader &inout_stream, T &ref_obj)
Reads a single object inplace.
plResult ReadMap(plStreamReader &inout_stream, plMapBase< KeyType, ValueType, Comparer > &ref_map, ReadMapMode mode, plAllocator *pKeyAllocator=plFoundation::GetDefaultAllocator(), plAllocator *pValueAllocator=plFoundation::GetDefaultAllocator())
Reads a map. Mode controls whether key or value or both should de-duplicated.
Definition DeduplicationReadContext_inl.h:150
plResult ReadObject(plStreamReader &inout_stream, T *&ref_pObject, plAllocator *pAllocator=plFoundation::GetDefaultAllocator())
Reads a single object and sets the pointer to it. The given allocator is used to create the object if...
Definition DeduplicationReadContext_inl.h:26
plResult ReadSet(plStreamReader &inout_stream, plSetBase< KeyType, Comparer > &ref_set, plAllocator *pAllocator=plFoundation::GetDefaultAllocator())
Reads a set of de-duplicated objects.
Definition DeduplicationReadContext_inl.h:108
plResult ReadArray(plStreamReader &inout_stream, plArrayBase< ValueType, ArrayType > &ref_array, plAllocator *pAllocator=plFoundation::GetDefaultAllocator())
Reads an array of de-duplicated objects.
Definition DeduplicationReadContext_inl.h:85
An associative container. Similar to STL::map.
Definition Map.h:193
void Clear()
Destroys all elements in the map and resets its size to zero.
Definition Map_inl.h:175
Iterator Insert(CompatibleKeyType &&key, CompatibleValueType &&value)
Inserts the key/value pair into the tree and returns an Iterator to it. O(log n) operation.
Definition Map_inl.h:535
A set container that only stores whether an element resides in it or not. Similar to STL::set.
Definition Set.h:13
void Clear()
Destroys all elements in the set and resets its size to zero.
Definition Set_inl.h:133
Iterator Insert(CompatibleKeyType &&key)
Inserts the key into the tree and returns an Iterator to it. O(log n) operation.
Definition Set_inl.h:351
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Interface for binary in (read) streams.
Definition Stream.h:22
plResult ReadQWordValue(T *pQWordValue)
Helper method to read a qword value correctly (copes with potentially different endianess)
Definition Stream_inl.h:107
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
Definition DeduplicationReadContext_inl.h:133
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54