Line data Source code
1 : #pragma GCC diagnostic push
2 : #pragma GCC diagnostic ignored "-Wmisleading-indentation"
3 :
4 : #ifndef FLATBUFFERS_COMMON_BUILDER_H
5 : #define FLATBUFFERS_COMMON_BUILDER_H
6 :
7 : /* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */
8 :
9 : /* Common FlatBuffers build functionality for C. */
10 :
11 : #include "flatcc/flatcc_prologue.h"
12 : #ifndef FLATBUILDER_H
13 : #include "flatcc/flatcc_builder.h"
14 : #endif
15 : typedef flatcc_builder_t flatbuffers_builder_t;
16 : typedef flatcc_builder_ref_t flatbuffers_ref_t;
17 : typedef flatcc_builder_ref_t flatbuffers_vec_ref_t;
18 : typedef flatcc_builder_union_ref_t flatbuffers_union_ref_t;
19 : typedef flatcc_builder_union_vec_ref_t flatbuffers_union_vec_ref_t;
20 : /* integer return code (ref and ptr always fail on 0) */
21 : #define flatbuffers_failed(x) ((x) < 0)
22 : typedef flatbuffers_ref_t flatbuffers_root_t;
23 : #define flatbuffers_root(ref) ((flatbuffers_root_t)(ref))
24 :
25 : #define __flatbuffers_memoize_begin(B, src)\
26 : do { flatcc_builder_ref_t _ref; if ((_ref = flatcc_builder_refmap_find((B), (src)))) return _ref; } while (0)
27 : #define __flatbuffers_memoize_end(B, src, op) do { return flatcc_builder_refmap_insert((B), (src), (op)); } while (0)
28 : #define __flatbuffers_memoize(B, src, op) do { __flatbuffers_memoize_begin(B, src); __flatbuffers_memoize_end(B, src, op); } while (0)
29 :
30 : #define __flatbuffers_build_buffer(NS)\
31 : typedef NS ## ref_t NS ## buffer_ref_t;\
32 0 : static inline int NS ## buffer_start(NS ## builder_t *B, const NS ##fid_t fid)\
33 0 : { return flatcc_builder_start_buffer(B, fid, 0, 0); }\
34 0 : static inline int NS ## buffer_start_with_size(NS ## builder_t *B, const NS ##fid_t fid)\
35 0 : { return flatcc_builder_start_buffer(B, fid, 0, flatcc_builder_with_size); }\
36 0 : static inline int NS ## buffer_start_aligned(NS ## builder_t *B, NS ##fid_t fid, uint16_t block_align)\
37 0 : { return flatcc_builder_start_buffer(B, fid, block_align, 0); }\
38 0 : static inline int NS ## buffer_start_aligned_with_size(NS ## builder_t *B, NS ##fid_t fid, uint16_t block_align)\
39 0 : { return flatcc_builder_start_buffer(B, fid, block_align, flatcc_builder_with_size); }\
40 0 : static inline NS ## buffer_ref_t NS ## buffer_end(NS ## builder_t *B, NS ## ref_t root)\
41 0 : { return flatcc_builder_end_buffer(B, root); }
42 :
43 : #define __flatbuffers_build_table_root(NS, N, FID, TFID)\
44 0 : static inline int N ## _start_as_root(NS ## builder_t *B)\
45 0 : { return NS ## buffer_start(B, FID) ? -1 : N ## _start(B); }\
46 0 : static inline int N ## _start_as_root_with_size(NS ## builder_t *B)\
47 0 : { return NS ## buffer_start_with_size(B, FID) ? -1 : N ## _start(B); }\
48 0 : static inline int N ## _start_as_typed_root(NS ## builder_t *B)\
49 0 : { return NS ## buffer_start(B, TFID) ? -1 : N ## _start(B); }\
50 0 : static inline int N ## _start_as_typed_root_with_size(NS ## builder_t *B)\
51 0 : { return NS ## buffer_start_with_size(B, TFID) ? -1 : N ## _start(B); }\
52 0 : static inline NS ## buffer_ref_t N ## _end_as_root(NS ## builder_t *B)\
53 0 : { return NS ## buffer_end(B, N ## _end(B)); }\
54 0 : static inline NS ## buffer_ref_t N ## _end_as_typed_root(NS ## builder_t *B)\
55 0 : { return NS ## buffer_end(B, N ## _end(B)); }\
56 0 : static inline NS ## buffer_ref_t N ## _create_as_root(NS ## builder_t *B __ ## N ## _formal_args)\
57 0 : { if (NS ## buffer_start(B, FID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
58 0 : static inline NS ## buffer_ref_t N ## _create_as_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
59 0 : { if (NS ## buffer_start_with_size(B, FID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
60 0 : static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B __ ## N ## _formal_args)\
61 0 : { if (NS ## buffer_start(B, TFID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
62 0 : static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
63 0 : { if (NS ## buffer_start_with_size(B, TFID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
64 0 : static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _table_t t)\
65 0 : { if (NS ## buffer_start(B, FID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }\
66 0 : static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _table_t t)\
67 0 : { if (NS ## buffer_start_with_size(B, FID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }\
68 0 : static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _table_t t)\
69 0 : { if (NS ## buffer_start(B, TFID)) return 0;return NS ## buffer_end(B, N ## _clone(B, t)); }\
70 0 : static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _table_t t)\
71 0 : { if (NS ## buffer_start_with_size(B, TFID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }
72 :
73 : #define __flatbuffers_build_table_prolog(NS, N, FID, TFID)\
74 : __flatbuffers_build_table_vector_ops(NS, N ## _vec, N)\
75 : __flatbuffers_build_table_root(NS, N, FID, TFID)
76 :
77 : #define __flatbuffers_build_struct_root(NS, N, A, FID, TFID)\
78 0 : static inline N ## _t *N ## _start_as_root(NS ## builder_t *B)\
79 0 : { return NS ## buffer_start(B, FID) ? 0 : N ## _start(B); }\
80 0 : static inline N ## _t *N ## _start_as_root_with_size(NS ## builder_t *B)\
81 0 : { return NS ## buffer_start_with_size(B, FID) ? 0 : N ## _start(B); }\
82 0 : static inline N ## _t *N ## _start_as_typed_root(NS ## builder_t *B)\
83 0 : { return NS ## buffer_start(B, TFID) ? 0 : N ## _start(B); }\
84 0 : static inline N ## _t *N ## _start_as_typed_root_with_size(NS ## builder_t *B)\
85 0 : { return NS ## buffer_start_with_size(B, TFID) ? 0 : N ## _start(B); }\
86 0 : static inline NS ## buffer_ref_t N ## _end_as_root(NS ## builder_t *B)\
87 0 : { return NS ## buffer_end(B, N ## _end(B)); }\
88 0 : static inline NS ## buffer_ref_t N ## _end_as_typed_root(NS ## builder_t *B)\
89 0 : { return NS ## buffer_end(B, N ## _end(B)); }\
90 0 : static inline NS ## buffer_ref_t N ## _end_pe_as_root(NS ## builder_t *B)\
91 0 : { return NS ## buffer_end(B, N ## _end_pe(B)); }\
92 0 : static inline NS ## buffer_ref_t N ## _end_pe_as_typed_root(NS ## builder_t *B)\
93 0 : { return NS ## buffer_end(B, N ## _end_pe(B)); }\
94 0 : static inline NS ## buffer_ref_t N ## _create_as_root(NS ## builder_t *B __ ## N ## _formal_args)\
95 0 : { return flatcc_builder_create_buffer(B, FID, 0,\
96 0 : N ## _create(B __ ## N ## _call_args), A, 0); }\
97 0 : static inline NS ## buffer_ref_t N ## _create_as_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
98 0 : { return flatcc_builder_create_buffer(B, FID, 0,\
99 0 : N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\
100 0 : static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B __ ## N ## _formal_args)\
101 0 : { return flatcc_builder_create_buffer(B, TFID, 0,\
102 0 : N ## _create(B __ ## N ## _call_args), A, 0); }\
103 0 : static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
104 0 : { return flatcc_builder_create_buffer(B, TFID, 0,\
105 0 : N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\
106 0 : static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _struct_t p)\
107 0 : { return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, 0); }\
108 0 : static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _struct_t p)\
109 0 : { return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }\
110 0 : static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _struct_t p)\
111 0 : { return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, 0); }\
112 0 : static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _struct_t p)\
113 0 : { return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }
114 :
115 : #define __flatbuffers_build_nested_table_root(NS, N, TN, FID, TFID)\
116 : static inline int N ## _start_as_root(NS ## builder_t *B)\
117 : { return NS ## buffer_start(B, FID) ? -1 : TN ## _start(B); }\
118 : static inline int N ## _start_as_typed_root(NS ## builder_t *B)\
119 : { return NS ## buffer_start(B, TFID) ? -1 : TN ## _start(B); }\
120 : static inline int N ## _end_as_root(NS ## builder_t *B)\
121 : { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
122 : static inline int N ## _end_as_typed_root(NS ## builder_t *B)\
123 : { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
124 : static inline int N ## _nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
125 : { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
126 : align ? align : 8, FLATBUFFERS_COUNT_MAX(1))); }\
127 : static inline int N ## _typed_nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
128 : { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
129 : align ? align : 8, FLATBUFFERS_COUNT_MAX(1))); }\
130 : static inline int N ## _clone_as_root(NS ## builder_t *B, TN ## _table_t t)\
131 : { return N ## _add(B, TN ## _clone_as_root(B, t)); }\
132 : static inline int N ## _clone_as_typed_root(NS ## builder_t *B, TN ## _table_t t)\
133 : { return N ## _add(B, TN ## _clone_as_typed_root(B, t)); }
134 :
135 : #define __flatbuffers_build_nested_struct_root(NS, N, TN, A, FID, TFID)\
136 : static inline TN ## _t *N ## _start_as_root(NS ## builder_t *B)\
137 : { return NS ## buffer_start(B, FID) ? 0 : TN ## _start(B); }\
138 : static inline TN ## _t *N ## _start_as_typed_root(NS ## builder_t *B)\
139 : { return NS ## buffer_start(B, FID) ? 0 : TN ## _start(B); }\
140 : static inline int N ## _end_as_root(NS ## builder_t *B)\
141 : { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
142 : static inline int N ## _end_as_typed_root(NS ## builder_t *B)\
143 : { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
144 : static inline int N ## _end_pe_as_root(NS ## builder_t *B)\
145 : { return N ## _add(B, NS ## buffer_end(B, TN ## _end_pe(B))); }\
146 : static inline int N ## _create_as_root(NS ## builder_t *B __ ## TN ## _formal_args)\
147 : { return N ## _add(B, flatcc_builder_create_buffer(B, FID, 0,\
148 : TN ## _create(B __ ## TN ## _call_args), A, flatcc_builder_is_nested)); }\
149 : static inline int N ## _create_as_typed_root(NS ## builder_t *B __ ## TN ## _formal_args)\
150 : { return N ## _add(B, flatcc_builder_create_buffer(B, TFID, 0,\
151 : TN ## _create(B __ ## TN ## _call_args), A, flatcc_builder_is_nested)); }\
152 : static inline int N ## _nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
153 : { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
154 : align < A ? A : align, FLATBUFFERS_COUNT_MAX(1))); }\
155 : static inline int N ## _typed_nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
156 : { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
157 : align < A ? A : align, FLATBUFFERS_COUNT_MAX(1))); }\
158 : static inline int N ## _clone_as_root(NS ## builder_t *B, TN ## _struct_t p)\
159 : { return N ## _add(B, TN ## _clone_as_root(B, p)); }\
160 : static inline int N ## _clone_as_typed_root(NS ## builder_t *B, TN ## _struct_t p)\
161 : { return N ## _add(B, TN ## _clone_as_typed_root(B, p)); }
162 :
163 : #define __flatbuffers_build_vector_ops(NS, V, N, TN, T)\
164 0 : static inline T *V ## _extend(NS ## builder_t *B, size_t len)\
165 0 : { return (T *)flatcc_builder_extend_vector(B, len); }\
166 0 : static inline T *V ## _append(NS ## builder_t *B, const T *data, size_t len)\
167 0 : { return (T *)flatcc_builder_append_vector(B, data, len); }\
168 0 : static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
169 0 : { return flatcc_builder_truncate_vector(B, len); }\
170 0 : static inline T *V ## _edit(NS ## builder_t *B)\
171 0 : { return (T *)flatcc_builder_vector_edit(B); }\
172 0 : static inline size_t V ## _reserved_len(NS ## builder_t *B)\
173 0 : { return flatcc_builder_vector_count(B); }\
174 0 : static inline T *V ## _push(NS ## builder_t *B, const T *p)\
175 0 : { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? (memcpy(_p, p, TN ## __size()), _p) : 0; }\
176 0 : static inline T *V ## _push_copy(NS ## builder_t *B, const T *p)\
177 0 : { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _copy(_p, p) : 0; }\
178 0 : static inline T *V ## _push_clone(NS ## builder_t *B, const T *p)\
179 0 : { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _copy(_p, p) : 0; }\
180 0 : static inline T *V ## _push_create(NS ## builder_t *B __ ## TN ## _formal_args)\
181 0 : { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _assign(_p __ ## TN ## _call_args) : 0; }
182 :
183 : #define __flatbuffers_build_vector(NS, N, T, S, A)\
184 : typedef NS ## ref_t N ## _vec_ref_t;\
185 0 : static inline int N ## _vec_start(NS ## builder_t *B)\
186 0 : { return flatcc_builder_start_vector(B, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
187 0 : static inline N ## _vec_ref_t N ## _vec_end_pe(NS ## builder_t *B)\
188 0 : { return flatcc_builder_end_vector(B); }\
189 0 : static inline N ## _vec_ref_t N ## _vec_end(NS ## builder_t *B)\
190 0 : { if (!NS ## is_native_pe()) { size_t i, n; T *p = (T *)flatcc_builder_vector_edit(B);\
191 0 : for (i = 0, n = flatcc_builder_vector_count(B); i < n; ++i)\
192 0 : { N ## _to_pe(N ## __ptr_add(p, i)); }} return flatcc_builder_end_vector(B); }\
193 0 : static inline N ## _vec_ref_t N ## _vec_create_pe(NS ## builder_t *B, const T *data, size_t len)\
194 0 : { return flatcc_builder_create_vector(B, data, len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
195 0 : static inline N ## _vec_ref_t N ## _vec_create(NS ## builder_t *B, const T *data, size_t len)\
196 0 : { if (!NS ## is_native_pe()) { size_t i; T *p; int ret = flatcc_builder_start_vector(B, S, A, FLATBUFFERS_COUNT_MAX(S)); if (ret) { return ret; }\
197 0 : p = (T *)flatcc_builder_extend_vector(B, len); if (!p) return 0;\
198 0 : for (i = 0; i < len; ++i) { N ## _copy_to_pe(N ## __ptr_add(p, i), N ## __const_ptr_add(data, i)); }\
199 0 : return flatcc_builder_end_vector(B); } else return flatcc_builder_create_vector(B, data, len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
200 0 : static inline N ## _vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_vec_t vec)\
201 0 : { __flatbuffers_memoize(B, vec, flatcc_builder_create_vector(B, vec, N ## _vec_len(vec), S, A, FLATBUFFERS_COUNT_MAX(S))); }\
202 0 : static inline N ## _vec_ref_t N ## _vec_slice(NS ## builder_t *B, N ##_vec_t vec, size_t index, size_t len)\
203 0 : { size_t n = N ## _vec_len(vec); if (index >= n) index = n; n -= index; if (len > n) len = n;\
204 0 : return flatcc_builder_create_vector(B, N ## __const_ptr_add(vec, index), len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
205 : __flatbuffers_build_vector_ops(NS, N ## _vec, N, N, T)
206 :
207 : #define __flatbuffers_build_union_vector_ops(NS, V, N, TN)\
208 : static inline TN ## _union_ref_t *V ## _extend(NS ## builder_t *B, size_t len)\
209 : { return flatcc_builder_extend_union_vector(B, len); }\
210 : static inline TN ## _union_ref_t *V ## _append(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\
211 : { return flatcc_builder_append_union_vector(B, data, len); }\
212 : static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
213 : { return flatcc_builder_truncate_union_vector(B, len); }\
214 : static inline TN ## _union_ref_t *V ## _edit(NS ## builder_t *B)\
215 : { return (TN ## _union_ref_t *) flatcc_builder_union_vector_edit(B); }\
216 : static inline size_t V ## _reserved_len(NS ## builder_t *B)\
217 : { return flatcc_builder_union_vector_count(B); }\
218 : static inline TN ## _union_ref_t *V ## _push(NS ## builder_t *B, const TN ## _union_ref_t ref)\
219 : { return flatcc_builder_union_vector_push(B, ref); }\
220 : static inline TN ## _union_ref_t *V ## _push_clone(NS ## builder_t *B, TN ## _union_t u)\
221 : { return TN ## _vec_push(B, TN ## _clone(B, u)); }
222 :
223 : #define __flatbuffers_build_union_vector(NS, N)\
224 : static inline int N ## _vec_start(NS ## builder_t *B)\
225 : { return flatcc_builder_start_union_vector(B); }\
226 : static inline N ## _union_vec_ref_t N ## _vec_end(NS ## builder_t *B)\
227 : { return flatcc_builder_end_union_vector(B); }\
228 : static inline N ## _union_vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _union_ref_t *data, size_t len)\
229 : { return flatcc_builder_create_union_vector(B, data, len); }\
230 : __flatbuffers_build_union_vector_ops(NS, N ## _vec, N, N)\
231 : /* Preserves DAG structure separately for type and value vector, so a type vector could be shared for many value vectors. */\
232 : static inline N ## _union_vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_union_vec_t vec)\
233 : { N ## _union_vec_ref_t _uvref, _ret = { 0, 0 }; NS ## union_ref_t _uref; size_t _i, _len;\
234 : if (vec.type == 0) return _ret;\
235 : _uvref.type = flatcc_builder_refmap_find(B, vec.type); _uvref.value = flatcc_builder_refmap_find(B, vec.value);\
236 : _len = N ## _union_vec_len(vec); if (_uvref.type == 0) {\
237 : _uvref.type = flatcc_builder_refmap_insert(B, vec.type, (flatcc_builder_create_type_vector(B, vec.type, _len))); }\
238 : if (_uvref.type == 0) { return _ret; } if (_uvref.value == 0) {\
239 : if (flatcc_builder_start_offset_vector(B)) return _ret;\
240 : for (_i = 0; _i < _len; ++_i) { _uref = N ## _clone(B, N ## _union_vec_at(vec, _i));\
241 : if (!_uref.value || !(flatcc_builder_offset_vector_push(B, _uref.value))) return _ret; }\
242 : _uvref.value = flatcc_builder_refmap_insert(B, vec.value, flatcc_builder_end_offset_vector(B));\
243 : if (_uvref.value == 0) return _ret; } return _uvref; }
244 :
245 : #define __flatbuffers_build_string_vector_ops(NS, N)\
246 : static inline int N ## _push_start(NS ## builder_t *B)\
247 : { return NS ## string_start(B); }\
248 : static inline NS ## string_ref_t *N ## _push_end(NS ## builder_t *B)\
249 : { return NS ## string_vec_push(B, NS ## string_end(B)); }\
250 : static inline NS ## string_ref_t *N ## _push_create(NS ## builder_t *B, const char *s, size_t len)\
251 : { return NS ## string_vec_push(B, NS ## string_create(B, s, len)); }\
252 : static inline NS ## string_ref_t *N ## _push_create_str(NS ## builder_t *B, const char *s)\
253 : { return NS ## string_vec_push(B, NS ## string_create_str(B, s)); }\
254 : static inline NS ## string_ref_t *N ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
255 : { return NS ## string_vec_push(B, NS ## string_create_strn(B, s, max_len)); }\
256 : static inline NS ## string_ref_t *N ## _push_clone(NS ## builder_t *B, NS ## string_t string)\
257 : { return NS ## string_vec_push(B, NS ## string_clone(B, string)); }\
258 : static inline NS ## string_ref_t *N ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
259 : { return NS ## string_vec_push(B, NS ## string_slice(B, string, index, len)); }
260 :
261 : #define __flatbuffers_build_table_vector_ops(NS, N, TN)\
262 0 : static inline int N ## _push_start(NS ## builder_t *B)\
263 0 : { return TN ## _start(B); }\
264 0 : static inline TN ## _ref_t *N ## _push_end(NS ## builder_t *B)\
265 0 : { return N ## _push(B, TN ## _end(B)); }\
266 0 : static inline TN ## _ref_t *N ## _push_create(NS ## builder_t *B __ ## TN ##_formal_args)\
267 0 : { return N ## _push(B, TN ## _create(B __ ## TN ## _call_args)); }
268 :
269 : #define __flatbuffers_build_offset_vector_ops(NS, V, N, TN)\
270 0 : static inline TN ## _ref_t *V ## _extend(NS ## builder_t *B, size_t len)\
271 0 : { return flatcc_builder_extend_offset_vector(B, len); }\
272 0 : static inline TN ## _ref_t *V ## _append(NS ## builder_t *B, const TN ## _ref_t *data, size_t len)\
273 0 : { return flatcc_builder_append_offset_vector(B, data, len); }\
274 0 : static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
275 0 : { return flatcc_builder_truncate_offset_vector(B, len); }\
276 0 : static inline TN ## _ref_t *V ## _edit(NS ## builder_t *B)\
277 0 : { return (TN ## _ref_t *)flatcc_builder_offset_vector_edit(B); }\
278 0 : static inline size_t V ## _reserved_len(NS ## builder_t *B)\
279 0 : { return flatcc_builder_offset_vector_count(B); }\
280 0 : static inline TN ## _ref_t *V ## _push(NS ## builder_t *B, const TN ## _ref_t ref)\
281 0 : { return ref ? flatcc_builder_offset_vector_push(B, ref) : 0; }
282 :
283 : #define __flatbuffers_build_offset_vector(NS, N)\
284 : typedef NS ## ref_t N ## _vec_ref_t;\
285 0 : static inline int N ## _vec_start(NS ## builder_t *B)\
286 0 : { return flatcc_builder_start_offset_vector(B); }\
287 0 : static inline N ## _vec_ref_t N ## _vec_end(NS ## builder_t *B)\
288 0 : { return flatcc_builder_end_offset_vector(B); }\
289 0 : static inline N ## _vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _ref_t *data, size_t len)\
290 0 : { return flatcc_builder_create_offset_vector(B, data, len); }\
291 : __flatbuffers_build_offset_vector_ops(NS, N ## _vec, N, N)\
292 0 : static inline N ## _vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_vec_t vec)\
293 0 : { int _ret; N ## _ref_t _e; size_t _i, _len; __flatbuffers_memoize_begin(B, vec);\
294 0 : _len = N ## _vec_len(vec); if (flatcc_builder_start_offset_vector(B)) return 0;\
295 0 : for (_i = 0; _i < _len; ++_i) { if (!(_e = N ## _clone(B, N ## _vec_at(vec, _i)))) return 0;\
296 0 : if (!flatcc_builder_offset_vector_push(B, _e)) return 0; }\
297 0 : __flatbuffers_memoize_end(B, vec, flatcc_builder_end_offset_vector(B)); }\
298 :
299 : #define __flatbuffers_build_string_ops(NS, N)\
300 0 : static inline char *N ## _append(NS ## builder_t *B, const char *s, size_t len)\
301 0 : { return flatcc_builder_append_string(B, s, len); }\
302 0 : static inline char *N ## _append_str(NS ## builder_t *B, const char *s)\
303 0 : { return flatcc_builder_append_string_str(B, s); }\
304 0 : static inline char *N ## _append_strn(NS ## builder_t *B, const char *s, size_t len)\
305 0 : { return flatcc_builder_append_string_strn(B, s, len); }\
306 0 : static inline size_t N ## _reserved_len(NS ## builder_t *B)\
307 0 : { return flatcc_builder_string_len(B); }\
308 0 : static inline char *N ## _extend(NS ## builder_t *B, size_t len)\
309 0 : { return flatcc_builder_extend_string(B, len); }\
310 0 : static inline char *N ## _edit(NS ## builder_t *B)\
311 0 : { return flatcc_builder_string_edit(B); }\
312 0 : static inline int N ## _truncate(NS ## builder_t *B, size_t len)\
313 0 : { return flatcc_builder_truncate_string(B, len); }
314 :
315 : #define __flatbuffers_build_string(NS)\
316 : typedef NS ## ref_t NS ## string_ref_t;\
317 0 : static inline int NS ## string_start(NS ## builder_t *B)\
318 0 : { return flatcc_builder_start_string(B); }\
319 0 : static inline NS ## string_ref_t NS ## string_end(NS ## builder_t *B)\
320 0 : { return flatcc_builder_end_string(B); }\
321 0 : static inline NS ## ref_t NS ## string_create(NS ## builder_t *B, const char *s, size_t len)\
322 0 : { return flatcc_builder_create_string(B, s, len); }\
323 0 : static inline NS ## ref_t NS ## string_create_str(NS ## builder_t *B, const char *s)\
324 0 : { return flatcc_builder_create_string_str(B, s); }\
325 0 : static inline NS ## ref_t NS ## string_create_strn(NS ## builder_t *B, const char *s, size_t len)\
326 0 : { return flatcc_builder_create_string_strn(B, s, len); }\
327 0 : static inline NS ## string_ref_t NS ## string_clone(NS ## builder_t *B, NS ## string_t string)\
328 0 : { __flatbuffers_memoize(B, string, flatcc_builder_create_string(B, string, NS ## string_len(string))); }\
329 0 : static inline NS ## string_ref_t NS ## string_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
330 0 : { size_t n = NS ## string_len(string); if (index >= n) index = n; n -= index; if (len > n) len = n;\
331 0 : return flatcc_builder_create_string(B, string + index, len); }\
332 : __flatbuffers_build_string_ops(NS, NS ## string)\
333 : __flatbuffers_build_offset_vector(NS, NS ## string)
334 :
335 : #define __flatbuffers_copy_from_pe(P, P2, N) (*(P) = N ## _read_from_pe(P2), (P))
336 : #define __flatbuffers_from_pe(P, N) (*(P) = N ## _read_from_pe(P), (P))
337 : #define __flatbuffers_copy_to_pe(P, P2, N) (N ## _write_to_pe((P), *(P2)), (P))
338 : #define __flatbuffers_to_pe(P, N) (N ## _write_to_pe((P), *(P)), (P))
339 : #define __flatbuffers_define_fixed_array_primitives(NS, N, T)\
340 0 : static inline T *N ## _array_copy(T *p, const T *p2, size_t n)\
341 0 : { memcpy(p, p2, n * sizeof(T)); return p; }\
342 0 : static inline T *N ## _array_copy_from_pe(T *p, const T *p2, size_t n)\
343 0 : { size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else {\
344 0 : for (i = 0; i < n; ++i) N ## _copy_from_pe(&p[i], &p2[i]); } return p; }\
345 0 : static inline T *N ## _array_copy_to_pe(T *p, const T *p2, size_t n)\
346 0 : { size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else {\
347 0 : for (i = 0; i < n; ++i) N ## _copy_to_pe(&p[i], &p2[i]); } return p; }
348 : #define __flatbuffers_define_scalar_primitives(NS, N, T)\
349 0 : static inline T *N ## _from_pe(T *p) { return __ ## NS ## from_pe(p, N); }\
350 0 : static inline T *N ## _to_pe(T *p) { return __ ## NS ## to_pe(p, N); }\
351 0 : static inline T *N ## _copy(T *p, const T *p2) { *p = *p2; return p; }\
352 0 : static inline T *N ## _copy_from_pe(T *p, const T *p2)\
353 0 : { return __ ## NS ## copy_from_pe(p, p2, N); }\
354 0 : static inline T *N ## _copy_to_pe(T *p, const T *p2) \
355 0 : { return __ ## NS ## copy_to_pe(p, p2, N); }\
356 0 : static inline T *N ## _assign(T *p, const T v0) { *p = v0; return p; }\
357 0 : static inline T *N ## _assign_from_pe(T *p, T v0)\
358 0 : { *p = N ## _read_from_pe(&v0); return p; }\
359 0 : static inline T *N ## _assign_to_pe(T *p, T v0)\
360 0 : { N ## _write_to_pe(p, v0); return p; }
361 : #define __flatbuffers_build_scalar(NS, N, T)\
362 : __ ## NS ## define_scalar_primitives(NS, N, T)\
363 : __ ## NS ## define_fixed_array_primitives(NS, N, T)\
364 : __ ## NS ## build_vector(NS, N, T, sizeof(T), sizeof(T))
365 : /* Depends on generated copy_to/from_pe functions, and the type. */
366 : #define __flatbuffers_define_struct_primitives(NS, N)\
367 0 : static inline N ## _t *N ##_to_pe(N ## _t *p)\
368 0 : { if (!NS ## is_native_pe()) { N ## _copy_to_pe(p, p); }; return p; }\
369 0 : static inline N ## _t *N ##_from_pe(N ## _t *p)\
370 0 : { if (!NS ## is_native_pe()) { N ## _copy_from_pe(p, p); }; return p; }\
371 0 : static inline N ## _t *N ## _clear(N ## _t *p) { return (N ## _t *)memset(p, 0, N ## __size()); }
372 :
373 : /* Depends on generated copy/assign_to/from_pe functions, and the type. */
374 : #define __flatbuffers_build_struct(NS, N, S, A, FID, TFID)\
375 : __ ## NS ## define_struct_primitives(NS, N)\
376 : typedef NS ## ref_t N ## _ref_t;\
377 0 : static inline N ## _t *N ## _start(NS ## builder_t *B)\
378 0 : { return (N ## _t *)flatcc_builder_start_struct(B, S, A); }\
379 0 : static inline N ## _ref_t N ## _end(NS ## builder_t *B)\
380 0 : { if (!NS ## is_native_pe()) { N ## _to_pe((N ## _t *)flatcc_builder_struct_edit(B)); }\
381 0 : return flatcc_builder_end_struct(B); }\
382 0 : static inline N ## _ref_t N ## _end_pe(NS ## builder_t *B)\
383 0 : { return flatcc_builder_end_struct(B); }\
384 0 : static inline N ## _ref_t N ## _create(NS ## builder_t *B __ ## N ## _formal_args)\
385 0 : { N ## _t *_p = N ## _start(B); if (!_p) return 0; N ##_assign_to_pe(_p __ ## N ## _call_args);\
386 0 : return N ## _end_pe(B); }\
387 0 : static inline N ## _ref_t N ## _clone(NS ## builder_t *B, N ## _struct_t p)\
388 0 : { N ## _t *_p; __flatbuffers_memoize_begin(B, p); _p = N ## _start(B); if (!_p) return 0;\
389 0 : N ## _copy(_p, p); __flatbuffers_memoize_end(B, p, N ##_end_pe(B)); }\
390 : __flatbuffers_build_vector(NS, N, N ## _t, S, A)\
391 : __flatbuffers_build_struct_root(NS, N, A, FID, TFID)\
392 :
393 : #define __flatbuffers_struct_clear_field(p) memset((p), 0, sizeof(*(p)))
394 : #define __flatbuffers_build_table(NS, N, K)\
395 0 : static inline int N ## _start(NS ## builder_t *B)\
396 0 : { return flatcc_builder_start_table(B, K); }\
397 0 : static inline N ## _ref_t N ## _end(NS ## builder_t *B)\
398 0 : { FLATCC_ASSERT(flatcc_builder_check_required(B, __ ## N ## _required,\
399 0 : sizeof(__ ## N ## _required) / sizeof(__ ## N ## _required[0]) - 1));\
400 0 : return flatcc_builder_end_table(B); }\
401 : __flatbuffers_build_offset_vector(NS, N)
402 :
403 : #define __flatbuffers_build_table_field(ID, NS, N, TN, TT)\
404 0 : static inline int N ## _add(NS ## builder_t *B, TN ## _ref_t ref)\
405 0 : { TN ## _ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ?\
406 0 : ((*_p = ref), 0) : -1; }\
407 0 : static inline int N ## _start(NS ## builder_t *B)\
408 0 : { return TN ## _start(B); }\
409 0 : static inline int N ## _end(NS ## builder_t *B)\
410 0 : { return N ## _add(B, TN ## _end(B)); }\
411 0 : static inline TN ## _ref_t N ## _create(NS ## builder_t *B __ ## TN ##_formal_args)\
412 0 : { return N ## _add(B, TN ## _create(B __ ## TN ## _call_args)); }\
413 0 : static inline int N ## _clone(NS ## builder_t *B, TN ## _table_t p)\
414 0 : { return N ## _add(B, TN ## _clone(B, p)); }\
415 0 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
416 0 : { TN ## _table_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
417 :
418 : #define __flatbuffers_build_union_field(ID, NS, N, TN, TT)\
419 : static inline int N ## _add(NS ## builder_t *B, TN ## _union_ref_t uref)\
420 : { NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref.value == 0) return -1;\
421 : if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(*_pt)))) return -1;\
422 : *_pt = uref.type; if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uref.value; return 0; }\
423 : static inline int N ## _add_type(NS ## builder_t *B, TN ## _union_type_t type)\
424 : { TN ## _union_type_t *_pt; if (type == TN ## _NONE) return 0; return (_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1,\
425 : sizeof(*_pt), sizeof(*_pt))) ? ((*_pt = type), 0) : -1; }\
426 : static inline int N ## _add_value(NS ## builder_t *B, TN ## _union_ref_t uref)\
427 : { NS ## ref_t *p; if (uref.type == TN ## _NONE) return 0; return (p = flatcc_builder_table_add_offset(B, ID)) ?\
428 : ((*p = uref.value), 0) : -1; }\
429 : static inline int N ## _clone(NS ## builder_t *B, TN ## _union_t p)\
430 : { return N ## _add(B, TN ## _clone(B, p)); }\
431 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
432 : { TN ## _union_t _p = N ## _union(t); return _p.type ? N ## _clone(B, _p) : 0; }
433 :
434 : /* M is the union value name and T is its type, i.e. the qualified name. */
435 : #define __flatbuffers_build_union_table_value_field(NS, N, NU, M, T)\
436 : static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\
437 : { return N ## _add(B, NU ## _as_ ## M (ref)); }\
438 : static inline int N ## _ ## M ## _start(NS ## builder_t *B)\
439 : { return T ## _start(B); }\
440 : static inline int N ## _ ## M ## _end(NS ## builder_t *B)\
441 : { T ## _ref_t ref = T ## _end(B);\
442 : return ref ? N ## _ ## M ## _add(B, ref) : -1; }\
443 : static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\
444 : { T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\
445 : return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
446 : static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _table_t t)\
447 : { T ## _ref_t ref = T ## _clone(B, t);\
448 : return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }
449 :
450 : /* M is the union value name and T is its type, i.e. the qualified name. */
451 : #define __flatbuffers_build_union_struct_value_field(NS, N, NU, M, T)\
452 : static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\
453 : { return N ## _add(B, NU ## _as_ ## M (ref)); }\
454 : static inline T ## _t *N ## _ ## M ## _start(NS ## builder_t *B)\
455 : { return T ## _start(B); }\
456 : static inline int N ## _ ## M ## _end(NS ## builder_t *B)\
457 : { T ## _ref_t ref = T ## _end(B);\
458 : return ref ? N ## _ ## M ## _add(B, ref) : -1; }\
459 : static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\
460 : { T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\
461 : return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
462 : static inline int N ## _ ## M ## _end_pe(NS ## builder_t *B)\
463 : { T ## _ref_t ref = T ## _end_pe(B);\
464 : return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
465 : static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _struct_t p)\
466 : { T ## _ref_t ref = T ## _clone(B, p);\
467 : return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }
468 : #define __flatbuffers_build_union_string_value_field(NS, N, NU, M)\
469 : static inline int N ## _ ## M ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
470 : { return N ## _add(B, NU ## _as_ ## M (ref)); }\
471 : __flatbuffers_build_string_field_ops(NS, N ## _ ## M)
472 :
473 : /* NS: common namespace, ID: table field id (not offset), TN: name of type T, TT: name of table type
474 : * S: sizeof of scalar type, A: alignment of type T, default value V of type T. */
475 : #define __flatbuffers_build_scalar_field(ID, NS, N, TN, T, S, A, V, TT)\
476 0 : static inline int N ## _add(NS ## builder_t *B, const T v)\
477 0 : { T *_p; if (v == V) return 0; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
478 0 : TN ## _assign_to_pe(_p, v); return 0; }\
479 0 : static inline int N ## _force_add(NS ## builder_t *B, const T v)\
480 0 : { T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
481 0 : TN ## _assign_to_pe(_p, v); return 0; }\
482 : /* Clone does not skip default values and expects pe endian content. */\
483 0 : static inline int N ## _clone(NS ## builder_t *B, const T *p)\
484 0 : { return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\
485 : /* Transferring a missing field is a nop success with 0 as result. */\
486 0 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
487 0 : { const T *_p = N ## _get_ptr(t); return _p ? N ## _clone(B, _p) : 0; }
488 :
489 : /* NS: common namespace, ID: table field id (not offset), TN: name of type T, TT: name of table type
490 : * S: sizeof of scalar type, A: alignment of type T. */
491 : #define __flatbuffers_build_scalar_optional_field(ID, NS, N, TN, T, S, A, TT)\
492 : static inline int N ## _add(NS ## builder_t *B, const T v)\
493 : { T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
494 : TN ## _assign_to_pe(_p, v); return 0; }\
495 : /* Clone does not skip default values and expects pe endian content. */\
496 : static inline int N ## _clone(NS ## builder_t *B, const T *p)\
497 : { return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\
498 : /* Transferring a missing field is a nop success with 0 as result. */\
499 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
500 : { const T *_p = N ## _get_ptr(t); return _p ? N ## _clone(B, _p) : 0; }
501 :
502 : #define __flatbuffers_build_struct_field(ID, NS, N, TN, S, A, TT)\
503 0 : static inline TN ## _t *N ## _start(NS ## builder_t *B)\
504 0 : { return (TN ## _t *)flatcc_builder_table_add(B, ID, S, A); }\
505 0 : static inline int N ## _end(NS ## builder_t *B)\
506 0 : { if (!NS ## is_native_pe()) { TN ## _to_pe((TN ## _t *)flatcc_builder_table_edit(B, S)); } return 0; }\
507 0 : static inline int N ## _end_pe(NS ## builder_t *B) { return 0; }\
508 0 : static inline int N ## _create(NS ## builder_t *B __ ## TN ## _formal_args)\
509 0 : { TN ## _t *_p = N ## _start(B); if (!_p) return -1; TN ##_assign_to_pe(_p __ ## TN ## _call_args);\
510 0 : return 0; }\
511 0 : static inline int N ## _add(NS ## builder_t *B, const TN ## _t *p)\
512 0 : { TN ## _t *_p = N ## _start(B); if (!_p) return -1; TN ##_copy_to_pe(_p, p); return 0; }\
513 0 : static inline int N ## _clone(NS ## builder_t *B, TN ## _struct_t p)\
514 0 : { return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\
515 0 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
516 0 : { TN ## _struct_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
517 :
518 : #define __flatbuffers_build_vector_field(ID, NS, N, TN, T, TT)\
519 0 : static inline int N ## _add(NS ## builder_t *B, TN ## _vec_ref_t ref)\
520 0 : { TN ## _vec_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
521 0 : static inline int N ## _start(NS ## builder_t *B)\
522 0 : { return TN ## _vec_start(B); }\
523 0 : static inline int N ## _end_pe(NS ## builder_t *B)\
524 0 : { return N ## _add(B, TN ## _vec_end_pe(B)); }\
525 0 : static inline int N ## _end(NS ## builder_t *B)\
526 0 : { return N ## _add(B, TN ## _vec_end(B)); }\
527 0 : static inline int N ## _create_pe(NS ## builder_t *B, const T *data, size_t len)\
528 0 : { return N ## _add(B, TN ## _vec_create_pe(B, data, len)); }\
529 0 : static inline int N ## _create(NS ## builder_t *B, const T *data, size_t len)\
530 0 : { return N ## _add(B, TN ## _vec_create(B, data, len)); }\
531 0 : static inline int N ## _slice(NS ## builder_t *B, TN ## _vec_t vec, size_t index, size_t len)\
532 0 : { return N ## _add(B, TN ## _vec_slice(B, vec, index, len)); }\
533 0 : static inline int N ## _clone(NS ## builder_t *B, TN ## _vec_t vec)\
534 0 : { return N ## _add(B, TN ## _vec_clone(B, vec)); }\
535 0 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
536 0 : { TN ## _vec_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }\
537 : __flatbuffers_build_vector_ops(NS, N, N, TN, T)\
538 :
539 : #define __flatbuffers_build_offset_vector_field(ID, NS, N, TN, TT)\
540 : static inline int N ## _add(NS ## builder_t *B, TN ## _vec_ref_t ref)\
541 : { TN ## _vec_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
542 : static inline int N ## _start(NS ## builder_t *B)\
543 : { return flatcc_builder_start_offset_vector(B); }\
544 : static inline int N ## _end(NS ## builder_t *B)\
545 : { return N ## _add(B, flatcc_builder_end_offset_vector(B)); }\
546 : static inline int N ## _create(NS ## builder_t *B, const TN ## _ref_t *data, size_t len)\
547 : { return N ## _add(B, flatcc_builder_create_offset_vector(B, data, len)); }\
548 : __flatbuffers_build_offset_vector_ops(NS, N, N, TN)\
549 : static inline int N ## _clone(NS ## builder_t *B, TN ## _vec_t vec)\
550 : { return N ## _add(B, TN ## _vec_clone(B, vec)); }\
551 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
552 : { TN ## _vec_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
553 :
554 : /* depends on N ## _add which differs for union member fields and ordinary fields */\
555 : #define __flatbuffers_build_string_field_ops(NS, N)\
556 0 : static inline int N ## _start(NS ## builder_t *B)\
557 0 : { return flatcc_builder_start_string(B); }\
558 0 : static inline int N ## _end(NS ## builder_t *B)\
559 0 : { return N ## _add(B, flatcc_builder_end_string(B)); }\
560 0 : static inline int N ## _create(NS ## builder_t *B, const char *s, size_t len)\
561 0 : { return N ## _add(B, flatcc_builder_create_string(B, s, len)); }\
562 0 : static inline int N ## _create_str(NS ## builder_t *B, const char *s)\
563 0 : { return N ## _add(B, flatcc_builder_create_string_str(B, s)); }\
564 0 : static inline int N ## _create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
565 0 : { return N ## _add(B, flatcc_builder_create_string_strn(B, s, max_len)); }\
566 0 : static inline int N ## _clone(NS ## builder_t *B, NS ## string_t string)\
567 0 : { return N ## _add(B, NS ## string_clone(B, string)); }\
568 0 : static inline int N ## _slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
569 0 : { return N ## _add(B, NS ## string_slice(B, string, index, len)); }\
570 : __flatbuffers_build_string_ops(NS, N)
571 :
572 : #define __flatbuffers_build_string_field(ID, NS, N, TT)\
573 0 : static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
574 0 : { NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
575 : __flatbuffers_build_string_field_ops(NS, N)\
576 0 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
577 0 : { NS ## string_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
578 :
579 : #define __flatbuffers_build_table_vector_field(ID, NS, N, TN, TT)\
580 : __flatbuffers_build_offset_vector_field(ID, NS, N, TN, TT)\
581 : __flatbuffers_build_table_vector_ops(NS, N, TN)
582 :
583 : #define __flatbuffers_build_union_vector_field(ID, NS, N, TN, TT)\
584 : static inline int N ## _add(NS ## builder_t *B, TN ## _union_vec_ref_t uvref)\
585 : { NS ## vec_ref_t *_p; if (!uvref.type || !uvref.value) return uvref.type == uvref.value ? 0 : -1;\
586 : if (!(_p = flatcc_builder_table_add_offset(B, ID - 1))) return -1; *_p = uvref.type;\
587 : if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uvref.value; return 0; }\
588 : static inline int N ## _start(NS ## builder_t *B)\
589 : { return flatcc_builder_start_union_vector(B); }\
590 : static inline int N ## _end(NS ## builder_t *B)\
591 : { return N ## _add(B, flatcc_builder_end_union_vector(B)); }\
592 : static inline int N ## _create(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\
593 : { return N ## _add(B, flatcc_builder_create_union_vector(B, data, len)); }\
594 : __flatbuffers_build_union_vector_ops(NS, N, N, TN)\
595 : static inline int N ## _clone(NS ## builder_t *B, TN ## _union_vec_t vec)\
596 : { return N ## _add(B, TN ## _vec_clone(B, vec)); }\
597 : static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
598 : { TN ## _union_vec_t _p = N ## _union(t); return _p.type ? N ## _clone(B, _p) : 0; }
599 :
600 : #define __flatbuffers_build_union_table_vector_value_field(NS, N, NU, M, T)\
601 : static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\
602 : { return T ## _start(B); }\
603 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
604 : { return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\
605 : static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\
606 : { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
607 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\
608 : { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }\
609 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, T ## _table_t t)\
610 : { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _clone(B, t))); }
611 :
612 : #define __flatbuffers_build_union_struct_vector_value_field(NS, N, NU, M, T)\
613 : static inline T ## _t *N ## _ ## M ## _push_start(NS ## builder_t *B)\
614 : { return T ## _start(B); }\
615 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
616 : { return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\
617 : static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\
618 : { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
619 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\
620 : { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }\
621 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, T ## _struct_t p)\
622 : { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _clone(B, p))); }
623 :
624 : #define __flatbuffers_build_union_string_vector_value_field(NS, N, NU, M)\
625 : static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, NS ## string_ref_t ref)\
626 : { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
627 : static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\
628 : { return NS ## string_start(B); }\
629 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
630 : { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_end(B))); }\
631 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B, const char *s, size_t len)\
632 : { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create(B, s, len))); }\
633 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_str(NS ## builder_t *B, const char *s)\
634 : { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_str(B, s))); }\
635 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
636 : { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_strn(B, s, max_len))); }\
637 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, NS ## string_t string)\
638 : { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_clone(B, string))); }\
639 : static inline NU ## _union_ref_t *N ## _ ## M ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
640 : { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_slice(B, string, index, len))); }
641 :
642 : #define __flatbuffers_build_string_vector_field(ID, NS, N, TT)\
643 : __flatbuffers_build_offset_vector_field(ID, NS, N, NS ## string, TT)\
644 : __flatbuffers_build_string_vector_ops(NS, N)
645 :
646 : #define __flatbuffers_char_formal_args , char v0
647 : #define __flatbuffers_char_call_args , v0
648 : #define __flatbuffers_uint8_formal_args , uint8_t v0
649 : #define __flatbuffers_uint8_call_args , v0
650 : #define __flatbuffers_int8_formal_args , int8_t v0
651 : #define __flatbuffers_int8_call_args , v0
652 : #define __flatbuffers_bool_formal_args , flatbuffers_bool_t v0
653 : #define __flatbuffers_bool_call_args , v0
654 : #define __flatbuffers_uint16_formal_args , uint16_t v0
655 : #define __flatbuffers_uint16_call_args , v0
656 : #define __flatbuffers_uint32_formal_args , uint32_t v0
657 : #define __flatbuffers_uint32_call_args , v0
658 : #define __flatbuffers_uint64_formal_args , uint64_t v0
659 : #define __flatbuffers_uint64_call_args , v0
660 : #define __flatbuffers_int16_formal_args , int16_t v0
661 : #define __flatbuffers_int16_call_args , v0
662 : #define __flatbuffers_int32_formal_args , int32_t v0
663 : #define __flatbuffers_int32_call_args , v0
664 : #define __flatbuffers_int64_formal_args , int64_t v0
665 : #define __flatbuffers_int64_call_args , v0
666 : #define __flatbuffers_float_formal_args , float v0
667 : #define __flatbuffers_float_call_args , v0
668 : #define __flatbuffers_double_formal_args , double v0
669 : #define __flatbuffers_double_call_args , v0
670 :
671 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_char, char)
672 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint8, uint8_t)
673 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int8, int8_t)
674 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_bool, flatbuffers_bool_t)
675 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint16, uint16_t)
676 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint32, uint32_t)
677 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint64, uint64_t)
678 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int16, int16_t)
679 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int32, int32_t)
680 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int64, int64_t)
681 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_float, float)
682 : __flatbuffers_build_scalar(flatbuffers_, flatbuffers_double, double)
683 :
684 : __flatbuffers_build_string(flatbuffers_)
685 :
686 : __flatbuffers_build_buffer(flatbuffers_)
687 : #include "flatcc/flatcc_epilogue.h"
688 : #endif /* FLATBUFFERS_COMMON_BUILDER_H */
689 :
690 : #pragma GCC diagnostic pop
|