9#if defined(CVEC_OS_WIN32)
11# define CVEC_sys_strdup _strdup
13# ifdef _POSIX_C_SOURCE
14# undef _POSIX_C_SOURCE
16# define _POSIX_C_SOURCE 200809L
18# define CVEC_sys_strdup strdup
28#define CVEC_FAIL_ALLOCATION 2
29#define CVEC_FORCECAP_FAIL 3
30#define CVEC_ELEM_NOT_FOUND 4
31#define CVEC_GET_NULL 5
32#define CVEC_OUT_BOUNDS 6
33#define CVEC_NOT_ENOUGH_CAP 7
35#define __CVEC_CAP_ADDITION 1
37#define __CVEC_SET_NULL(vec, ptrSym) \
38 vec ptrSym size = 0; \
40 vec ptrSym elemLen = 0; \
41 vec ptrSym forceCap = false; \
42 vec ptrSym dynamicCap = false; \
43 vec ptrSym initialized = false \
270#define __CVEC_MACRO_MOD_CALL(func, vec, type, val) \
272 type _CVEC_TMP_X_VAR_ = val; \
273 int _CVEC_TMP_RETVAL_ = CVEC_NOT_ENOUGH_CAP; \
274 if (__cvec_hasEnoughCap(vec, 1)) \
275 _CVEC_TMP_RETVAL_ = func(vec, &_CVEC_TMP_X_VAR_); \
280#define cvec_push(vec, type, val) \
281 __CVEC_MACRO_MOD_CALL(__cvec_push, vec, type, val)
283#define cvec_pushFront(vec, type, val) \
284 __CVEC_MACRO_MOD_CALL(__cvec_pushFront, vec, type, val)
286#define cvec_pushIndex(vec, type, pos, val) \
288 type _CVEC_TMP_X_VAR_ = val; \
289 int _CVEC_TMP_RETVAL_; \
290 if (__cvec_hasEnoughCap(vec, 1)) \
291 _CVEC_TMP_RETVAL_ = __cvec_pushIndex(vec, pos, &_CVEC_TMP_X_VAR_); \
293 _CVEC_TMP_RETVAL_ = CVEC_NOT_ENOUGH_CAP; \
299#define cvec_set(vec, type, val, index) \
301 type _CVEC_TMP_X_VAR_ = val; \
302 int _CVEC_TMP_RETVAL_ = __cvec_set(vec, index, &_CVEC_TMP_X_VAR_); \
306#define cvec_delIndex(vec, type, val, index) \
308 type _CVEC_TMP_X_VAR_ = val; \
309 int _CVEC_TMP_RETVAL_ = __cvec_delIndex(vec, &_CVEC_TMP_X_VAR_, index); \
313#define cvec_del(vec, type, val) \
315 type _CVEC_TMP_X_VAR_ = val; \
316 int _CVEC_TMP_RETVAL_ = __cvec_del(vec, &_CVEC_TMP_X_VAR_); \
320#define cvec_find(vec, type, val) \
322 type _CVEC_TMP_X_VAR_ = val; \
323 int _CVEC_TMP_RETVAL_ = __cvec_find(vec, &_CVEC_TMP_X_VAR_); \
int cvec_reverse(CVEC *_vec)
Reverse the order of elements in place.
int cvec_popFront(CVEC *_vec)
Remove the first element, shifting all others left.
int cvec_remove(CVEC *_vec, const size_t _index)
Remove an element at a specific index.
void * cvec_get(const CVEC *_vec, const size_t _index)
Get a pointer to an element at specified index.
int __cvec_delIndex(CVEC *_vec, void *_elem, const size_t start)
Delete matching element starting search at index.
void cvec_swap(CVEC *_a, CVEC *_b)
Swap two CVEC instances.
int __cvec_set(CVEC *_vec, const size_t _index, void *_set)
Replace value at given index.
int cvec_merge(CVEC *_toMerge, const CVEC *_input)
Merge contents of _input vector into _toMerge.
int __cvec_pushIndex(CVEC *_vec, const size_t _index, void *_elem)
Insert element at specific index, shifting elements as needed.
int __cvec_find(const CVEC *_vec, void *_find)
Search for an element in the vector.
void cvec_clear(CVEC *_vec)
Clear vector contents but keep capacity unchanged.
CVEC cvec_initCopy(const CVEC *_src)
Create a deep copy of an existing CVEC.
CVEC cvec_init(int _cap, size_t _elemSize)
Initialize a new vector with requested capacity and element size.
bool __cvec_hasEnoughCap(const CVEC *_vec, const size_t _additions)
Check whether capacity is sufficient for requested additions.
int cvec_emptyAll(CVEC *_vec)
Clear all elements and reset size to zero without freeing memory.
int __cvec_del(CVEC *_vec, void *_elem)
Delete first occurrence of matching value.
int __cvec_pushFront(CVEC *_vec, void *_elem)
Insert new element at beginning.
bool cvec_at(const CVEC *_vec, const size_t _index)
Check whether element exists at index.
int __cvec_destroySplit(CVEC *_vec)
Cleanup after split operations.
int cvec_destroy(CVEC *_vec)
Destroy a CVEC, freeing allocated memory and invalidating the structure.
int __cvec_push(CVEC *_vec, void *_elem)
Insert at end of vector.
int cvec_shrink(CVEC *_vec)
Shrink allocated memory to match current size.
bool cvec_atCap(const CVEC *_vec, const size_t _index)
Check whether element exists within vector capacity.
int cvec_popBack(CVEC *_vec)
Remove the last element.
int cvec_split(CVEC *_vec, char *_str, const char *_del)
Split a string by delimiter and store parts inside CVEC.
Custom generic dynamic vector type.
size_t cap
Allocated storage capacity.
bool dynamicCap
Enables automatic capacity growth when true.
void * data
Pointer to contiguous allocated memory storing array elements.
bool forceCap
Prevents capacity expansion if true; insertion fails when full.
bool initialized
Tracks whether this CVEC has been properly initialized.
size_t size
Current number of stored items.
bool __usedSplit
Internal flag used by split operations.
size_t elemLen
Size in bytes of each element.