3#include <Foundation/Algorithm/Sorting.h>
4#include <Foundation/Math/Math.h>
5#include <Foundation/Types/ArrayPtr.h>
7#if PL_ENABLED(PL_INTEROP_STL_SPAN)
13# define plInvalidIndex 0xFFFFFFFF
17template <
typename T,
typename Derived>
43#if PL_DISABLED(PL_USE_CPP20_OPERATORS)
62 void SetCount(plUInt32 uiCount,
const T& fillValue);
65 template <
typename =
void>
85 void InsertAt(plUInt32 uiIndex,
const T& value);
88 void InsertAt(plUInt32 uiIndex, T&& value);
106 plUInt32
IndexOf(
const T& value, plUInt32 uiStartIndex = 0)
const;
109 plUInt32
LastIndexOf(
const T& value, plUInt32 uiStartIndex = plInvalidIndex)
const;
115 T*
ExpandBy(plUInt32 uiNumNewItems);
133 void PopBack(plUInt32 uiCountToRemove = 1);
142 template <
typename Comparer>
143 void Sort(
const Comparer& comparer);
169 using const_iterator =
const T*;
174#if PL_ENABLED(PL_INTEROP_STL_SPAN)
175 operator std::span<const T>()
const
180 operator std::span<T>()
185 std::span<T> GetSpan()
190 std::span<const T> GetSpan()
const
209template <
typename T,
typename Derived>
212 return ref_container.
GetData();
215template <
typename T,
typename Derived>
221template <
typename T,
typename Derived>
227template <
typename T,
typename Derived>
233template <
typename T,
typename Derived>
239template <
typename T,
typename Derived>
245template <
typename T,
typename Derived>
251template <
typename T,
typename Derived>
257template <
typename T,
typename Derived>
263template <
typename T,
typename Derived>
269template <
typename T,
typename Derived>
275template <
typename T,
typename Derived>
281#include <Foundation/Containers/Implementation/ArrayBase_inl.h>
Base class for all array containers. Implements all the basic functionality that only requires a poin...
Definition ArrayBase.h:19
~plArrayBase()
Destructor.
Definition ArrayBase_inl.h:6
bool Contains(const T &value) const
Checks whether the given value can be found in the array. O(n) complexity.
Definition ArrayBase_inl.h:191
T & ExpandAndGetRef()
Grows the array by one element and returns a reference to the newly created element.
Definition ArrayBase_inl.h:310
void RemoveAtAndCopy(plUInt32 uiIndex, plUInt32 uiNumElements=1)
Removes the element at index and fills the gap by shifting all following elements.
Definition ArrayBase_inl.h:253
const T & operator[](plUInt32 uiIndex) const
Returns the element at the given index. Does bounds checks in debug builds.
Definition ArrayBase_inl.h:92
void PushBack(const T &value)
Pushes value at the end of the array.
Definition ArrayBase_inl.h:333
T * GetData()
Returns a pointer to the array data, or nullptr if the array is empty.
Definition ArrayBase_inl.h:423
bool operator==(const plArrayBase< T, Derived > &rhs) const
Compares this array to another contiguous array type.
Definition ArrayBase_inl.h:60
void Sort()
Sort with default comparer.
Definition ArrayBase_inl.h:413
void Clear()
Clears the array.
Definition ArrayBase_inl.h:184
void InsertAt(plUInt32 uiIndex, const T &value)
Inserts value at index by shifting all following elements.
Definition ArrayBase_inl.h:197
plUInt32 m_uiCount
The number of elements used from the array.
Definition ArrayBase.h:203
void SetCountUninitialized(plUInt32 uiCount)
Resizes the array to have exactly uiCount elements. Extra elements might be uninitialized.
Definition ArrayBase_inl.h:155
void PushBackRange(const plArrayPtr< const T > &range)
Pushes all elements in range at the end of the array. Increases the capacity if necessary.
Definition ArrayBase_inl.h:369
void SetCount(plUInt32 uiCount)
Resizes the array to have exactly uiCount elements. Default constructs extra elements if the array is...
Definition ArrayBase_inl.h:106
plUInt32 m_uiCapacity
The number of elements which can be stored in the array without re-allocating.
Definition ArrayBase.h:206
plArrayBase()
Constructor.
void PopBack(plUInt32 uiCountToRemove=1)
Removes count elements from the end of the array.
Definition ArrayBase_inl.h:379
bool RemoveAndCopy(const T &value)
Removes the first occurrence of value and fills the gap by shifting all following elements.
Definition ArrayBase_inl.h:229
void EnsureCount(plUInt32 uiCount)
Ensures the container has at least uiCount elements. Ie. calls SetCount() if the container has fewer ...
Definition ArrayBase_inl.h:144
plUInt32 LastIndexOf(const T &value, plUInt32 uiStartIndex=plInvalidIndex) const
Searches for the last occurrence of the given value and returns its index or plInvalidIndex if not fo...
Definition ArrayBase_inl.h:297
T * ExpandBy(plUInt32 uiNumNewItems)
Expands the array by N new items and returns a pointer to the first new one.
Definition ArrayBase_inl.h:326
void InsertRange(const plArrayPtr< const T > &range, plUInt32 uiIndex)
Inserts all elements in the range starting at the given index, shifting the elements after the index.
Definition ArrayBase_inl.h:219
bool operator<(const plArrayBase< T, Derived > &rhs) const
Compares this array to another contiguous array type.
Definition ArrayBase_inl.h:69
void operator=(const plArrayPtr< const T > &rhs)
Copies the data from some other contiguous array into this one.
Definition ArrayBase_inl.h:13
T & PeekBack()
Returns the last element of the array.
Definition ArrayBase_inl.h:388
plArrayPtr< typename plArrayPtr< T >::ByteType > GetByteArrayPtr()
Returns a byte array pointer to the array data, or an empty array pointer if the array is empty.
Definition ArrayBase_inl.h:453
plUInt32 GetCapacity() const
Returns the reserved number of elements that the array can hold without reallocating.
Definition ArrayBase.h:167
bool RemoveAndSwap(const T &value)
Removes the first occurrence of value and fills the gap by swapping in the last element.
Definition ArrayBase_inl.h:241
void PushBackUnchecked(const T &value)
Pushes value at the end of the array. Does NOT ensure capacity.
Definition ArrayBase_inl.h:351
T * m_pElements
Element-type access to m_Data.
Definition ArrayBase.h:200
plUInt32 IndexOf(const T &value, plUInt32 uiStartIndex=0) const
Searches for the first occurrence of the given value and returns its index or plInvalidIndex if not f...
Definition ArrayBase_inl.h:284
bool IsEmpty() const
Returns true, if the array does not contain any elements.
Definition ArrayBase_inl.h:178
plArrayPtr< T > GetArrayPtr()
Returns an array pointer to the array data, or an empty array pointer if the array is empty.
Definition ArrayBase_inl.h:441
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
void RemoveAtAndSwap(plUInt32 uiIndex, plUInt32 uiNumElements=1)
Removes the element at index and fills the gap by swapping in the last element.
Definition ArrayBase_inl.h:264
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Base class for Pointer like reverse iterators.
Definition ArrayIterator.h:152
Non-Const class for Pointer like reverse iterators.
Definition ArrayIterator.h:216