C Container Collection (CCC)
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1
54#ifndef CCC_BUFFER_H
55#define CCC_BUFFER_H
56
58#include <stddef.h>
61#include "private/private_buffer.h"
62#include "types.h"
63
73typedef struct CCC_Buffer CCC_Buffer;
74
117#define CCC_buffer_initialize(data_pointer, type_name, allocate, context_data, \
118 capacity, optional_count...) \
119 CCC_private_buffer_initialize(data_pointer, type_name, allocate, \
120 context_data, capacity, optional_count)
121
167#define CCC_buffer_from(allocate, context_data, optional_capacity, \
168 compound_literal_array...) \
169 CCC_private_buffer_from(allocate, context_data, optional_capacity, \
170 compound_literal_array)
171
196#define CCC_buffer_with_capacity(type_name, allocate, context_data, capacity) \
197 CCC_private_buffer_with_capacity(type_name, allocate, context_data, \
198 capacity)
199
219#define CCC_buffer_with_compound_literal(count, compound_literal_array...) \
220 CCC_private_buffer_with_compound_literal(count, compound_literal_array)
221
246#define CCC_buffer_with_context_compound_literal(context, count, \
247 compound_literal_array...) \
248 CCC_private_buffer_with_context_compound_literal(context, count, \
249 compound_literal_array)
250
267[[nodiscard]] CCC_Result CCC_buffer_reserve(CCC_Buffer *buffer, size_t to_add,
269
331[[nodiscard]] CCC_Result CCC_buffer_copy(CCC_Buffer *destination,
332 CCC_Buffer const *source,
334
355 size_t capacity,
357
369[[nodiscard]] void *CCC_buffer_allocate_back(CCC_Buffer *buffer);
370
383[[nodiscard]] void *CCC_buffer_push_back(CCC_Buffer *buffer, void const *data);
384
394#define CCC_buffer_emplace_back(buffer_pointer, type_compound_literal...) \
395 CCC_private_buffer_emplace_back(buffer_pointer, type_compound_literal)
396
411[[nodiscard]] void *CCC_buffer_insert(CCC_Buffer *buffer, size_t index,
412 void const *data);
413
420
430
443
462[[nodiscard]] void *CCC_buffer_at(CCC_Buffer const *buffer, size_t index);
463
475#define CCC_buffer_as(buffer_pointer, type_name, index) \
476 ((type_name *)CCC_buffer_at(buffer_pointer, index))
477
483[[nodiscard]] CCC_Count CCC_buffer_index(CCC_Buffer const *buffer,
484 void const *slot);
485
490[[nodiscard]] void *CCC_buffer_back(CCC_Buffer const *buffer);
491
497#define CCC_buffer_back_as(buffer_pointer, type_name) \
498 ((type_name *)CCC_buffer_back(buffer_pointer))
499
504[[nodiscard]] void *CCC_buffer_front(CCC_Buffer const *buffer);
505
511#define CCC_buffer_front_as(buffer_pointer, type_name) \
512 ((type_name *)CCC_buffer_front(buffer_pointer))
513
524void *CCC_buffer_move(CCC_Buffer *buffer, size_t destination, size_t source);
525
539CCC_Result CCC_buffer_write(CCC_Buffer *buffer, size_t index, void const *data);
540
552#define CCC_buffer_emplace(buffer_pointer, index, type_compound_literal...) \
553 CCC_private_buffer_emplace(buffer_pointer, index, type_compound_literal)
554
570CCC_Result CCC_buffer_swap(CCC_Buffer *buffer, void *temp, size_t index,
571 size_t swap_index);
572
584[[nodiscard]] void *CCC_buffer_begin(CCC_Buffer const *buffer);
585
591[[nodiscard]] void *CCC_buffer_next(CCC_Buffer const *buffer,
592 void const *iterator);
593
601[[nodiscard]] void *CCC_buffer_end(CCC_Buffer const *buffer);
602
611[[nodiscard]] void *CCC_buffer_capacity_end(CCC_Buffer const *buffer);
612
619[[nodiscard]] void *CCC_buffer_reverse_begin(CCC_Buffer const *buffer);
620
627[[nodiscard]] void *CCC_buffer_reverse_next(CCC_Buffer const *buffer,
628 void const *iterator);
629
635[[nodiscard]] void *CCC_buffer_reverse_end(CCC_Buffer const *buffer);
636
652
662
672
679[[nodiscard]] CCC_Count CCC_buffer_count(CCC_Buffer const *buffer);
680
686[[nodiscard]] CCC_Count CCC_buffer_capacity(CCC_Buffer const *buffer);
687
692[[nodiscard]] CCC_Count CCC_buffer_sizeof_type(CCC_Buffer const *buffer);
693
701[[nodiscard]] CCC_Count CCC_buffer_count_bytes(CCC_Buffer const *buffer);
702
709[[nodiscard]] CCC_Count CCC_buffer_capacity_bytes(CCC_Buffer const *buffer);
710
714[[nodiscard]] CCC_Tribool CCC_buffer_is_empty(CCC_Buffer const *buffer);
715
719[[nodiscard]] CCC_Tribool CCC_buffer_is_full(CCC_Buffer const *buffer);
720
756 CCC_Type_destructor *destroy,
758
770 CCC_Type_destructor *destroy);
771
782
788#ifdef BUFFER_USING_NAMESPACE_CCC
789typedef CCC_Buffer Buffer;
790# define buffer_initialize(args...) CCC_buffer_initialize(args)
791# define buffer_with_compound_literal(args...) \
792 CCC_buffer_with_compound_literal(args)
793# define buffer_with_context_compound_literal(args...) \
794 CCC_buffer_with_context_compound_literal(args)
795# define buffer_with_capacity(args...) CCC_buffer_with_capacity(args)
796# define buffer_from(args...) CCC_buffer_from(args)
797# define buffer_allocate(args...) CCC_buffer_allocate(args)
798# define buffer_reserve(args...) CCC_buffer_reserve(args)
799# define buffer_copy(args...) CCC_buffer_copy(args)
800# define buffer_clear(args...) CCC_buffer_clear(args)
801# define buffer_clear_and_free(args...) CCC_buffer_clear_and_free(args)
802# define buffer_clear_and_free_reserve(args...) \
803 CCC_buffer_clear_and_free_reserve(args)
804# define buffer_count(args...) CCC_buffer_count(args)
805# define buffer_count_bytes(args...) CCC_buffer_count_bytes(args)
806# define buffer_size_plus(args...) CCC_buffer_size_plus(args)
807# define buffer_size_minus(args...) CCC_buffer_size_minus(args)
808# define buffer_size_set(args...) CCC_buffer_size_set(args)
809# define buffer_capacity(args...) CCC_buffer_capacity(args)
810# define buffer_capacity_bytes(args...) CCC_buffer_capacity_bytes(args)
811# define buffer_sizeof_type(args...) CCC_buffer_sizeof_type(args)
812# define buffer_index(args...) CCC_buffer_index(args)
813# define buffer_is_full(args...) CCC_buffer_is_full(args)
814# define buffer_is_empty(args...) CCC_buffer_is_empty(args)
815# define buffer_at(args...) CCC_buffer_at(args)
816# define buffer_as(args...) CCC_buffer_as(args)
817# define buffer_back(args...) CCC_buffer_back(args)
818# define buffer_back_as(args...) CCC_buffer_back_as(args)
819# define buffer_front(args...) CCC_buffer_front(args)
820# define buffer_front_as(args...) CCC_buffer_front_as(args)
821# define buffer_allocate_back(args...) CCC_buffer_allocate_back(args)
822# define buffer_emplace(args...) CCC_buffer_emplace(args)
823# define buffer_emplace_back(args...) CCC_buffer_emplace_back(args)
824# define buffer_push_back(args...) CCC_buffer_push_back(args)
825# define buffer_pop_back(args...) CCC_buffer_pop_back(args)
826# define buffer_pop_back_n(args...) CCC_buffer_pop_back_n(args)
827# define buffer_move(args...) CCC_buffer_move(args)
828# define buffer_swap(args...) CCC_buffer_swap(args)
829# define buffer_write(args...) CCC_buffer_write(args)
830# define buffer_erase(args...) CCC_buffer_erase(args)
831# define buffer_insert(args...) CCC_buffer_insert(args)
832# define buffer_begin(args...) CCC_buffer_begin(args)
833# define buffer_next(args...) CCC_buffer_next(args)
834# define buffer_end(args...) CCC_buffer_end(args)
835# define buffer_reverse_begin(args...) CCC_buffer_reverse_begin(args)
836# define buffer_reverse_next(args...) CCC_buffer_reverse_next(args)
837# define buffer_reverse_end(args...) CCC_buffer_reverse_end(args)
838# define buffer_capacity_end(args...) CCC_buffer_capacity_end(args)
839#endif /* BUFFER_USING_NAMESPACE_CCC */
840
841#endif /* CCC_BUFFER_H */
CCC_Count CCC_buffer_count_bytes(CCC_Buffer const *buffer)
Return the bytes in the Buffer given the current count of active elements.
CCC_Result CCC_buffer_allocate(CCC_Buffer *buffer, size_t capacity, CCC_Allocator *allocate)
allocates the Buffer to the specified size according to the user defined allocation function.
void * CCC_buffer_at(CCC_Buffer const *buffer, size_t index)
return the element at slot index in buf.
CCC_Result CCC_buffer_clear_and_free(CCC_Buffer *buffer, CCC_Type_destructor *destroy)
Set size of buffer to 0 and call destroy on each element if needed. Free the underlying Buffer settin...
void * CCC_buffer_reverse_begin(CCC_Buffer const *buffer)
obtain the address of the last element in the Buffer in preparation for iteration according to size.
CCC_Count CCC_buffer_index(CCC_Buffer const *buffer, void const *slot)
return the index of an element known to be in the buffer.
CCC_Result CCC_buffer_pop_back(CCC_Buffer *buffer)
pop the back element from the Buffer according to size.
void * CCC_buffer_front(CCC_Buffer const *buffer)
return the first element in the Buffer at index 0.
CCC_Result CCC_buffer_erase(CCC_Buffer *buffer, size_t index)
erase element at slot index according to size of the Buffer maintaining contiguous storage of element...
void * CCC_buffer_push_back(CCC_Buffer *buffer, void const *data)
return the newly pushed data into the last slot of the buffer according to size.
CCC_Count CCC_buffer_capacity(CCC_Buffer const *buffer)
Return the current capacity of total possible slots.
CCC_Tribool CCC_buffer_is_empty(CCC_Buffer const *buffer)
return true if the size of the Buffer is 0.
void * CCC_buffer_move(CCC_Buffer *buffer, size_t destination, size_t source)
Move data at index source to destination according to capacity.
void * CCC_buffer_next(CCC_Buffer const *buffer, void const *iterator)
advance the iterator to the next slot in the Buffer according to size.
CCC_Result CCC_buffer_reserve(CCC_Buffer *buffer, size_t to_add, CCC_Allocator *allocate)
Reserves space for at least to_add more elements.
void * CCC_buffer_allocate_back(CCC_Buffer *buffer)
allocates a new slot from the Buffer at the end of the contiguous array. A slot is equivalent to one ...
CCC_Result CCC_buffer_clear(CCC_Buffer *buffer, CCC_Type_destructor *destroy)
Set size of buffer to 0 and call destroy on each element if needed. O(1) if no destroy is provided,...
CCC_Count CCC_buffer_count(CCC_Buffer const *buffer)
obtain the count of Buffer active slots.
void * CCC_buffer_end(CCC_Buffer const *buffer)
return the end position of the Buffer according to size.
CCC_Result CCC_buffer_clear_and_free_reserve(CCC_Buffer *buffer, CCC_Type_destructor *destroy, CCC_Allocator *allocate)
Frees all slots in the buffer and frees the underlying Buffer that was previously dynamically reserve...
void * CCC_buffer_insert(CCC_Buffer *buffer, size_t index, void const *data)
insert data at slot index according to size of the Buffer maintaining contiguous storage of elements ...
void * CCC_buffer_reverse_next(CCC_Buffer const *buffer, void const *iterator)
advance the iterator to the next slot in the Buffer according to size and in reverse order.
CCC_Count CCC_buffer_sizeof_type(CCC_Buffer const *buffer)
The size of the type being stored contiguously in the buffer.
CCC_Result CCC_buffer_write(CCC_Buffer *buffer, size_t index, void const *data)
write data to Buffer at slot at index index according to capacity.
void * CCC_buffer_begin(CCC_Buffer const *buffer)
obtain the base address of the Buffer in preparation for iteration.
CCC_Count CCC_buffer_capacity_bytes(CCC_Buffer const *buffer)
Return the bytes in the Buffer given the current capacity elements.
CCC_Result CCC_buffer_pop_back_n(CCC_Buffer *buffer, size_t count)
pop count elements from the back of the Buffer according to size.
CCC_Result CCC_buffer_size_minus(CCC_Buffer *buffer, size_t count)
Subtract count from the size of the buffer.
CCC_Tribool CCC_buffer_is_full(CCC_Buffer const *buffer)
return true if the size of the Buffer equals capacity.
void * CCC_buffer_capacity_end(CCC_Buffer const *buffer)
return the end position of the Buffer according to capacity.
void * CCC_buffer_back(CCC_Buffer const *buffer)
return the final element in the Buffer according the current size.
void * CCC_buffer_reverse_end(CCC_Buffer const *buffer)
return the reverse_end position of the buffer.
CCC_Result CCC_buffer_size_plus(CCC_Buffer *buffer, size_t count)
add count to the size of the buffer.
CCC_Result CCC_buffer_size_set(CCC_Buffer *buffer, size_t count)
Set the Buffer size to n.
CCC_Result CCC_buffer_swap(CCC_Buffer *buffer, void *temp, size_t index, size_t swap_index)
swap elements at index and swap_index according to capacity of the bufer.
CCC_Result CCC_buffer_copy(CCC_Buffer *destination, CCC_Buffer const *source, CCC_Allocator *allocate)
Copy the buffer from source to newly initialized destination.
Definition: private_buffer.h:34
size_t capacity
Definition: private_buffer.h:40
size_t count
Definition: private_buffer.h:38
CCC_Allocator * allocate
Definition: private_buffer.h:44
void * data
Definition: private_buffer.h:36
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:202
The C Container Collection Fundamental Types.
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:133
void CCC_Type_destructor(CCC_Type_context)
A callback function for destroying an element in the container.
Definition: types.h:376
CCC_Result
A result of actions on containers.
Definition: types.h:148
void * CCC_Allocator(CCC_Allocator_context)
An allocation function at the core of all containers.
Definition: types.h:340