Plasma Engine  2.0
Loading...
Searching...
No Matches
StaticArray.h
1#pragma once
2
3#include <Foundation/Containers/ArrayBase.h>
4
11template <typename T, plUInt32 Capacity>
12class plStaticArray : public plArrayBase<T, plStaticArray<T, Capacity>>
13{
14public:
15 // Only if the stored type is either POD or relocatable the hybrid array itself is also relocatable.
16 PL_DECLARE_MEM_RELOCATABLE_TYPE_CONDITIONAL(T);
17
19 plStaticArray(); // [tested]
20
23
25 template <plUInt32 OtherCapacity>
26 plStaticArray(const plStaticArray<T, OtherCapacity>& rhs); // [tested]
27
29 explicit plStaticArray(const plArrayPtr<const T>& rhs); // [tested]
30
32 ~plStaticArray(); // [tested]
33
35 void operator=(const plStaticArray<T, Capacity>& rhs); // [tested]
36
38 template <plUInt32 OtherCapacity>
39 void operator=(const plStaticArray<T, OtherCapacity>& rhs); // [tested]
40
42 void operator=(const plArrayPtr<const T>& rhs); // [tested]
43
45 void Reserve(plUInt32 uiCapacity);
46
47protected:
48 T* GetElementsPtr();
49 const T* GetElementsPtr() const;
50 friend class plArrayBase<T, plStaticArray<T, Capacity>>;
51
52private:
53 T* GetStaticArray();
54 const T* GetStaticArray() const;
55
57 struct alignas(PL_ALIGNMENT_OF(T))
58 {
59 plUInt8 m_Data[Capacity * sizeof(T)];
60 };
61
62 friend class plArrayBase<T, plStaticArray<T, Capacity>>;
63};
64
65// TODO static_assert with a ',' in the expression does not work
66// static_assert(plGetTypeClass< plStaticArray<int, 4> >::value == 2, "static array is not memory relocatable");
67
68#include <Foundation/Containers/Implementation/StaticArray_inl.h>
Base class for all array containers. Implements all the basic functionality that only requires a poin...
Definition ArrayBase.h:19
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Wraps a C-style array, which has a fixed size at compile-time, with a more convenient interface.
Definition StaticArray.h:13
void Reserve(plUInt32 uiCapacity)
For the static array Reserve is a no-op. However the function checks if the requested capacity is bel...
Definition StaticArray_inl.h:58
plStaticArray(const plStaticArray< T, Capacity > &rhs)
Creates a copy of the given array.
plStaticArray()
Creates an empty array.
Definition StaticArray_inl.h:3
~plStaticArray()
Destroys all objects.
Definition StaticArray_inl.h:39
void operator=(const plStaticArray< T, OtherCapacity > &rhs)
Copies the data from some other contiguous array into this one.
void operator=(const plStaticArray< T, Capacity > &rhs)
Copies the data from some other contiguous array into this one.