2#include <Foundation/IO/Stream.h>
11 static const T* GetAddress(
const T& obj) {
return &obj; }
17 static const T* GetAddress(
const T* pObj) {
return pObj; }
30 return WriteObjectInternal(inout_stream, pObject.
Borrow());
36 return WriteObjectInternal(inout_stream, pObject.
Borrow());
39template <
typename ArrayType,
typename ValueType>
42 const plUInt64 uiCount = array.
GetCount();
45 for (plUInt32 i = 0; i < static_cast<plUInt32>(uiCount); ++i)
47 PL_SUCCEED_OR_RETURN(
WriteObject(inout_stream, array[i]));
53template <
typename KeyType,
typename Comparer>
56 const plUInt64 uiWriteSize = set.
GetCount();
59 for (
const auto& item : set)
61 PL_SUCCEED_OR_RETURN(
WriteObject(inout_stream, item));
67template <
typename KeyType,
typename ValueType,
typename Comparer>
70 const plUInt64 uiWriteSize = map.
GetCount();
73 if (mode == WriteMapMode::DedupKey)
75 for (
auto It = map.
GetIterator(); It.IsValid(); ++It)
77 PL_SUCCEED_OR_RETURN(
WriteObject(inout_stream, It.Key()));
78 PL_SUCCEED_OR_RETURN(plStreamWriterUtil::Serialize<ValueType>(inout_stream, It.Value()));
81 else if (mode == WriteMapMode::DedupValue)
83 for (
auto It = map.
GetIterator(); It.IsValid(); ++It)
85 PL_SUCCEED_OR_RETURN(plStreamWriterUtil::Serialize<KeyType>(inout_stream, It.Key()));
86 PL_SUCCEED_OR_RETURN(
WriteObject(inout_stream, It.Value()));
91 for (
auto It = map.
GetIterator(); It.IsValid(); ++It)
93 PL_SUCCEED_OR_RETURN(
WriteObject(inout_stream, It.Key()));
94 PL_SUCCEED_OR_RETURN(
WriteObject(inout_stream, It.Value()));
104 plUInt32 uiIndex = plInvalidIndex;
108 bool bIsRealObject = !m_Objects.
TryGetValue(pObject, uiIndex);
109 stream << bIsRealObject;
114 m_Objects.
Insert(pObject, uiIndex);
116 return plStreamWriterUtil::Serialize<T>(stream, *pObject);
126 stream << plInvalidIndex;
Base class for all array containers. Implements all the basic functionality that only requires a poin...
Definition ArrayBase.h:19
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
plResult WriteSet(plStreamWriter &inout_stream, const plSetBase< KeyType, Comparer > &set)
Writes a set of de-duplicated objects.
Definition DeduplicationWriteContext_inl.h:54
plResult WriteObject(plStreamWriter &inout_stream, const T &obj)
Writes a single object to the stream. Can be either a reference or a pointer to the object.
plResult WriteMap(plStreamWriter &inout_stream, const plMapBase< KeyType, ValueType, Comparer > &map, WriteMapMode mode)
Writes a map. Mode controls whether key or value or both should de-duplicated.
Definition DeduplicationWriteContext_inl.h:68
plResult WriteArray(plStreamWriter &inout_stream, const plArrayBase< ValueType, ArrayType > &array)
Writes an array of de-duplicated objects.
Definition DeduplicationWriteContext_inl.h:40
plUInt32 GetCount() const
Returns the number of active entries in the table.
Definition HashTable_inl.h:343
bool TryGetValue(const CompatibleKeyType &key, ValueType &out_value) const
Returns whether an entry with the given key was found and if found writes out the corresponding value...
bool Insert(CompatibleKeyType &&key, CompatibleValueType &&value, ValueType *out_pOldValue=nullptr)
Inserts the key value pair or replaces value if an entry with the given key already exists.
An associative container. Similar to STL::map.
Definition Map.h:193
plUInt32 GetCount() const
Returns the number of elements currently stored in the map. O(1) operation.
Definition Map_inl.h:200
Iterator GetIterator()
Returns an Iterator to the very first element.
Definition Map_inl.h:207
A set container that only stores whether an element resides in it or not. Similar to STL::set.
Definition Set.h:13
plUInt32 GetCount() const
Returns the number of elements currently stored in the set. O(1) operation.
Definition Set_inl.h:158
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
T * Borrow() const
Borrows the managed object. The shared ptr stays unmodified.
Definition SharedPtr_inl.h:168
Interface for binary out (write) streams.
Definition Stream.h:107
plResult WriteQWordValue(const T *pQWordValue)
Helper method to write a qword value correctly (copes with potentially different endianess)
Definition Stream_inl.h:134
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
T * Borrow() const
Borrows the managed object. The unique ptr stays unmodified.
Definition UniquePtr_inl.h:102
Definition DeduplicationWriteContext_inl.h:10
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54