16#ifndef CCC_PRIVATE_BUFFER_H
17#define CCC_PRIVATE_BUFFER_H
50#define CCC_private_buf_non_CCC_private_buf_default_size(...) __VA_ARGS__
52#define CCC_private_buf_default_size(...) 0
54#define CCC_private_buf_optional_size(...) \
55 __VA_OPT__(CCC_private_buf_non_)##CCC_private_buf_default_size(__VA_ARGS__)
61#define CCC_private_buffer_initialize(private_data, private_type_name, \
62 private_allocate, private_context_data, \
63 private_capacity, ...) \
65 .data = (private_data), \
66 .sizeof_type = sizeof(private_type_name), \
67 .count = CCC_private_buf_optional_size(__VA_ARGS__), \
68 .capacity = (private_capacity), \
69 .allocate = (private_allocate), \
70 .context = (private_context_data), \
75#define CCC_private_buffer_from(private_allocate, private_context_data, \
76 private_optional_capacity, \
77 private_compound_literal_array...) \
79 typeof(*private_compound_literal_array) \
80 *private_buffer_initializer_list \
81 = private_compound_literal_array; \
82 struct CCC_Buffer private_buf = CCC_private_buffer_initialize( \
83 NULL, typeof(*private_buffer_initializer_list), private_allocate, \
84 private_context_data, 0); \
85 size_t const private_n = sizeof(private_compound_literal_array) \
86 / sizeof(*private_buffer_initializer_list); \
87 size_t const private_cap = private_optional_capacity; \
88 if (CCC_buffer_reserve( \
90 (private_n > private_cap ? private_n : private_cap), \
94 (void)memcpy(private_buf.data, private_buffer_initializer_list, \
96 * sizeof(*private_buffer_initializer_list)); \
97 private_buf.count = private_n; \
104#define CCC_private_buffer_with_capacity(private_type_name, private_allocate, \
105 private_context_data, \
108 struct CCC_Buffer private_buf = CCC_private_buffer_initialize( \
109 NULL, private_type_name, private_allocate, private_context_data, \
111 (void)CCC_buffer_reserve(&private_buf, (private_capacity), \
117#define CCC_private_buffer_emplace(private_buffer_pointer, index, \
118 private_type_compound_literal...) \
120 typeof(private_type_compound_literal) *private_buffer_res = NULL; \
121 __auto_type private_i = (index); \
122 __auto_type private_emplace_buff_pointer = (private_buffer_pointer); \
124 = CCC_buffer_at(private_emplace_buff_pointer, private_i); \
125 if (private_buffer_res) \
127 *private_buffer_res = private_type_compound_literal; \
129 private_buffer_res; \
133#define CCC_private_buffer_emplace_back(private_buffer_pointer, \
134 private_type_compound_literal...) \
136 typeof(private_type_compound_literal) *private_buffer_res = NULL; \
137 __auto_type private_emplace_back_private_buffer_pointer \
138 = (private_buffer_pointer); \
139 private_buffer_res = CCC_buffer_allocate_back( \
140 (private_emplace_back_private_buffer_pointer)); \
141 if (private_buffer_res) \
143 *private_buffer_res = private_type_compound_literal; \
145 private_buffer_res; \
Definition: private_buffer.h:34
void * context
Definition: private_buffer.h:46
size_t capacity
Definition: private_buffer.h:40
size_t count
Definition: private_buffer.h:38
size_t sizeof_type
Definition: private_buffer.h:42
CCC_Allocator * allocate
Definition: private_buffer.h:44
void * data
Definition: private_buffer.h:36
void * CCC_Allocator(CCC_Allocator_context)
An allocation function at the core of all containers.
Definition: types.h:340