7 #ifndef Fw_ExternalArray_HPP 8 #define Fw_ExternalArray_HPP 12 #include <type_traits> 26 static_assert(std::is_assignable<T&, T>::value,
"T must be assignable to T&");
41 : m_elements(elements), m_size(size) {}
68 FW_ASSERT(i < this->m_size, static_cast<FwAssertArgType>(i));
69 return this->m_elements[i];
77 FW_ASSERT(i < this->m_size, static_cast<FwAssertArgType>(i));
78 return this->m_elements[i];
115 FW_ASSERT((elements !=
nullptr) || (size == 0), static_cast<FwAssertArgType>(size));
116 if (elements == this->m_elements) {
121 this->releaseStorage();
122 this->m_elements = elements;
124 this->m_destroyElementsOnRelease =
false;
136 FW_ASSERT(reinterpret_cast<uintptr_t>(data.
bytes) %
alignof(T) == 0);
141 this->releaseStorage();
143 this->m_elements =
reinterpret_cast<T*
>(data.
bytes);
150 (void)
new (&this->m_elements[i]) T();
155 this->m_destroyElementsOnRelease =
true;
172 return size *
sizeof(T);
181 void releaseStorage() {
182 if ((this->m_elements !=
nullptr) && this->m_destroyElementsOnRelease) {
183 for (
FwSizeType i = 0; i < this->m_size; i++) {
184 this->m_elements[i].~T();
186 this->m_destroyElementsOnRelease =
false;
196 T* m_elements =
nullptr;
202 bool m_destroyElementsOnRelease =
false;
PlatformSizeType FwSizeType
~ExternalArray()
Destructor.
void setStorage(T *elements, FwSizeType size)
Set the backing storage (typed data)
ExternalArray()
Zero-argument constructor.
T & operator[](const FwSizeType i)
#define FW_MIN(a, b)
MIN macro (deprecated in C++, use std::min)
ExternalArray(const ExternalArray< T > &a)
Copy constructor.
ExternalArray(ByteArray data, FwSizeType size)
const T * getElements() const
A variable-length byte array.
void setStorage(ByteArray data, FwSizeType size)
ExternalArray(T *elements, FwSizeType size)
FwSizeType getSize() const
uint8_t U8
8-bit unsigned integer
void copyDataFrom(const ExternalArray< T > &a)
Copy the data from a.
U8 *const bytes
The bytes.
ExternalArray< T > & operator=(const ExternalArray< T > &a)
static constexpr U8 getByteArrayAlignment()
static constexpr FwSizeType getByteArraySize(FwSizeType size)
const T & operator[](const FwSizeType i) const
Implementation of malloc based allocator.
const FwSizeType size
The size.