53#include "impl/impl_buffer.h"
94#define ccc_buf_init(mem_ptr, any_type_name, alloc_fn, aux_data, capacity, \
96 ccc_impl_buf_init(mem_ptr, any_type_name, alloc_fn, aux_data, capacity, \
485#ifdef BUFFER_USING_NAMESPACE_CCC
487# define buf_init(args...) ccc_buf_init(args)
488# define buf_alloc(args...) ccc_buf_alloc(args)
489# define buf_reserve(args...) ccc_buf_reserve(args)
490# define buf_clear(args...) ccc_buf_clear(args)
491# define buf_clear_and_free(args...) ccc_buf_clear_and_free(args)
492# define buf_clear_and_free_reserve(args...) \
493 ccc_buf_clear_and_free_reserve(args)
494# define buf_size(args...) ccc_buf_size(args)
495# define buf_size_plus(args...) ccc_buf_size_plus(args)
496# define buf_size_minus(args...) ccc_buf_size_minus(args)
497# define buf_size_set(args...) ccc_buf_size_set(args)
498# define buf_capacity(args...) ccc_buf_capacity(args)
499# define buf_sizeof_type(args...) ccc_buf_sizeof_type(args)
500# define buf_i(args...) ccc_buf_i(args)
501# define buf_is_full(args...) ccc_buf_is_full(args)
502# define buf_is_empty(args...) ccc_buf_is_empty(args)
503# define buf_at(args...) ccc_buf_at(args)
504# define buf_back(args...) ccc_buf_back(args)
505# define buf_front(args...) ccc_buf_front(args)
506# define buf_alloc_back(args...) ccc_buf_alloc_back(args)
507# define buf_push_back(args...) ccc_buf_push_back(args)
508# define buf_pop_back(args...) ccc_buf_pop_back(args)
509# define buf_pop_back_n(args...) ccc_buf_pop_back_n(args)
510# define buf_copy(args...) ccc_buf_copy(args)
511# define buf_swap(args...) ccc_buf_swap(args)
512# define buf_write(args...) ccc_buf_write(args)
513# define buf_erase(args...) ccc_buf_erase(args)
514# define buf_insert(args...) ccc_buf_insert(args)
515# define buf_begin(args...) ccc_buf_begin(args)
516# define buf_next(args...) ccc_buf_next(args)
517# define buf_end(args...) ccc_buf_end(args)
518# define buf_rbegin(args...) ccc_buf_rbegin(args)
519# define buf_rnext(args...) ccc_buf_rnext(args)
520# define buf_rend(args...) ccc_buf_rend(args)
521# define buf_capacity_end(args...) ccc_buf_capacity_end(args)
ccc_ucount ccc_buf_i(ccc_buffer const *buf, void const *slot)
return the index of an element known to be in the buffer.
ccc_result ccc_buf_pop_back(ccc_buffer *buf)
pop the back element from the buffer according to size.
ccc_result ccc_buf_size_minus(ccc_buffer *buf, size_t n)
subtract n from the size of the buffer.
ccc_result ccc_buf_swap(ccc_buffer *buf, char tmp[], size_t i, size_t j)
swap elements at i and j according to capacity of the bufer.
ccc_result ccc_buf_clear_and_free(ccc_buffer *buf, ccc_any_type_destructor_fn *destructor)
Set size of buf to 0 and call destructor on each element if needed. Free the underlying buffer settin...
void * ccc_buf_alloc_back(ccc_buffer *buf)
allocates a new slot from the buffer at the end of the contiguous array. A slot is equivalent to one ...
ccc_tribool ccc_buf_is_empty(ccc_buffer const *buf)
return true if the size of the buffer is 0.
struct ccc_buffer ccc_buffer
A contiguous block of storage for elements of the same type.
Definition: buffer.h:65
ccc_tribool ccc_buf_is_full(ccc_buffer const *buf)
return true if the size of the buffer equals capacity.
ccc_result ccc_buf_size_set(ccc_buffer *buf, size_t n)
set the buffer size to n.
ccc_result ccc_buf_clear(ccc_buffer *buf, ccc_any_type_destructor_fn *destructor)
Set size of buf to 0 and call destructor on each element if needed. O(1) if no destructor is provided...
void * ccc_buf_rend(ccc_buffer const *buf)
return the rend position of the buffer.
void * ccc_buf_capacity_end(ccc_buffer const *buf)
return the end position of the buffer according to capacity.
ccc_ucount ccc_buf_sizeof_type(ccc_buffer const *buf)
the size of the type being stored contiguously in the buffer.
void * ccc_buf_at(ccc_buffer const *buf, size_t i)
return the element at slot i in buf.
void * ccc_buf_rnext(ccc_buffer const *buf, void const *iter)
advance the iter to the next slot in the buffer according to size and in reverse order.
void * ccc_buf_back(ccc_buffer const *buf)
return the final element in the buffer according the current size.
void * ccc_buf_next(ccc_buffer const *buf, void const *iter)
advance the iter to the next slot in the buffer according to size.
ccc_result ccc_buf_write(ccc_buffer *buf, size_t i, void const *data)
write data to buffer at slot at index i according to capacity.
ccc_result ccc_buf_size_plus(ccc_buffer *buf, size_t n)
add n to the size of the buffer.
void * ccc_buf_rbegin(ccc_buffer const *buf)
obtain the address of the last element in the buffer in preparation for iteration according to size.
ccc_result ccc_buf_reserve(ccc_buffer *buf, size_t to_add, ccc_any_alloc_fn *fn)
Reserves space for at least to_add more elements.
void * ccc_buf_end(ccc_buffer const *buf)
return the end position of the buffer according to size.
void * ccc_buf_copy(ccc_buffer *buf, size_t dst, size_t src)
copy data at index src to dst according to capacity.
ccc_ucount ccc_buf_capacity(ccc_buffer const *buf)
return the current capacity of total possible slots.
void * ccc_buf_front(ccc_buffer const *buf)
return the first element in the buffer at index 0.
void * ccc_buf_begin(ccc_buffer const *buf)
obtain the base address of the buffer in preparation for iteration.
ccc_result ccc_buf_erase(ccc_buffer *buf, size_t i)
erase element at slot i according to size of the buffer maintaining contiguous storage of elements be...
ccc_result ccc_buf_clear_and_free_reserve(ccc_buffer *buf, ccc_any_type_destructor_fn *destructor, ccc_any_alloc_fn *alloc)
Frees all slots in the buf and frees the underlying buffer that was previously dynamically reserved w...
ccc_ucount ccc_buf_size(ccc_buffer const *buf)
obtain the size of the buffer representing active slots.
void * ccc_buf_insert(ccc_buffer *buf, size_t i, void const *data)
insert data at slot i according to size of the buffer maintaining contiguous storage of elements betw...
ccc_result ccc_buf_pop_back_n(ccc_buffer *buf, size_t n)
pop n elements from the back of the buffer according to size.
ccc_result ccc_buf_alloc(ccc_buffer *buf, size_t capacity, ccc_any_alloc_fn *fn)
allocates the buffer to the specified size according to the user defined allocation function.
void * ccc_buf_push_back(ccc_buffer *buf, void const *data)
return the newly pushed data into the last slot of the buffer according to size.
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:187
The C Container Collection Fundamental Types.
void * ccc_any_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:312
ccc_result
A result of actions on containers.
Definition: types.h:132
ccc_tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:117
void ccc_any_type_destructor_fn(ccc_any_type)
A callback function for destroying an element in the container.
Definition: types.h:347