A buffer holding binary data. More...
Public Member Functions | |
Buffer () noexcept | |
Buffer (unsigned long long size) noexcept | |
Buffer (const unsigned char *data, unsigned long long size) noexcept | |
Buffer (std::initializer_list< unsigned char > args) noexcept | |
Buffer (const Buffer &other) noexcept | |
Buffer (Buffer &&other) noexcept | |
~Buffer () | |
unsigned char * | getData () const |
unsigned long long | getSize () const |
bool | empty () const |
unsigned char & | front () |
const unsigned char & | front () const |
unsigned char & | back () |
const unsigned char & | back () const |
unsigned char * | begin () |
const unsigned char * | begin () const |
unsigned char * | end () |
const unsigned char * | end () const |
Buffer & | clear () |
Buffer & | resize (unsigned long long size) |
Buffer & | append (unsigned char value) |
Buffer & | erase (unsigned long long index, unsigned long long count=1ull) |
BufferDataDescriptor | relinquishDataOwnership () |
unsigned char & | operator[] (unsigned long long index) |
const unsigned char & | operator[] (unsigned long long index) const |
Buffer & | operator= (const Buffer &other) noexcept |
Buffer & | operator= (Buffer &&other) noexcept |
template<typename T , std::size_t S> | |
Buffer (const std::array< T, S > &array) noexcept | |
template<typename T > | |
Buffer (const std::vector< T > &vec) noexcept | |
Static Public Member Functions | |
static Buffer | createAndTakeMemory (unsigned char *data, unsigned long long size) |
A buffer holding binary data.
The Buffer class owns its memory, and is hard coded to handle binary data shaped as unsigned char. It is meant to manage all memory and operations in the DLL itself, meaning that passing one from user space to dll space is safe. This class will be the basis to safely exchange data with components. It avoids having to play with vectors that can be unsafe due to their build time template parameters.
If you need something else than unsigned char, take a look at the BufferCast template class. Its purpose is to use this class, with an API casting for you. For data that doesn't need to be copied, BufferView can be the answer as it is only meant to offer a bridge to the data.
|
noexcept |
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. As this buffer is binary, size is in bytes. |
|
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 bytes. |
|
noexcept |
Utility initializer list constructor.
args | The list of elements to initialize the buffer with. |
|
noexcept |
Copy constructor. Will duplicate the data.
other | The buffer to copy. |
|
noexcept |
Move constructor. Data will be moved into the buffer being constructed.
other | The buffer to move. |
nkMemory::Buffer::~Buffer | ( | ) |
Destructor. The destructor frees the memory, invalidating all potential pointers to it.
|
noexcept |
Utility copy constructor with arrays.
array | The array to copy from. |
|
noexcept |
Utility copy constructor with vectors.
vec | The vector to copy from. |
unsigned char* nkMemory::Buffer::getData | ( | ) | const |
unsigned long long nkMemory::Buffer::getSize | ( | ) | const |
bool nkMemory::Buffer::empty | ( | ) | const |
unsigned char& nkMemory::Buffer::front | ( | ) |
const unsigned char& nkMemory::Buffer::front | ( | ) | const |
unsigned char& nkMemory::Buffer::back | ( | ) |
const unsigned char& nkMemory::Buffer::back | ( | ) | const |
unsigned char* nkMemory::Buffer::begin | ( | ) |
const unsigned char* nkMemory::Buffer::begin | ( | ) | const |
unsigned char* nkMemory::Buffer::end | ( | ) |
const unsigned char* nkMemory::Buffer::end | ( | ) | const |
Buffer& nkMemory::Buffer::clear | ( | ) |
Clears the buffer, freeing its internal memory and resetting it to its empty state.
Buffer& nkMemory::Buffer::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 bytes. |
Buffer& nkMemory::Buffer::append | ( | unsigned char | value | ) |
Appends a byte to the buffer. This will cause the buffer to reallocate and copy data around.
value | The value of the byte to append. |
Buffer& nkMemory::Buffer::erase | ( | unsigned long long | index, |
unsigned long long | count = 1ull |
||
) |
Erases bytes from the buffer. This will cause the buffer to reallocate and copy remaining data around.
index | The starting index to erase data from. |
count | The number of bytes to erase. |
BufferDataDescriptor nkMemory::Buffer::relinquishDataOwnership | ( | ) |
Requests a buffer to abandon its ownership, leaving the management to the client using this function.
unsigned char& nkMemory::Buffer::operator[] | ( | unsigned long long | index | ) |
Indexing operator.
index | The index of the element to index in the memory. |
const unsigned char& nkMemory::Buffer::operator[] | ( | unsigned long long | index | ) | const |
Indexing operator, const versioned.
index | The index of the element to index in the memory. |
Copy assignment operator.
other | The buffer to copy. |
Move assignment operator.
other | The buffer to move. |
|
static |
Static creation function for which the buffer takes ownership of the memory provided. This means the buffer will free the memory given once it is destroyed (through the operator delete[]).
data | The data the buffer will free. |
size | The size, in bytes, of the data provided. |