libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_byte_array.hpp
1#ifndef GIMBAL_BYTE_ARRAY_HPP
2#define GIMBAL_BYTE_ARRAY_HPP
3
4#include <utility>
6#include "../types/gimbal_typedefs.hpp"
7#include "../objects/gimbal_context.hpp"
8
9namespace gimbal {
10
11class ByteArray: public GblByteArray {
12public:
13 ByteArray(Size bytes=0, const void* pData=nullptr);
14
15 ByteArray(const ByteArray& other);
16 ByteArray(ByteArray&& other);
17
18 ~ByteArray(void);
19
20 ByteArray& operator=(const ByteArray& other);
21 ByteArray& operator=(ByteArray&& other);
22
23 bool operator==(const ByteArray& rhs) const;
24 bool operator!=(const ByteArray& rhs) const;
25
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;
31
32 void clear(void);
33 void acquire(std::pair<Size, void*> data);
34 auto release(void) -> std::pair<Size, void*>;
35
36 template<typename T>
37 void readData(T* pOutData, Size offset=0, Size bytes=sizeof(T)) const;
38 template<typename T>
39 void writeData(const T& pInData, Size offset=0, Size bytes=sizeof(T));
40
41 void resize(Size bytes);
42 void grow(Size bytes);
43 void shrink(Size bytes);
44
45 void erase(Size offset, Size bytes);
46
47 template<typename T>
48 void insert(const T& dataIn, Size offset=0, Size bytes=sizeof(T));
49 template<typename T>
50 void append(const T& dataIn, Size bytes=sizeof(T));
51 template<typename T>
52 void prepend(const T& dataIn, Size bytes=sizeof(T));
53};
54
55
56
57// ======= IMPLEMENTATION =======
58inline ByteArray::ByteArray(Size bytes, const void* pData) {
59 Exception::checkThrow(GblByteArray_construct(this, bytes, pData));
60}
61
62
63inline ByteArray::ByteArray(const ByteArray& other) {
64 Exception::checkThrow(GblByteArray_copy(this, &other));
65}
66
67inline ByteArray::ByteArray(ByteArray&& other) {
68 Exception::checkThrow(GblByteArray_move(this, &other));
69}
70
71inline ByteArray::~ByteArray(void) {
72 Exception::checkThrow(GblByteArray_destruct(this));
73}
74
75inline bool ByteArray::operator==(const ByteArray& rhs) const {
76 GblCmpResult result = GblByteArray_compare(this, &rhs);
77 return !result;
78}
79
80inline bool ByteArray::operator!=(const ByteArray& rhs) const {
81 return !(*this == rhs);
82}
83
84
85inline ByteArray& ByteArray::operator=(const ByteArray& other) {
86 Exception::checkThrow(GblByteArray_copy(this, &other));
87 return *this;
88}
89
90inline ByteArray& ByteArray::operator=(ByteArray&& other) {
91 Exception::checkThrow(GblByteArray_move(this, &other));
92 return *this;
93}
94
95inline Size ByteArray::getSize(void) const {
96 return GblByteArray_size(this);
97}
98
99template<typename T>
100inline T ByteArray::getData(void) const {
101 return reinterpret_cast<T>(GblByteArray_data(this));
102}
103
104inline bool ByteArray::isEmpty(void) const {
105 return GblByteArray_isEmpty(this);
106}
107
108inline void ByteArray::clear(void) {
109 Exception::checkThrow(GblByteArray_clear(this));
110}
111
112inline void ByteArray::acquire(std::pair<Size, void*> data) {
113 Exception::checkThrow(GblByteArray_acquire(this, data.first, data.second));
114}
115
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));
119 return retVal;
120}
121
122inline void ByteArray::resize(Size bytes) {
123 Exception::checkThrow(GblByteArray_resize(this, bytes));
124}
125
126inline void ByteArray::grow(Size bytes) {
127 Exception::checkThrow(GblByteArray_grow(this, bytes));
128}
129
130inline void ByteArray::shrink(Size bytes) {
131 Exception::checkThrow(GblByteArray_shrink(this, bytes));
132}
133
134inline void ByteArray::erase(Size offset, Size bytes) {
135 Exception::checkThrow(GblByteArray_erase(this, offset, bytes));
136}
137
138template<typename T>
139inline void ByteArray::insert(const T& dataIn, Size offset, Size bytes) {
140 Exception::checkThrow(GblByteArray_insert(this, offset, bytes, &dataIn));
141}
142
143template<typename T>
144inline void ByteArray::append(const T& dataIn, Size bytes) {
145 Exception::checkThrow(GblByteArray_append(this, bytes, &dataIn));
146}
147
148template<typename T>
149inline void ByteArray::prepend(const T& dataIn, Size bytes) {
150 Exception::checkThrow(GblByteArray_prepend(this, bytes, &dataIn));
151}
152template<typename T>
153inline void ByteArray::readData(T* pOutData, Size offset, Size bytes) const {
154 Exception::checkThrow(GblByteArray_dataRead(this, offset, bytes, pOutData));
155}
156
157template<typename T>
158inline void ByteArray::writeData(const T& pInData, Size offset, Size bytes) {
159 Exception::checkThrow(GblByteArray_dataWrite(this, offset, bytes, &pInData));
160}
161
162
163
164}
165
166#endif // GIMBAL_ByteArray_HPP
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)