Holds a Buffer and make it easy to cast the binary data. More...
Public Member Functions | |
BufferCast () noexcept=default | |
BufferCast (unsigned long long size) noexcept | |
BufferCast (T *data, unsigned long long size) noexcept | |
BufferCast (const Buffer &buffer) noexcept | |
BufferCast (Buffer &&buffer) noexcept | |
BufferCast (const BufferCast &cast) noexcept | |
BufferCast (BufferCast &&cast) noexcept | |
template<typename U = T> | |
BufferCast (std::enable_if_t<!std::is_class_v< U >, const Buffer & > buffer) noexcept | |
~BufferCast () | |
T * | getData () const |
unsigned long long | getSize () const |
bool | empty () const |
T & | front () |
const T & | front () const |
T & | back () |
const T & | back () const |
T * | begin () |
const T * | begin () const |
T * | end () |
const T * | end () const |
BufferCast< T > & | clear () |
BufferCast< T > & | resize (unsigned long long size) |
T & | append (const T &value) |
template<typename U = T> | |
std::enable_if_t< std::is_class_v< U >, T & > | append (T &&value) |
BufferCast< T > & | erase (unsigned long long index, unsigned long long count=1ull) Buffer relinquishBufferOwnership() |
BufferCastDataDescriptor< T > | relinquishDataOwnership () |
T & | operator[] (unsigned long long index) |
const T & | operator[] (unsigned long long index) const |
BufferCast< T > & | operator= (const BufferCast< T > &other) noexcept |
template<typename U = T> | |
std::enable_if_t<!std::is_class_v< U >||std::is_move_assignable_v< U >, BufferCast< T > & > | operator= (BufferCast< T > &&other) noexcept |
template<std::size_t S> | |
BufferCast (const std::array< T, S > &array) noexcept | |
template<typename U , std::size_t S> | |
BufferCast (const std::array< U, S > &array) noexcept | |
BufferCast (const std::vector< T > &vec) noexcept | |
template<typename U > | |
BufferCast (const std::vector< U > &vec) noexcept | |
BufferCast (std::initializer_list< T > args) noexcept | |
BufferCast (std::initializer_list< U > args) noexcept | |
Holds a Buffer and make it easy to cast the binary data.
This class holds a binary Buffer and abstracts all casting needed when using a buffer to keep data that can be interpreted. This buffer cast owns the buffer, meaning that it also owns the memory allocated.
If you need a simple non-owning view over the data, consider looking at BufferView.
|
defaultnoexcept |
Default constructor. The buffer will be empty.
|
noexcept |
Size constructor. Will allocate the size requested within the buffer. Memory will be 0-cleared.
size | The size of the buffer to create, in number of elements. |
|
noexcept |
Data constructor. Will copy the data into its internal memory.
data | Pointer to the data to copy. |
size | The size of the data to copy, in number of elements. |
|
noexcept |
Copy buffer constructor. Will duplicate the data.
buffer | The buffer to copy. |
|
noexcept |
Move buffer constructor. Data will be moved into the buffer being constructed.
buffer | The buffer to move. |
|
noexcept |
Copy cast constructor. Will duplicate the data.
cast | The cast to copy. |
|
noexcept |
Move cast constructor. Data will be moved into the cast being constructed.
cast | The cast to move. |
|
noexcept |
Binary data copy constructor.
buffer | The buffer to copy and reinterpret the binary data from. |
nkMemory::BufferCast< T >::~BufferCast | ( | ) |
Destructor. The destructor frees the memory, invalidating all potential pointers to it. If T is a class needing destruction, then the destructor of each entry will get called.
|
noexcept |
Utility copy constructor with arrays.
array | The array to copy from. |
|
noexcept |
Utility copy constructor with arrays, which memory will be reinterpreted to another type.
array | The array to copy from. |
|
noexcept |
Utility copy constructor with vectors.
vec | The vector to copy from. |
|
noexcept |
Utility copy constructor with vectors, which memory will be reinterpreted to another type.
vec | The vector to copy from. |
|
noexcept |
Utility initializer list constructor.
args | The list of elements to initialize the buffer with. |
|
noexcept |
Utility initializer list constructor, which memory entries will get converted.
args | The list of elements to initialize the buffer with. |
T* nkMemory::BufferCast< T >::getData | ( | ) | const |
unsigned long long nkMemory::BufferCast< T >::getSize | ( | ) | const |
bool nkMemory::BufferCast< T >::empty | ( | ) | const |
T& nkMemory::BufferCast< T >::front | ( | ) |
const T& nkMemory::BufferCast< T >::front | ( | ) | const |
T& nkMemory::BufferCast< T >::back | ( | ) |
const T& nkMemory::BufferCast< T >::back | ( | ) | const |
T* nkMemory::BufferCast< T >::begin | ( | ) |
const T* nkMemory::BufferCast< T >::begin | ( | ) | const |
T* nkMemory::BufferCast< T >::end | ( | ) |
const T* nkMemory::BufferCast< T >::end | ( | ) | const |
BufferCast<T>& nkMemory::BufferCast< T >::clear | ( | ) |
Clears the buffer, freeing its internal memory and resetting it to its empty state.
BufferCast<T>& nkMemory::BufferCast< T >::resize | ( | unsigned long long | size | ) |
Resizes the buffer for it to fit a given size. This will trigger a reallocation of the data. In the process, the buffer will copy its content to the new memory area.
size | The size to fit, in number of elements. |
T& nkMemory::BufferCast< T >::append | ( | const T & | value | ) |
Appends an element to the buffer. This will cause the buffer to reallocate and copy data around.
value | The value to append. |
std::enable_if_t<std::is_class_v<U>, T&> nkMemory::BufferCast< T >::append | ( | T && | value | ) |
Appends an element to the buffer by moving it in. This will cause the buffer to reallocate and copy data around.
value | The value to append. |
BufferCast<T>& nkMemory::BufferCast< T >::erase | ( | unsigned long long | index, |
unsigned long long | count = 1ull |
||
) |
Erases a number of elements from the container.
index | The index at which the erasure should start. |
count | The number of elements to erase. |
BufferCastDataDescriptor<T> nkMemory::BufferCast< T >::relinquishDataOwnership | ( | ) |
Forwards the internal buffer's data ownership and memory.
T& nkMemory::BufferCast< T >::operator[] | ( | unsigned long long | index | ) |
Indexing operator.
index | The index of the element to index in the memory. |
const T& nkMemory::BufferCast< T >::operator[] | ( | unsigned long long | index | ) | const |
Indexing operator, const versioned.
index | The index of the element to index in the memory. |
|
noexcept |
Copy assignment operator.
other | The other buffer to copy from. |
|
noexcept |
Move assignment operator.
other | The other buffer to move from. |