![]() |
1.2.1
|
The macros contained here can be used to generate a new struct and a group of functions that provide a type-safe API to handle all kind of types. The functions are equivalent to using the ones defined in buffer.h but they are declared to hold a single type of data. Everything declared and defined by these macros are backed by nb_buffer structs and functions.
Usage
The recommended way of using these macros are as follows:
NAUGHTY_BUFFERS_ARRAY_DECLARATION macro: c file, include the int-array.h file and place the NAUGHTY_BUFFERS_ARRAY_DEFINITION macro: Generated code:
For array type T_array and data type T, the following is generated:
struct T_array { struct nb_buffer buffer; }void T_init(struct T_array *), analogous to nb_initvoid T_init_advanced(struct T_array *, nb_alloc_fn, nb_realloc_fn, nb_free_fn, nb_copy_fn, nb_move_fn, void *), analogous to nb_init_advanced;void T_push(struct T_array *, const T), analogous to nb_push but accepting a copy of the data of the argument. Most useful when the block size is at most sizeof(ptrdiff_t).void T_push_ptr(struct T_array *, const T *), analogous to nb_push and useful when the block size is greater than sizeof(ptrdiff_t).void T_assign(struct T_array *, size_t, const T), analogous to nb_assign but accepting a copy of the item as an argument. Most useful when the block size is at most sizeof(ptrdiff_t).void T_assign_ptr(struct T_array *, size_t, const T *), analogous to nb_assign and useful when the block size is greater than sizeof(ptrdiff_t).void T_insert(struct T_array *, size_t, const T), analogous to nb_insert but accepting a copy of the item as an argument. Most useful when the block size is at most sizeof(ptrdiff_t).void T_insert_ptr(struct T_array *, size_t, const T *), analogous to nb_insert and useful when the block size is greater than sizeof(ptrdiff_t).size_t T_count(struct T_array *), analogous to nb_block_countT T_at(struct T_array *, size_t), analogous to nb_at but returning a copy of the block in the array. Most useful when the block size is at most sizeof(ptrdiff_t).T * T_at(struct T_array *, size_t), analogous to nb_at but returning a pointer to the data directly in the array. Useful when the block size is greater than sizeof(ptrdiff_t).T T_front(struct T_array *), analogous to nb_front but returning a copy of the block in the array. Most useful when the block size is at most sizeof(ptrdiff_t).T * T_front_ptr(struct T_array *), analogous to nb_front but returning a pointer to the data directly in the array. Useful when the block size is greater than sizeof(ptrdiff_t).T T_back(struct T_array *), analogous to nb_back but returning a copy of the block in the array. Most useful when the block size is at most sizeof(ptrdiff_t).T * T_back_ptr(struct T_array *), analogous to nb_back but returning a pointer to the data directly in the array. Useful when the block size is greater than sizeof(ptrdiff_t).void T_remove_at(struct T *, size_t), analogous to nb_remove_at.void T_remove_back(struct T *), analogous to nb_remove_backvoid T_remove_front(struct T *), analogous to nb_remove_frontvoid T_sort(struct T *, nb_compare_fn), analogous to nb_sortvoid T_release(struct T *), analogous to nb_release