42 lines
2.3 KiB
C
42 lines
2.3 KiB
C
#ifndef INCLUDE_WAYLANDCLIENT_DYNARRAY_H_
|
|
#define INCLUDE_WAYLANDCLIENT_DYNARRAY_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#define dyn_array_append(array, item) \
|
|
do { \
|
|
if ((array)->count >= (array)->capacity) { \
|
|
(array)->capacity += 10; \
|
|
(array)->items = realloc((array)->items, \
|
|
(array)->capacity * sizeof(*(array)->items)); \
|
|
} \
|
|
(array)->items[(array)->count++] = (item); \
|
|
} while (0)
|
|
#define dyn_array_remove(array, index) \
|
|
do { \
|
|
(array)->items[(index)] = (array)->items[(array)->count - 1]; \
|
|
(array)->items[(array)->count] = NULL; \
|
|
(array)->count--; \
|
|
} while (0)
|
|
#define dyn_array_destroy(array) free((array)->items)
|
|
#define dyn_array_reset(array) \
|
|
do { \
|
|
(array)->capacity = 10; \
|
|
(array)->count = 0; \
|
|
(array)->items = \
|
|
realloc((array)->items, (array)->capacity * sizeof(*(array)->items)); \
|
|
} while (0)
|
|
|
|
#define dyn_array_define($name, $type) \
|
|
struct $name { \
|
|
$type *items; \
|
|
int count; \
|
|
int capacity; \
|
|
}
|
|
|
|
dyn_array_define(da_uint32_t, uint32_t);
|
|
|
|
void *dyn_array_create();
|
|
void dyn_array_create_inplace(void *array);
|
|
|
|
#endif // INCLUDE_WAYLANDCLIENT_DYNARRAY_H_
|