1#ifndef GIMBAL_BYTE_ARRAY_HPP
2#define GIMBAL_BYTE_ARRAY_HPP
6#include "../types/gimbal_typedefs.hpp"
7#include "../objects/gimbal_context.hpp"
13 ByteArray(Size bytes=0,
const void* pData=
nullptr);
23 bool operator==(
const ByteArray& rhs)
const;
24 bool operator!=(
const ByteArray& rhs)
const;
26 Size getSize(
void)
const;
27 template<
typename T=
void*>
28 T getData(
void)
const;
29 bool isEmpty(
void)
const;
30 Context* getContext(
void)
const;
33 void acquire(std::pair<Size,
void*> data);
34 auto release(
void) -> std::pair<Size,
void*>;
37 void readData(T* pOutData, Size offset=0, Size bytes=
sizeof(T))
const;
39 void writeData(
const T& pInData, Size offset=0, Size bytes=
sizeof(T));
41 void resize(Size bytes);
42 void grow(Size bytes);
43 void shrink(Size bytes);
45 void erase(Size offset, Size bytes);
48 void insert(
const T& dataIn, Size offset=0, Size bytes=
sizeof(T));
50 void append(
const T& dataIn, Size bytes=
sizeof(T));
52 void prepend(
const T& dataIn, Size bytes=
sizeof(T));
58inline ByteArray::ByteArray(Size bytes,
const void* pData) {
59 Exception::checkThrow(GblByteArray_construct(
this, bytes, pData));
64 Exception::checkThrow(GblByteArray_copy(
this, &other));
68 Exception::checkThrow(GblByteArray_move(
this, &other));
72 Exception::checkThrow(GblByteArray_destruct(
this));
76 GblCmpResult result = GblByteArray_compare(
this, &rhs);
81 return !(*
this == rhs);
86 Exception::checkThrow(GblByteArray_copy(
this, &other));
91 Exception::checkThrow(GblByteArray_move(
this, &other));
95inline Size
ByteArray::getSize(
void)
const {
104inline bool ByteArray::isEmpty(
void)
const {
105 return GblByteArray_isEmpty(
this);
109 Exception::checkThrow(GblByteArray_clear(
this));
112inline void ByteArray::acquire(std::pair<Size,
void*> data) {
113 Exception::checkThrow(GblByteArray_acquire(
this, data.first, data.second));
116inline auto ByteArray::release(
void) -> std::pair<Size,
void*> {
117 std::pair<Size,
void*> retVal;
118 Exception::checkThrow(GblByteArray_release(
this, &retVal.first, &retVal.second));
122inline void ByteArray::resize(Size bytes) {
123 Exception::checkThrow(GblByteArray_resize(
this, bytes));
127 Exception::checkThrow(GblByteArray_grow(
this, bytes));
130inline void ByteArray::shrink(Size bytes) {
131 Exception::checkThrow(GblByteArray_shrink(
this, bytes));
134inline void ByteArray::erase(Size offset, Size bytes) {
135 Exception::checkThrow(GblByteArray_erase(
this, offset, bytes));
139inline void ByteArray::insert(
const T& dataIn, Size offset, Size bytes) {
140 Exception::checkThrow(GblByteArray_insert(
this, offset, bytes, &dataIn));
144inline void ByteArray::append(
const T& dataIn, Size bytes) {
145 Exception::checkThrow(GblByteArray_append(
this, bytes, &dataIn));
149inline void ByteArray::prepend(
const T& dataIn, Size bytes) {
150 Exception::checkThrow(GblByteArray_prepend(
this, bytes, &dataIn));
153inline void ByteArray::readData(T* pOutData, Size offset, Size bytes)
const {
154 Exception::checkThrow(GblByteArray_dataRead(
this, offset, bytes, pOutData));
158inline void ByteArray::writeData(
const T& pInData, Size offset, Size bytes) {
159 Exception::checkThrow(GblByteArray_dataWrite(
this, offset, bytes, &pInData));
void * GblByteArray_data(const GblByteArray *pSelf)
Returns the data pointer of the GblByteArray (GblByteArray::pData)
size_t GblByteArray_size(const GblByteArray *pSelf)
Returns the size of the GblByteArray (GblByteArray::size)