62#include "impl/impl_buffer.h"
103#define ccc_buf_init(mem_ptr, any_type_name, alloc_fn, aux_data, capacity, \
105 ccc_impl_buf_init(mem_ptr, any_type_name, alloc_fn, aux_data, capacity, \
246#define ccc_buf_emplace_back(buf_ptr, type_compound_literal...) \
247 ccc_impl_buf_emplace_back(buf_ptr, type_compound_literal)
326#define ccc_buf_as(buf_ptr, type_name, index) \
327 ((type_name *)ccc_buf_at(buf_ptr, index))
347#define ccc_buf_back_as(buf_ptr, type_name) ((type_name *)ccc_buf_back(buf_ptr))
360#define ccc_buf_front_as(buf_ptr, type_name) \
361 ((type_name *)ccc_buf_front(buf_ptr))
401#define ccc_buf_emplace(buf_ptr, index, type_compound_literal...) \
402 ccc_impl_buf_emplace(buf_ptr, index, type_compound_literal)
633#ifdef BUFFER_USING_NAMESPACE_CCC
635# define buf_init(args...) ccc_buf_init(args)
636# define buf_alloc(args...) ccc_buf_alloc(args)
637# define buf_reserve(args...) ccc_buf_reserve(args)
638# define buf_copy(args...) ccc_buf_copy(args)
639# define buf_clear(args...) ccc_buf_clear(args)
640# define buf_clear_and_free(args...) ccc_buf_clear_and_free(args)
641# define buf_clear_and_free_reserve(args...) \
642 ccc_buf_clear_and_free_reserve(args)
643# define buf_count(args...) ccc_buf_count(args)
644# define buf_count_bytes(args...) ccc_buf_count_bytes(args)
645# define buf_size_plus(args...) ccc_buf_size_plus(args)
646# define buf_size_minus(args...) ccc_buf_size_minus(args)
647# define buf_size_set(args...) ccc_buf_size_set(args)
648# define buf_capacity(args...) ccc_buf_capacity(args)
649# define buf_capacity_bytes(args...) ccc_buf_capacity_bytes(args)
650# define buf_sizeof_type(args...) ccc_buf_sizeof_type(args)
651# define buf_i(args...) ccc_buf_i(args)
652# define buf_is_full(args...) ccc_buf_is_full(args)
653# define buf_is_empty(args...) ccc_buf_is_empty(args)
654# define buf_at(args...) ccc_buf_at(args)
655# define buf_as(args...) ccc_buf_as(args)
656# define buf_back(args...) ccc_buf_back(args)
657# define buf_back_as(args...) ccc_buf_back_as(args)
658# define buf_front(args...) ccc_buf_front(args)
659# define buf_front_as(args...) ccc_buf_front_as(args)
660# define buf_alloc_back(args...) ccc_buf_alloc_back(args)
661# define buf_emplace(args...) ccc_buf_emplace(args)
662# define buf_emplace_back(args...) ccc_buf_emplace_back(args)
663# define buf_push_back(args...) ccc_buf_push_back(args)
664# define buf_pop_back(args...) ccc_buf_pop_back(args)
665# define buf_pop_back_n(args...) ccc_buf_pop_back_n(args)
666# define buf_move(args...) ccc_buf_move(args)
667# define buf_swap(args...) ccc_buf_swap(args)
668# define buf_write(args...) ccc_buf_write(args)
669# define buf_erase(args...) ccc_buf_erase(args)
670# define buf_insert(args...) ccc_buf_insert(args)
671# define buf_begin(args...) ccc_buf_begin(args)
672# define buf_next(args...) ccc_buf_next(args)
673# define buf_end(args...) ccc_buf_end(args)
674# define buf_rbegin(args...) ccc_buf_rbegin(args)
675# define buf_rnext(args...) ccc_buf_rnext(args)
676# define buf_rend(args...) ccc_buf_rend(args)
677# 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_copy(ccc_buffer *dst, ccc_buffer const *src, ccc_any_alloc_fn *fn)
Copy the buf from src to newly initialized dst.
ccc_ucount ccc_buf_capacity_bytes(ccc_buffer const *buf)
Return the bytes in the buffer given the current capacity elements.
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_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.
ccc_ucount ccc_buf_count(ccc_buffer const *buf)
obtain the count of buffer active slots.
struct ccc_buffer ccc_buffer
A contiguous block of storage for elements of the same type.
Definition: buffer.h:74
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.
void * ccc_buf_move(ccc_buffer *buf, size_t dst, size_t src)
Move data at index src to dst according to capacity.
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.
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_ucount ccc_buf_count_bytes(ccc_buffer const *buf)
Return the bytes in the buffer given the current count of active elements.
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...
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.
ccc_result ccc_buf_swap(ccc_buffer *buf, void *tmp, size_t i, size_t j)
swap elements at i and j according to capacity of the bufer.
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