16#ifndef CCC_PRIVATE_FLAT_BUFFER_H
17#define CCC_PRIVATE_FLAT_BUFFER_H
44#define CCC_private_flat_buffer_default(private_type_name) \
45 (struct CCC_Flat_buffer) { \
46 .sizeof_type = sizeof(private_type_name), \
53#define CCC_private_flat_buffer_for( \
54 private_type_name, private_capacity, private_count, private_data... \
56 (struct CCC_Flat_buffer) { \
57 .data = (private_data), .sizeof_type = sizeof(private_type_name), \
58 .count = (private_count), .capacity = (private_capacity), \
63#define CCC_private_flat_buffer_from( \
65 private_optional_capacity, \
66 private_compound_literal_array... \
68 (struct { struct CCC_Flat_buffer private; }){(__extension__({ \
69 typeof(*private_compound_literal_array) \
70 *private_flat_buffer_initializer_list \
71 = private_compound_literal_array; \
72 struct CCC_Flat_buffer private_buf = CCC_private_flat_buffer_default( \
73 typeof(*private_flat_buffer_initializer_list) \
75 size_t const private_n \
76 = sizeof(private_compound_literal_array) \
77 / sizeof(*private_flat_buffer_initializer_list); \
78 size_t const private_cap = private_optional_capacity; \
79 if (CCC_flat_buffer_reserve( \
81 (private_n > private_cap ? private_n : private_cap), \
82 &(private_allocator) \
87 private_flat_buffer_initializer_list, \
88 private_n * sizeof(*private_flat_buffer_initializer_list) \
90 private_buf.count = private_n; \
97#define CCC_private_flat_buffer_with_capacity( \
98 private_type_name, private_allocator, private_capacity \
100 (struct { struct CCC_Flat_buffer private; }){(__extension__({ \
101 struct CCC_Flat_buffer private_buf \
102 = CCC_private_flat_buffer_default(private_type_name); \
103 (void)CCC_flat_buffer_reserve( \
104 &private_buf, (private_capacity), &(private_allocator) \
113#if defined(__clang__) || defined(__llvm__)
115# define CCC_private_flat_buffer_with_storage( \
116 private_count, private_compound_literal_array... \
120 sizeof(private_compound_literal_array), \
121 "provide non-zero capacity compound literal array" \
125 <= (sizeof(private_compound_literal_array) \
126 / sizeof(*private_compound_literal_array)), \
127 "provide count less than or equal to capacity of " \
128 "compound literal array" \
130 CCC_Flat_buffer private; \
132 .data = (private_compound_literal_array), \
133 .sizeof_type = sizeof(*private_compound_literal_array), \
134 .count = private_count, \
135 .capacity = sizeof(private_compound_literal_array) \
136 / sizeof(*private_compound_literal_array), \
141# define CCC_private_flat_buffer_with_storage( \
142 private_count, private_compound_literal_array... \
144 (struct CCC_Flat_buffer) { \
145 .data = (private_compound_literal_array), \
146 .sizeof_type = sizeof(*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_emplace( \
155 private_flat_buffer_pointer, index, private_type_compound_literal... \
158 __auto_type private_i = (index); \
159 typeof(private_type_compound_literal) *private_flat_buffer_res \
160 = CCC_flat_buffer_at((private_flat_buffer_pointer), private_i); \
161 if (private_flat_buffer_res) { \
162 *private_flat_buffer_res = private_type_compound_literal; \
164 private_flat_buffer_res; \
168#define CCC_private_flat_buffer_emplace_back( \
169 private_flat_buffer_pointer, \
170 private_allocator_pointer, \
171 private_type_compound_literal... \
174 typeof(private_type_compound_literal) *private_flat_buffer_res \
175 = CCC_flat_buffer_allocate_back( \
176 (private_flat_buffer_pointer), (private_allocator_pointer) \
178 if (private_flat_buffer_res) { \
179 *private_flat_buffer_res = private_type_compound_literal; \
181 private_flat_buffer_res; \
Definition: private_flat_buffer.h:32
void * data
Definition: private_flat_buffer.h:34
size_t capacity
Definition: private_flat_buffer.h:38
size_t count
Definition: private_flat_buffer.h:36
size_t sizeof_type
Definition: private_flat_buffer.h:40