These functions implement generic lists. They rely on 3 variables, sharing a common root. The trick that these macros rely on, is that the naming of these different variables is standard.
int foo_cap; int foo_len; <some type *>foo
These can be local variables, or members of a struct.
In all the functions below, we pass foo (or ‘bar->foo’, or ‘bar.foo’ etc), and foo_cap and foo_len are found by C preprocessor extending the name of the list.
#define fz_list(TYPE, NAME)
A macro to prettily instantiate a list.
Declare a list of entries of type ‘TYPE’ referred to by ‘NAME’.
#define fz_push_list(CTX, ELEM)
Push a new element onto a given list.
Returns a pointer to the new element.
#define fz_push_list_init(CTX, ELEM, INITIAL)
Push a new element onto a list, with a suggested initial size for the list.
Returns a pointer to the new element.
#define fz_extend_list(CTX, ELEM, N)
Push n new elements onto a list.
Returns a pointer to the first new element.
#define fz_extend_list_init(CTX, ELEM, N, INITIAL)
Push n new elements onto a list, with a suggested initial size.
Returns a pointer to the first new element.
#define fz_extend_list_tight(CTX, ELEM, N)
Push n new elements onto a list, never growing the list further than it needs to be.
Returns a pointer to the first new element.
#define fz_trim_list(CTX, ELEM)
Trim the storage for a list to remove any excess.
void *
fz_push_list_imp (
fz_context *ctx,
void **list,
int *list_len,
int *list_cap,
size_t z,
int initial
)
Functions used to implement the above macros.
void *
fz_extend_list_imp (
fz_context *ctx,
void **list,
int *list_len,
int *list_cap,
size_t z,
int n,
int initial
)
void *
fz_extend_list_tight_imp (
fz_context *ctx,
void **list,
int *list_len,
int *list_cap,
size_t z,
int n
)
void
fz_trim_list_imp (
fz_context *ctx,
void **list,
int list_len,
int *list_cap,
size_t z
)