6 #ifndef GIMBAL_VECTOR_H
7 #define GIMBAL_VECTOR_H
9 #include "../core/gimbal_api_frame.h"
10 #include "../algorithms/gimbal_numeric.h"
12 #define SELF GblVector* pSelf
13 #define CSELF const SELF
29 GBL_EXPORT GBL_RESULT GblVector_construct_6 (SELF,
32 const void* pInitialData,
35 GBL_INLINE GBL_RESULT GblVector_construct_5 (SELF,
38 const void* pInitialData,
39 GblSize structSize) GBL_NOEXCEPT;
40 GBL_INLINE GBL_RESULT GblVector_construct_4 (SELF,
43 const void* pInitialData) GBL_NOEXCEPT;
44 GBL_INLINE GBL_RESULT GblVector_construct_3 (SELF,
46 GblSize elementCount) GBL_NOEXCEPT;
47 GBL_INLINE GBL_RESULT GblVector_construct_2 (SELF,
48 uint16_t elementSize) GBL_NOEXCEPT;
49 #define GblVector_construct(...) \
50 GBL_VA_OVERLOAD_SELECT(GblVector_construct, GBL_VA_OVERLOAD_SUFFIXER_ARGC, __VA_ARGS__)(__VA_ARGS__)
51 #define GblVector_alloca(...) \
52 GBL_VA_OVERLOAD_SELECT(GBL_VECTOR_ALLOCA, GBL_VA_OVERLOAD_SUFFIXER_ARGC, __VA_ARGS__)(__VA_ARGS__)
54 GBL_EXPORT GBL_RESULT GblVector_destruct (SELF) GBL_NOEXCEPT;
55 GBL_EXPORT GBL_RESULT GblVector_assign (SELF,
const void* pData, GblSize elementCount) GBL_NOEXCEPT;
56 GBL_EXPORT GBL_RESULT GblVector_release (SELF,
void** ppVecPtr, GblSize* pSize, GblSize* pCapacity) GBL_NOEXCEPT;
57 GBL_EXPORT GBL_RESULT GblVector_acquire (SELF,
void* pData, GblSize size, GblSize capacity) GBL_NOEXCEPT;
59 GBL_INLINE
GblContext* GblVector_context (CSELF) GBL_NOEXCEPT;
60 GBL_INLINE uint16_t GblVector_stackBytes (CSELF) GBL_NOEXCEPT;
61 GBL_INLINE
void* GblVector_stackBuffer (CSELF) GBL_NOEXCEPT;
62 GBL_INLINE GblSize GblVector_size (CSELF) GBL_NOEXCEPT;
63 GBL_INLINE GblSize GblVector_capacity (CSELF) GBL_NOEXCEPT;
64 GBL_INLINE uint16_t GblVector_elementSize (CSELF) GBL_NOEXCEPT;
65 GBL_INLINE
void* GblVector_data (CSELF) GBL_NOEXCEPT;
67 GBL_INLINE GblBool GblVector_empty (CSELF) GBL_NOEXCEPT;
68 GBL_INLINE GblBool GblVector_stack (CSELF) GBL_NOEXCEPT;
70 GBL_INLINE
void* GblVector_at (CSELF, GblSize index) GBL_NOEXCEPT;
71 GBL_INLINE
void* GblVector_front (CSELF) GBL_NOEXCEPT;
72 GBL_INLINE
void* GblVector_back (CSELF) GBL_NOEXCEPT;
74 GBL_EXPORT
void* GblVector_insert (SELF, GblSize index, GblSize count,
const void* pData) GBL_NOEXCEPT;
75 GBL_INLINE GBL_RESULT GblVector_pushFront (SELF,
const void* pData) GBL_NOEXCEPT;
76 GBL_INLINE GBL_RESULT GblVector_pushBack (SELF,
const void* pData) GBL_NOEXCEPT;
77 GBL_EXPORT GBL_RESULT GblVector_append (SELF,
const void* pData, GblSize elementCount) GBL_NOEXCEPT;
78 GBL_EXPORT GBL_RESULT GblVector_prepend (SELF,
const void* pData, GblSize elementCount) GBL_NOEXCEPT;
80 GBL_EXPORT GBL_RESULT GblVector_popFront (SELF,
void* pOut) GBL_NOEXCEPT;
81 GBL_EXPORT GBL_RESULT GblVector_popBack (SELF,
void* pOut) GBL_NOEXCEPT;
83 GBL_EXPORT GBL_RESULT GblVector_erase (SELF, GblSize begin, GblSize count) GBL_NOEXCEPT;
84 GBL_EXPORT GBL_RESULT GblVector_clear (SELF) GBL_NOEXCEPT;
86 GBL_EXPORT GBL_RESULT GblVector_reserve (SELF, GblSize capacity) GBL_NOEXCEPT;
87 GBL_EXPORT GBL_RESULT GblVector_resize (SELF, GblSize size) GBL_NOEXCEPT;
88 GBL_EXPORT GBL_RESULT GblVector_shrinkToFit (SELF) GBL_NOEXCEPT;
93 #define GBL_VECTOR_ALLOCA_5(elemSize, elemCount, pData, size, pCtx) \
94 GblVector_createInPlace_(GBL_ALLOCA(size), elemSize, elemCount, pData, size, pCtx)
96 #define GBL_VECTOR_ALLOCA_4(elemSize, elemCount, pData, size) \
97 GBL_VECTOR_ALLOCA_5(elemSize, elemCount, pData, size, NULL)
99 #define GBL_VECTOR_ALLOCA_3(elemSize, elemCount, pData) \
100 GBL_VECTOR_ALLOCA_4(elemSize, elemCount, pData, 0)
102 #define GBL_VECTOR_ALLOCA_2(elemSize, elemCount) \
103 GBL_VECTOR_ALLOCA_3(elemSize, elemCount, NULL)
105 #define GBL_VECTOR_ALLOCA_1(elemSize) \
106 GBL_VECTOR_ALLOCA_2(elemSize, 0)
108 GBL_INLINE GblSize GBL_VECTOR_CAPACITY_FROM_SIZE_(GblSize size) GBL_NOEXCEPT {
109 return gblPow2Next(size);
113 GBL_INLINE
void* GblVector_stackBuffer(CSELF) GBL_NOEXCEPT {
114 return (uint8_t*)((pSelf && pSelf->stackSize)? (pSelf + 1) : NULL);
117 GBL_INLINE GblBool GblVector_empty(CSELF) GBL_NOEXCEPT {
118 return (pSelf && pSelf->size)? GBL_FALSE : GBL_TRUE;
121 GBL_INLINE GblBool GblVector_stack(CSELF) GBL_NOEXCEPT {
122 return (pSelf && (pSelf->pData == GblVector_stackBuffer(pSelf)))? GBL_TRUE : GBL_FALSE;
125 GBL_INLINE GBL_RESULT GblVector_construct_5(SELF, uint16_t elementSize, GblSize elementCount,
const void* pInitialData, GblSize structSize) GBL_NOEXCEPT {
126 return GblVector_construct_6(pSelf, elementSize, elementCount, pInitialData, structSize, NULL);
129 GBL_INLINE GBL_RESULT GblVector_construct_4(SELF, uint16_t elementSize, GblSize elementCount,
const void* pInitialData) GBL_NOEXCEPT {
130 return GblVector_construct_5(pSelf, elementSize, elementCount, pInitialData,
sizeof(
GblVector));
133 GBL_INLINE GBL_RESULT GblVector_construct_3(SELF, uint16_t elementSize, GblSize elementCount) GBL_NOEXCEPT {
134 return GblVector_construct_4(pSelf, elementSize, elementCount, NULL);
137 GBL_INLINE GBL_RESULT GblVector_construct_2(SELF, uint16_t elementSize) GBL_NOEXCEPT {
138 return GblVector_construct_3(pSelf, elementSize, 0);
141 GBL_INLINE
GblContext* GblVector_context(CSELF) GBL_NOEXCEPT {
142 return (pSelf)? pSelf->pCtx : NULL;
145 GBL_INLINE uint16_t GblVector_stackBytes(CSELF) GBL_NOEXCEPT {
146 return (pSelf)? pSelf->stackSize : 0;
149 GBL_INLINE GblSize GblVector_size(CSELF) GBL_NOEXCEPT {
150 return (pSelf)? pSelf->size : 0;
153 GBL_INLINE GblSize GblVector_capacity(CSELF) GBL_NOEXCEPT {
154 return (pSelf)? pSelf->capacity : 0;
157 GBL_INLINE uint16_t GblVector_elementSize(CSELF) GBL_NOEXCEPT {
158 return (pSelf)? pSelf->elementSize : 0;
161 GBL_INLINE
void* GblVector_data(CSELF) GBL_NOEXCEPT {
162 return (pSelf)? pSelf->pData : NULL;
165 GBL_INLINE
void* GblVector_at(CSELF, GblSize index) GBL_NOEXCEPT {
167 GBL_API_BEGIN(pSelf->pCtx);
168 GBL_API_VERIFY(index < pSelf->size,
169 GBL_RESULT_ERROR_OUT_OF_RANGE);
170 pData = &pSelf->pData[index * pSelf->elementSize];
175 GBL_INLINE
void* GblVector_front(CSELF) GBL_NOEXCEPT {
176 return GblVector_at(pSelf, 0);
179 GBL_INLINE
void* GblVector_back(CSELF) GBL_NOEXCEPT {
180 return GblVector_at(pSelf, pSelf->size-1);
183 GBL_INLINE GBL_RESULT GblVector_pushBack(SELF,
const void* pData) GBL_NOEXCEPT {
184 GBL_API_BEGIN(pSelf->pCtx);
185 GblVector_insert(pSelf, GblVector_size(pSelf), 1, pData);
186 GBL_API_VERIFY_LAST_RECORD();
190 GBL_INLINE GBL_RESULT GblVector_pushFront(SELF,
const void* pData) GBL_NOEXCEPT {
191 GBL_API_BEGIN(pSelf->pCtx);
192 GblVector_insert(pSelf, 0, 1, pData);
193 GBL_API_VERIFY_LAST_RECORD();
197 GBL_INLINE
GblVector* GblVector_createInPlace (SELF,
198 uint16_t elementSize,
199 GblSize elementCount,
200 const void* pInitialData,
206 GBL_API_VERIFY_CALL(GblVector_construct_6(pSelf, elementSize, elementCount, pInitialData, structSize, pCtx));
217 #endif // GIMBAL_VECTOR_H