24#ifndef CCC_PRIVATE_FLAT_BUFFER_H
25#define CCC_PRIVATE_FLAT_BUFFER_H
54#define CCC_private_flat_buffer_default(private_type_name) \
55 (struct CCC_Flat_buffer) { \
56 .sizeof_type = sizeof(private_type_name), \
57 .alignof_type = alignof(private_type_name), \
64#define CCC_private_flat_buffer_for( \
65 private_type_name, private_capacity, private_count, private_data... \
67 (struct CCC_Flat_buffer) { \
68 .data = (private_data), .sizeof_type = sizeof(private_type_name), \
69 .alignof_type = alignof(private_type_name), .count = (private_count), \
70 .capacity = (private_capacity), \
75#define CCC_private_flat_buffer_from( \
77 private_optional_capacity, \
78 private_compound_literal_array... \
80 (struct { struct CCC_Flat_buffer private; }){(__extension__({ \
81 typeof(*private_compound_literal_array) \
82 *private_flat_buffer_initializer_list \
83 = private_compound_literal_array; \
84 struct CCC_Flat_buffer private_buf = CCC_private_flat_buffer_default( \
85 typeof(*private_flat_buffer_initializer_list) \
87 size_t const private_n \
88 = sizeof(private_compound_literal_array) \
89 / sizeof(*private_flat_buffer_initializer_list); \
90 size_t const private_cap = private_optional_capacity; \
91 if (CCC_flat_buffer_reserve( \
93 (private_n > private_cap ? private_n : private_cap), \
94 &(private_allocator) \
99 private_flat_buffer_initializer_list, \
100 private_n * sizeof(*private_flat_buffer_initializer_list) \
102 private_buf.count = private_n; \
109#define CCC_private_flat_buffer_with_capacity( \
110 private_type_name, private_allocator, private_capacity \
112 (struct { struct CCC_Flat_buffer private; }){(__extension__({ \
113 struct CCC_Flat_buffer private_buf \
114 = CCC_private_flat_buffer_default(private_type_name); \
115 (void)CCC_flat_buffer_reserve( \
116 &private_buf, (private_capacity), &(private_allocator) \
125#if defined(__clang__) || defined(__llvm__)
127# define CCC_private_flat_buffer_with_storage( \
128 private_count, private_compound_literal_array... \
132 sizeof(private_compound_literal_array), \
133 "provide non-zero capacity compound literal array" \
137 <= (sizeof(private_compound_literal_array) \
138 / sizeof(*private_compound_literal_array)), \
139 "provide count less than or equal to capacity of " \
140 "compound literal array" \
142 CCC_Flat_buffer private; \
144 .data = (private_compound_literal_array), \
145 .sizeof_type = sizeof(*private_compound_literal_array), \
146 .alignof_type = alignof(*private_compound_literal_array), \
147 .count = private_count, \
148 .capacity = sizeof(private_compound_literal_array) \
149 / sizeof(*private_compound_literal_array), \
154# define CCC_private_flat_buffer_with_storage( \
155 private_count, private_compound_literal_array... \
157 (struct CCC_Flat_buffer) { \
158 .data = (private_compound_literal_array), \
159 .sizeof_type = sizeof(*private_compound_literal_array), \
160 .alignof_type = alignof(*private_compound_literal_array), \
161 .count = private_count, \
162 .capacity = sizeof(private_compound_literal_array) \
163 / sizeof(*private_compound_literal_array), \
168#define CCC_private_flat_buffer_emplace( \
169 private_flat_buffer_pointer, index, private_type_compound_literal... \
172 __auto_type private_i = (index); \
173 typeof(private_type_compound_literal) *private_flat_buffer_res \
174 = CCC_flat_buffer_at((private_flat_buffer_pointer), private_i); \
175 if (private_flat_buffer_res) { \
176 *private_flat_buffer_res = private_type_compound_literal; \
178 private_flat_buffer_res; \
182#define CCC_private_flat_buffer_emplace_back( \
183 private_flat_buffer_pointer, \
184 private_allocator_pointer, \
185 private_type_compound_literal... \
188 typeof(private_type_compound_literal) *private_flat_buffer_res \
189 = CCC_flat_buffer_allocate_back( \
190 (private_flat_buffer_pointer), (private_allocator_pointer) \
192 if (private_flat_buffer_res) { \
193 *private_flat_buffer_res = private_type_compound_literal; \
195 private_flat_buffer_res; \
Definition: private_flat_buffer.h:40
size_t alignof_type
Definition: private_flat_buffer.h:50
void * data
Definition: private_flat_buffer.h:42
size_t capacity
Definition: private_flat_buffer.h:46
size_t count
Definition: private_flat_buffer.h:44
size_t sizeof_type
Definition: private_flat_buffer.h:48