Concord - C Discord API library
A Discord API wrapper library written in C
carray.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CARRAY_INITIAL_SIZE   4
 
#define CARRAY_RESIZE(current_size)    1 + current_size * 2
 
#define __carray_init(carray, length, _type, _compare, _free)
 
#define carray_init(carray, settings)    __carray_init(carray, CARRAY_INITIAL_SIZE, settings)
 
#define __carray_insert_handle_full(carray, index, value)
 
#define carray_insert(carray, index, value)
 
#define carray_pop(carray, index, location)
 
#define __carray_remove(carray, value, _type, _compare, _free)
 
#define carray_remove(carray, value, settings)    __carray_remove(carray, value, settings)
 
#define __carray_find(carray, value, location, _type, _compare, _free)
 
#define carray_find(carray, value, location, settings)    __carray_find(carray, value, location, settings)
 
#define __carray_free_array(carray)   free((carray)->array);
 
#define __carray_free(carray, _type, _compare, _free)
 
#define carray_free(carray, settings)    __carray_free(carray, settings)
 
#define __carray_append_handle_full(carray, value)
 
#define carray_append(carray, value)
 

Macro Definition Documentation

◆ CARRAY_INITIAL_SIZE

#define CARRAY_INITIAL_SIZE   4

◆ CARRAY_RESIZE

#define CARRAY_RESIZE (   current_size)     1 + current_size * 2

◆ __carray_init

#define __carray_init (   carray,
  length,
  _type,
  _compare,
  _free 
)
Value:
do { \
(carray)->realsize = length; \
(carray)->size = 0; \
(carray)->array = calloc(length, sizeof(_type)); \
} while (0)

◆ carray_init

#define carray_init (   carray,
  settings 
)     __carray_init(carray, CARRAY_INITIAL_SIZE, settings)

◆ __carray_insert_handle_full

#define __carray_insert_handle_full (   carray,
  index,
  value 
)
Value:
(carray)->realsize = CARRAY_RESIZE((carray)->realsize); \
(carray)->array = realloc((carray)->array, sizeof(*(carray)->array) * (size_t) (carray)->realsize)
#define CARRAY_RESIZE(current_size)
Definition: carray.h:72

◆ carray_insert

#define carray_insert (   carray,
  index,
  value 
)
Value:
if((carray)->size == (carray)->realsize) { \
__carray_insert_handle_full(carray, index, value); \
} \
\
if(index < 0 || index > (carray)->size) { \
fprintf(stderr, "carray_insert: attempt to insert at index %i, out of bounds of array '%s'. (%s:%i)\n", index, #carray, __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
\
memmove((carray)->array + index + 1, (carray)->array + index, sizeof(*(carray)->array) * (size_t) ((carray)->size - index)); \
(carray)->array[index] = value; \
(carray)->size++

◆ carray_pop

#define carray_pop (   carray,
  index,
  location 
)
Value:
location; \
\
if(index < 0 || index >= (carray)->size) { \
fprintf(stderr, "carray_pop: attempt to pop index %i, out of bounds of array '%s'. (%s:%i)\n", index, #carray, __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
\
(carray)->size--; \
(location) = (carray)->array[(index)]; \
memmove((carray)->array + index, (carray)->array + index + 1, sizeof(*(carray)->array) * (size_t) ((carray)->size - index))

◆ __carray_remove

#define __carray_remove (   carray,
  value,
  _type,
  _compare,
  _free 
)
Value:
do { \
int __CARRAY_ITER_INDEX = 0; \
\
for(__CARRAY_ITER_INDEX = 0; __CARRAY_ITER_INDEX < (carray)->size; __CARRAY_ITER_INDEX++) { \
_type __CARRAY_OPERAND_A = (carray)->array[__CARRAY_ITER_INDEX]; \
_type __CARRAY_OPERAND_B = value; \
\
if((_compare) == 0) \
continue; \
\
_free; \
(carray)->size--; \
memmove((carray)->array + __CARRAY_ITER_INDEX, \
(carray)->array + __CARRAY_ITER_INDEX + 1, \
sizeof(*(carray)->array) * (size_t) ((carray)->size - __CARRAY_ITER_INDEX)); \
\
__CARRAY_ITER_INDEX = -1; \
break; \
} \
\
if(__CARRAY_ITER_INDEX != -1) { \
fprintf(stderr, "carray_remove: attempt to remove value '%s' that is not in array '%s'. (%s:%i)\n", #value, #carray, __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
} while(0)

◆ carray_remove

#define carray_remove (   carray,
  value,
  settings 
)     __carray_remove(carray, value, settings)

◆ __carray_find

#define __carray_find (   carray,
  value,
  location,
  _type,
  _compare,
  _free 
)
Value:
-1; \
\
do { \
int __CARRAY_ITER_INDEX = 0; \
location = -1; \
\
for(__CARRAY_ITER_INDEX = 0; __CARRAY_ITER_INDEX < (carray)->size; __CARRAY_ITER_INDEX++) { \
_type __CARRAY_OPERAND_A = (carray)->array[__CARRAY_ITER_INDEX]; \
_type __CARRAY_OPERAND_B = value; \
\
if((_compare) == 0) \
continue; \
\
location = __CARRAY_ITER_INDEX; \
\
break; \
} \
} while(0)

◆ carray_find

#define carray_find (   carray,
  value,
  location,
  settings 
)     __carray_find(carray, value, location, settings)

◆ __carray_free_array

#define __carray_free_array (   carray)    free((carray)->array);

◆ __carray_free

#define __carray_free (   carray,
  _type,
  _compare,
  _free 
)
Value:
do { \
int __CARRAY_ITER_INDEX = 0; \
\
for(__CARRAY_ITER_INDEX = 0; __CARRAY_ITER_INDEX < (carray)->size; __CARRAY_ITER_INDEX++) { \
_type __CARRAY_OPERAND_A = (carray)->array[__CARRAY_ITER_INDEX]; \
(void) __CARRAY_OPERAND_A; \
\
_free; \
} \
} while(0)
#define __carray_free_array(carray)
Definition: carray.h:190

◆ carray_free

#define carray_free (   carray,
  settings 
)     __carray_free(carray, settings)

◆ __carray_append_handle_full

#define __carray_append_handle_full (   carray,
  value 
)
Value:
(carray)->realsize = CARRAY_RESIZE((carray)->realsize); \
(carray)->array = realloc((carray)->array, sizeof(*(carray)->array) * (size_t) (carray)->realsize)

◆ carray_append

#define carray_append (   carray,
  value 
)
Value:
if((carray)->size == (carray)->realsize) { \
__carray_append_handle_full(carray, value); \
} \
\
(carray)->array[(carray)->size] = value; \
(carray)->size++;