libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_array_list.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblArrayList structure and related functions
3 * \ingroup containers
4 *
5 * \author Falco Girgis
6 */
7
8#ifndef GIMBAL_ARRAY_LIST_H
9#define GIMBAL_ARRAY_LIST_H
10
11#include "../core/gimbal_ctx.h"
12
13#define GBL_SELF_TYPE GblArrayList
14
16
17/*! \brief Contiguous, array-based abstract list container with C++-style STL API
18 *
19 * GblArrayList is a C++ STL-style std::vector replacement as
20 * a general-purpose dynamic array with a few extra features:
21 *
22 * - Custom allocator support
23 * - Optional additional stack-based storage before overflowing to the heap
24 * - Optional zero termination
25 *
26 * \ingroup containers
27 * \sa GblRingBuffer, GblArrayDeque
28 */
29typedef struct GblArrayList { // Size (32-bit / 64-bit)
31 GblContext* pCtx; // 4/8 bytes
32 uint8_t* pData; // 4/8 bytes
33 size_t size; // 4/8 bytes
34 size_t capacity; // 4/8 bytes
35 uint16_t elementSize; // 2 bytes
36 uint16_t zeroTerminated: 1;
37 uint16_t stackCapacity: 15; // 2 bytes
39} GblArrayList; // 20/36 bytes
40
41GBL_EXPORT GBL_RESULT GblArrayList_construct_7 (GBL_SELF,
42 uint16_t elementSize,
43 size_t elementCount,
44 const void* pInitialData,
45 size_t structSize,
46 GblBool zeroTerminated,
47 GblContext* pCtx) GBL_NOEXCEPT;
48GBL_EXPORT GBL_RESULT GblArrayList_construct_6 (GBL_SELF,
49 uint16_t elementSize,
50 size_t elementCount,
51 const void* pInitialData,
52 size_t structSize,
53 GblBool zeroTerminated) GBL_NOEXCEPT;
54GBL_EXPORT GBL_RESULT GblArrayList_construct_5 (GBL_SELF,
55 uint16_t elementSize,
56 size_t elementCount,
57 const void* pInitialData,
58 size_t structSize) GBL_NOEXCEPT;
59GBL_EXPORT GBL_RESULT GblArrayList_construct_4 (GBL_SELF,
60 uint16_t elementSize,
61 size_t elementCount,
62 const void* pInitialData) GBL_NOEXCEPT;
63GBL_EXPORT GBL_RESULT GblArrayList_construct_3 (GBL_SELF,
64 uint16_t elementSize,
65 size_t elementCount) GBL_NOEXCEPT;
66GBL_EXPORT GBL_RESULT GblArrayList_construct_2 (GBL_SELF,
67 uint16_t elementSize) GBL_NOEXCEPT;
68#define GblArrayList_construct(...)
70#define GblArrayList_alloca(...)
71 GBL_VA_OVERLOAD_CALL_ARGC(GBL_ARRAY_LIST_ALLOCA, __VA_ARGS__)
72
73GBL_EXPORT GBL_RESULT GblArrayList_destruct (GBL_SELF) GBL_NOEXCEPT;
74GBL_EXPORT GBL_RESULT GblArrayList_assign (GBL_SELF, const void* pData, size_t elementCount) GBL_NOEXCEPT;
75GBL_EXPORT GBL_RESULT GblArrayList_release (GBL_SELF, void** ppData, size_t * pSize, size_t * pCapacity) GBL_NOEXCEPT;
76GBL_EXPORT GBL_RESULT GblArrayList_acquire (GBL_SELF, void* pData, size_t size, size_t capacity) GBL_NOEXCEPT;
77//GBL_EXPORT GBL_RESULT GblArrayList_swap(GBL_SELF, GblArrayList* pOther) GBL_NOEXCEPT;
78
79GBL_EXPORT GblContext* GblArrayList_context (GBL_CSELF) GBL_NOEXCEPT;
80GBL_EXPORT uint16_t GblArrayList_stackBytes (GBL_CSELF) GBL_NOEXCEPT;
81GBL_EXPORT void* GblArrayList_stackBuffer (GBL_CSELF) GBL_NOEXCEPT;
82GBL_EXPORT size_t GblArrayList_size (GBL_CSELF) GBL_NOEXCEPT;
83GBL_EXPORT size_t GblArrayList_capacity (GBL_CSELF) GBL_NOEXCEPT;
84GBL_EXPORT uint16_t GblArrayList_elementSize (GBL_CSELF) GBL_NOEXCEPT;
85GBL_EXPORT void* GblArrayList_data (GBL_CSELF) GBL_NOEXCEPT;
86
87GBL_EXPORT GblBool GblArrayList_empty (GBL_CSELF) GBL_NOEXCEPT;
88GBL_EXPORT GblBool GblArrayList_stack (GBL_CSELF) GBL_NOEXCEPT;
89
90GBL_EXPORT void* GblArrayList_at (GBL_CSELF, size_t index) GBL_NOEXCEPT;
91GBL_EXPORT void* GblArrayList_front (GBL_CSELF) GBL_NOEXCEPT;
92GBL_EXPORT void* GblArrayList_back (GBL_CSELF) GBL_NOEXCEPT;
93
94GBL_EXPORT void* GblArrayList_insert (GBL_SELF, size_t index, size_t count, const void* pData) GBL_NOEXCEPT;
95GBL_EXPORT void* GblArrayList_emplace (GBL_SELF, size_t index) GBL_NOEXCEPT;
96
97GBL_EXPORT GBL_RESULT GblArrayList_pushFront (GBL_SELF, const void* pData) GBL_NOEXCEPT;
98GBL_EXPORT void* GblArrayList_emplaceFront (GBL_SELF) GBL_NOEXCEPT;
99
100GBL_EXPORT GBL_RESULT GblArrayList_pushBack (GBL_SELF, const void* pData) GBL_NOEXCEPT;
101GBL_EXPORT void* GblArrayList_emplaceBack (GBL_SELF) GBL_NOEXCEPT;
102
103GBL_EXPORT GBL_RESULT GblArrayList_append (GBL_SELF, const void* pData, size_t elementCount) GBL_NOEXCEPT;
104GBL_EXPORT GBL_RESULT GblArrayList_prepend (GBL_SELF, const void* pData, size_t elementCount) GBL_NOEXCEPT;
105
106GBL_EXPORT GBL_RESULT GblArrayList_popFront (GBL_SELF, void* pOut) GBL_NOEXCEPT;
107GBL_EXPORT GBL_RESULT GblArrayList_popBack (GBL_SELF, void* pOut) GBL_NOEXCEPT;
108
109GBL_EXPORT GBL_RESULT GblArrayList_erase (GBL_SELF, size_t begin, size_t count) GBL_NOEXCEPT;
110GBL_EXPORT GBL_RESULT GblArrayList_clear (GBL_SELF) GBL_NOEXCEPT;
111
112GBL_EXPORT GBL_RESULT GblArrayList_reserve (GBL_SELF, size_t capacity) GBL_NOEXCEPT;
113GBL_EXPORT GBL_RESULT GblArrayList_resize (GBL_SELF, size_t size) GBL_NOEXCEPT;
114GBL_EXPORT GBL_RESULT GblArrayList_shrinkToFit (GBL_SELF) GBL_NOEXCEPT;
115
116// ========== IMPL ==========
117
118/// \cond
119#define GBL_ARRAY_LIST_ALLOCA_6(elemSize, elemCount, pData, size, zeroTerminated, pCtx)
120 GblArrayList_createInPlace_(GBL_ALLOCA(size), elemSize, elemCount, pData, size, zeroTerminated, pCtx)
121
122#define GBL_ARRAY_LIST_ALLOCA_5(elemSize, elemCount, pData, size, zeroTerminated)
123 GBL_ARRAY_LIST_ALLOCA_6(elemSize, elemCount, pData, size, zeroterminated, NULL)
124
125#define GBL_ARRAY_LIST_ALLOCA_4(elemSize, elemCount, pData, size)
126 GBL_ARRAY_LIST_ALLOCA_5(elemSize, elemCount, pData, size, GBL_FALSE)
127
128#define GBL_ARRAY_LIST_ALLOCA_3(elemSize, elemCount, pData)
129 GBL_ARRAY_LIST_ALLOCA_4(elemSize, elemCount, pData, 0)
130
131#define GBL_ARRAY_LIST_ALLOCA_2(elemSize, elemCount)
132 GBL_ARRAY_LIST_ALLOCA_3(elemSize, elemCount, NULL)
133
134#define GBL_ARRAY_LIST_ALLOCA_1(elemSize)
135 GBL_ARRAY_LIST_ALLOCA_2(elemSize, 0)
136/// \endcond
137
138#undef GBL_SELF_TYPE
139
141
142#endif // GIMBAL_ARRAY_LIST_H
#define GblArrayList_construct(...)
#define GBL_NOEXCEPT
#define GBL_ALLOCA
#define GBL_DECLS_BEGIN
#define GBL_PRIVATE_BEGIN
#define GBL_EXPORT
#define GBL_PRIVATE_END
Private data structure.
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
#define GBL_FALSE
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
Contiguous, array-based abstract list container with C++-style STL API.