4#include <Foundation/Basics.h>
5#include <Foundation/Types/ArrayPtr.h>
15 PL_DECLARE_POD_TYPE();
17 static_assert(!std::is_same_v<T, void>,
"plBlobPtr<void> is not allowed (anymore)");
18 static_assert(!std::is_same_v<T, const void>,
"plBlobPtr<void> is not allowed (anymore)");
20 using ByteType =
typename plArrayPtrDetail::ByteTypeHelper<T>::type;
22 using PointerType = T*;
34 if (m_pPtr ==
nullptr || m_uiCount == 0)
43 PL_ALWAYS_INLINE
plBlobPtr(ValueType (&staticArray)[N])
45 , m_uiCount(static_cast<plUInt64>(N))
51 : m_pPtr(other.m_pPtr)
52 , m_uiCount(other.m_uiCount)
62 m_pPtr = other.m_pPtr;
63 m_uiCount = other.m_uiCount;
73 PL_ALWAYS_INLINE
void operator=(std::nullptr_t)
80 PL_ALWAYS_INLINE PointerType
GetPtr()
const {
return m_pPtr; }
83 PL_ALWAYS_INLINE PointerType
GetPtr() {
return m_pPtr; }
86 PL_ALWAYS_INLINE PointerType
GetEndPtr() {
return m_pPtr + m_uiCount; }
89 PL_ALWAYS_INLINE PointerType
GetEndPtr()
const {
return m_pPtr + m_uiCount; }
95 PL_ALWAYS_INLINE plUInt64
GetCount()
const {
return m_uiCount; }
101 uiStart + uiCount <=
GetCount(),
"uiStart+uiCount ({0}) has to be smaller or equal than the count ({1}).", uiStart + uiCount,
GetCount());
109 PL_ASSERT_DEV(uiStart <=
GetCount(),
"uiStart ({0}) has to be smaller or equal than the count ({1}).", uiStart,
GetCount());
123 template <
typename U>
126 static_assert(
sizeof(T) ==
sizeof(U),
"Can only cast with equivalent element size.");
131 template <
typename U>
134 static_assert(
sizeof(T) ==
sizeof(U),
"Can only cast with equivalent element size.");
139 PL_FORCE_INLINE
const ValueType&
operator[](plUInt64 uiIndex)
const
141 PL_ASSERT_DEBUG(uiIndex <
GetCount(),
"Cannot access element {0}, the array only holds {1} elements.", uiIndex,
GetCount());
142 return *
static_cast<const ValueType*
>(
GetPtr() + uiIndex);
148 PL_ASSERT_DEBUG(uiIndex <
GetCount(),
"Cannot access element {0}, the array only holds {1} elements.", uiIndex,
GetCount());
149 return *
static_cast<ValueType*
>(
GetPtr() + uiIndex);
158 if (
GetPtr() == other.GetPtr())
167 return !(*
this == other);
184 using const_iterator =
const T*;
190 PointerType m_pPtr =
nullptr;
191 plUInt64 m_uiCount = 0u;
203PL_ALWAYS_INLINE
plBlobPtr<T> plMakeBlobPtr(T* pPtr, plUInt64 uiCount)
209template <
typename T, plUInt64 N>
210PL_ALWAYS_INLINE
plBlobPtr<T> plMakeBlobPtr(T (&staticArray)[N])
224PL_ALWAYS_INLINE
plByteBlobPtr plMakeByteBlobPtr(T* pPtr, plUInt32 uiCount)
226 return plByteBlobPtr(
reinterpret_cast<plUInt8*
>(pPtr), uiCount *
sizeof(T));
230PL_ALWAYS_INLINE
plByteBlobPtr plMakeByteBlobPtr(
void* pPtr, plUInt32 uiBytes)
232 return plByteBlobPtr(
reinterpret_cast<plUInt8*
>(pPtr), uiBytes);
236PL_ALWAYS_INLINE
plConstByteBlobPtr plMakeByteBlobPtr(
const void* pPtr, plUInt32 uiBytes)
244typename plBlobPtr<T>::iterator begin(
plBlobPtr<T>& in_container)
246 return in_container.
GetPtr();
250typename plBlobPtr<T>::const_iterator begin(
const plBlobPtr<T>& container)
252 return container.
GetPtr();
256typename plBlobPtr<T>::const_iterator cbegin(
const plBlobPtr<T>& container)
258 return container.
GetPtr();
280typename plBlobPtr<T>::iterator end(
plBlobPtr<T>& in_container)
286typename plBlobPtr<T>::const_iterator end(
const plBlobPtr<T>& container)
292typename plBlobPtr<T>::const_iterator cend(
const plBlobPtr<T>& container)
321 PL_DECLARE_MEM_RELOCATABLE_TYPE();
330 void operator=(
plBlob&& rhs);
337 void SetFrom(
const void* pSource, plUInt64 uiSize);
343 bool IsEmpty()
const;
346 void SetCountUninitialized(plUInt64 uiCount);
352 template <
typename T>
355 return plBlobPtr<T>(
static_cast<T*
>(m_pStorage), m_uiSize);
359 template <
typename T>
372 void* m_pStorage =
nullptr;
373 plUInt64 m_uiSize = 0;
plBlob allows to store simple binary data larger than 4GB. This storage class is used by plImage to a...
Definition Blob.h:319
plConstByteBlobPtr GetByteBlobPtr() const
Returns a blob pointer to the blob data, or an empty blob pointer if the blob is empty.
Definition Blob.h:369
plByteBlobPtr GetByteBlobPtr()
Returns a blob pointer to the blob data, or an empty blob pointer if the blob is empty.
Definition Blob.h:366
plBlobPtr< T > GetBlobPtr()
Returns a blob pointer to the blob data, or an empty blob pointer if the blob is empty.
Definition Blob.h:353
plBlobPtr< const T > GetBlobPtr() const
Returns a blob pointer to the blob data, or an empty blob pointer if the blob is empty.
Definition Blob.h:360
plBlob()
Default constructor. Does not allocate any memory.
This class encapsulates a blob's storage and it's size. It is recommended to use this class instead o...
Definition Blob.h:13
bool operator==(const plBlobPtr< const T > &other) const
Compares the two arrays for equality.
Definition Blob.h:153
PL_FORCE_INLINE ValueType & operator[](plUInt64 uiIndex)
Index access.
Definition Blob.h:146
PL_ALWAYS_INLINE plBlobPtr(ValueType(&staticArray)[N])
Initializes the plBlobPtr to encapsulate the given array.
Definition Blob.h:43
PL_ALWAYS_INLINE void Clear()
Clears the array.
Definition Blob.h:67
PL_FORCE_INLINE const ValueType & operator[](plUInt64 uiIndex) const
Index access.
Definition Blob.h:139
PL_ALWAYS_INLINE void operator=(const plBlobPtr< T > &other)
Copies the pointer and size of /a other. Does not allocate any data.
Definition Blob.h:60
PL_FORCE_INLINE plBlobPtr< T > GetSubArray(plUInt64 uiStart) const
Creates a sub-array from this array.
Definition Blob.h:107
PL_ALWAYS_INLINE plBlobPtr< ByteType > ToByteBlob()
Reinterprets this array as a byte array.
Definition Blob.h:120
void CopyFrom(const plBlobPtr< const T > &other)
Copies the data from other into this array. The arrays must have the exact same size.
Definition Blob.h:171
PL_ALWAYS_INLINE PointerType GetEndPtr()
Returns the pointer behind the last element of the array.
Definition Blob.h:86
PL_ALWAYS_INLINE plBlobPtr< const ByteType > ToByteBlob() const
Reinterprets this array as a byte array.
Definition Blob.h:114
PL_ALWAYS_INLINE plBlobPtr(const plBlobPtr< T > &other)
Initializes the plBlobPtr to be a copy of other. No memory is allocated or copied.
Definition Blob.h:50
PL_ALWAYS_INLINE bool operator!=(const plBlobPtr< const T > &other) const
Compares the two arrays for inequality.
Definition Blob.h:165
PL_ALWAYS_INLINE PointerType GetEndPtr() const
Returns the pointer behind the last element of the array.
Definition Blob.h:89
PL_ALWAYS_INLINE plBlobPtr< const U > Cast() const
Cast an BlobPtr to an BlobPtr to a different, but same size, type.
Definition Blob.h:132
PL_FORCE_INLINE plBlobPtr< T > GetSubArray(plUInt64 uiStart, plUInt64 uiCount) const
Creates a sub-array from this array.
Definition Blob.h:98
PL_ALWAYS_INLINE PointerType GetPtr() const
Returns the pointer to the array.
Definition Blob.h:80
PL_ALWAYS_INLINE PointerType GetPtr()
Returns the pointer to the array.
Definition Blob.h:83
plBlobPtr(U *pPtr, plUInt64 uiCount)
Initializes the plBlobPtr with the given pointer and number of elements. No memory is allocated or co...
Definition Blob.h:29
PL_ALWAYS_INLINE bool IsEmpty() const
Returns whether the array is empty.
Definition Blob.h:92
PL_ALWAYS_INLINE plBlobPtr< U > Cast()
Cast an BlobPtr to an BlobPtr to a different, but same size, type.
Definition Blob.h:124
PL_ALWAYS_INLINE plUInt64 GetCount() const
Returns the number of elements in the array.
Definition Blob.h:95
plBlobPtr()=default
Initializes the plBlobPtr to be empty.
static bool IsEqual(const T *a, const T *b, size_t uiCount=1)
Tests if objects of type T from pSource and pDestination are equal.
static void Copy(T *pDestination, const T *pSource, size_t uiCount=1)
Copies objects of type T from pSource to pDestination.
PL_ALWAYS_INLINE void Swap(T &ref_f1, T &ref_f2)
Swaps the values in the two variables f1 and f2.
Definition Math_inl.h:224
Base class for Pointer like reverse iterators.
Definition ArrayIterator.h:152
Non-Const class for Pointer like reverse iterators.
Definition ArrayIterator.h:216