11#ifndef FLATBUFFERS_COMMON_BUILDER_H
22#define FLATBUFFERS_COMMON_BUILDER_H
33
4- /* Generated by flatcc 0.4.3 FlatBuffers schema compiler for C by dvide.com */
4+ /* Generated by flatcc 0.5.0 FlatBuffers schema compiler for C by dvide.com */
55
66/* Common FlatBuffers build functionality for C. */
77
1313typedef flatcc_builder_t flatbuffers_builder_t ;
1414typedef flatcc_builder_ref_t flatbuffers_ref_t ;
1515typedef flatcc_builder_ref_t flatbuffers_vec_ref_t ;
16+ typedef flatcc_builder_union_ref_t flatbuffers_union_ref_t ;
17+ typedef flatcc_builder_union_vec_ref_t flatbuffers_union_vec_ref_t ;
1618/* integer return code (ref and ptr always fail on 0) */
1719#define flatbuffers_failed (x ) ((x) < 0)
1820typedef flatbuffers_ref_t flatbuffers_root_t ;
@@ -85,7 +87,15 @@ static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B _
8587 N ## _create(B __ ## N ## _call_args), A, 0); }\
8688static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
8789{ return flatcc_builder_create_buffer(B, TFID, 0,\
88- N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }
90+ N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\
91+ static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _struct_t p)\
92+ { return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, 0); }\
93+ static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _struct_t p)\
94+ { return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }\
95+ static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _struct_t p)\
96+ { return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, 0); }\
97+ static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _struct_t p)\
98+ { return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }
8999
90100#define __flatbuffers_build_nested_table_root (NS , N , TN , FID , TFID )\
91101static inline int N ## _start_as_root(NS ## builder_t *B)\
@@ -169,6 +179,29 @@ static inline N ## _vec_ref_t N ## _vec_slice(NS ## builder_t *B, N ##_vec_t vec
169179 return flatcc_builder_create_vector(B, N ## __const_ptr_add(vec, index), len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
170180__flatbuffers_build_vector_ops(NS, N ## _vec, N, N, T)
171181
182+ #define __flatbuffers_build_union_vector_ops (NS , V , N , TN )\
183+ static inline TN ## _union_ref_t *V ## _extend(NS ## builder_t *B, size_t len)\
184+ { return flatcc_builder_extend_union_vector(B, len); }\
185+ static inline TN ## _union_ref_t *V ## _append(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\
186+ { return flatcc_builder_append_union_vector(B, data, len); }\
187+ static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
188+ { return flatcc_builder_truncate_union_vector(B, len); }\
189+ static inline TN ## _union_ref_t *V ## _edit(NS ## builder_t *B)\
190+ { return flatcc_builder_union_vector_edit(B); }\
191+ static inline size_t V ## _reserved_len(NS ## builder_t *B)\
192+ { return flatcc_builder_union_vector_count(B); }\
193+ static inline TN ## _union_ref_t *V ## _push(NS ## builder_t *B, const TN ## _union_ref_t ref)\
194+ { return flatcc_builder_union_vector_push(B, ref); }
195+
196+ #define __flatbuffers_build_union_vector (NS , N )\
197+ static inline int N ## _vec_start(NS ## builder_t *B)\
198+ { return flatcc_builder_start_union_vector(B); }\
199+ static inline N ## _union_vec_ref_t N ## _vec_end(NS ## builder_t *B)\
200+ { return flatcc_builder_end_union_vector(B); }\
201+ static inline N ## _union_vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _union_ref_t *data, size_t len)\
202+ { return flatcc_builder_create_union_vector(B, data, len); }\
203+ __flatbuffers_build_union_vector_ops(NS, N ## _vec, N, N)
204+
172205#define __flatbuffers_build_string_vector_ops (NS , N )\
173206static inline int N ## _push_start(NS ## builder_t *B)\
174207{ return NS ## string_start(B); }\
@@ -279,7 +312,7 @@ static inline N ## _t *N ##_to_pe(N ## _t *p)\
279312{ if (!NS ## is_native_pe()) { N ## _copy_to_pe(p, p); }; return p; }\
280313static inline N ## _t *N ##_from_pe(N ## _t *p)\
281314{ if (!NS ## is_native_pe()) { N ## _copy_from_pe(p, p); }; return p; }\
282- static inline N ## _t *N ## _clear(N ## _t *p) { return memset(p, 0, N ## __size()); }
315+ static inline N ## _t *N ## _clear(N ## _t *p) { return (N ## _t *) memset(p, 0, N ## __size()); }
283316
284317/* Depends on generated copy/assign_to/from_pe functions, and the type. */
285318#define __flatbuffers_build_struct (NS , N , S , A , FID , TFID )\
@@ -288,13 +321,16 @@ typedef NS ## ref_t N ## _ref_t;\
288321static inline N ## _t *N ## _start(NS ## builder_t *B)\
289322{ return (N ## _t *)flatcc_builder_start_struct(B, S, A); }\
290323static inline N ## _ref_t N ## _end(NS ## builder_t *B)\
291- { if (!NS ## is_native_pe()) { N ## _to_pe(flatcc_builder_struct_edit(B)); }\
324+ { if (!NS ## is_native_pe()) { N ## _to_pe((N ## _t *) flatcc_builder_struct_edit(B)); }\
292325 return flatcc_builder_end_struct(B); }\
293326static inline N ## _ref_t N ## _end_pe(NS ## builder_t *B)\
294327{ return flatcc_builder_end_struct(B); }\
295328static inline N ## _ref_t N ## _create(NS ## builder_t *B __ ## N ## _formal_args)\
296329{ N ## _t *_p = N ## _start(B); if (!_p) return 0; N ##_assign_to_pe(_p __ ## N ## _call_args);\
297330 return N ## _end_pe(B); }\
331+ static inline N ## _ref_t N ## _clone(NS ## builder_t *B, N ## _struct_t p)\
332+ { N ## _t *_p = N ## _start(B); if (!_p) return 0;\
333+ N ## _copy(_p, p); return N ##_end_pe(B); }\
298334__flatbuffers_build_vector(NS, N, N ## _t, S, A)\
299335__flatbuffers_build_struct_root(NS, N, A, FID, TFID)
300336
@@ -321,24 +357,52 @@ static inline TN ## _ref_t N ## _create(NS ## builder_t *B __ ## TN ##_formal_ar
321357
322358#define __flatbuffers_build_union_field (ID , NS , N , TN )\
323359static inline int N ## _add(NS ## builder_t *B, TN ## _union_ref_t uref)\
324- { NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref._member == 0) return -1;\
325- if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(_pt))) ||\
326- !(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_pt = uref.type; *_p = uref._member ; return 0; }\
360+ { NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref.member == 0) return -1;\
361+ if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(* _pt))) ||\
362+ !(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_pt = uref.type; *_p = uref.member ; return 0; }\
327363static inline int N ## _add_type(NS ## builder_t *B, TN ## _union_type_t type)\
328364{ TN ## _union_type_t *_pt; if (type == TN ## _NONE) return 0; return (_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1,\
329365 sizeof(*_pt), sizeof(*_pt))) ? ((*_pt = type), 0) : -1; }\
330366static inline int N ## _add_member(NS ## builder_t *B, TN ## _union_ref_t uref)\
331367{ NS ## ref_t *p; if (uref.type == TN ## _NONE) return 0; return (p = flatcc_builder_table_add_offset(B, ID)) ?\
332- ((*p = uref._member ), 0) : -1; }
368+ ((*p = uref.member ), 0) : -1; }
333369
334370/* M is the union member name and T is its type, i.e. the qualified name. */
335- #define __flatbuffers_build_union_member_field (NS , N , NU , M , T )\
371+ #define __flatbuffers_build_union_table_member_field (NS , N , NU , M , T )\
336372static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\
337373{ return N ## _add(B, NU ## _as_ ## M (ref)); }\
338374static inline int N ## _ ## M ## _start(NS ## builder_t *B)\
339375{ return T ## _start(B); }\
340376static inline int N ## _ ## M ## _end(NS ## builder_t *B)\
341- { return N ## _ ## M ## _add(B, T ## _end(B)); }
377+ { T ## _ref_t ref = T ## _end(B);\
378+ return ref ? N ## _ ## M ## _add(B, ref) : -1; }\
379+ static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\
380+ { T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\
381+ return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }
382+
383+ /* M is the union member name and T is its type, i.e. the qualified name. */
384+ #define __flatbuffers_build_union_struct_member_field (NS , N , NU , M , T )\
385+ static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\
386+ { return N ## _add(B, NU ## _as_ ## M (ref)); }\
387+ static inline T ## _t *N ## _ ## M ## _start(NS ## builder_t *B)\
388+ { return T ## _start(B); }\
389+ static inline int N ## _ ## M ## _end(NS ## builder_t *B)\
390+ { T ## _ref_t ref = T ## _end(B);\
391+ return ref ? N ## _ ## M ## _add(B, ref) : -1; }\
392+ static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\
393+ { T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\
394+ return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
395+ static inline int N ## _ ## M ## _end_pe(NS ## builder_t *B)\
396+ { T ## _ref_t ref = T ## _end_pe(B);\
397+ return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
398+ static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _struct_t p)\
399+ { T ## _ref_t ref = T ## _clone(B, p);\
400+ return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }
401+
402+ #define __flatbuffers_build_union_string_member_field (NS , N , NU , M )\
403+ static inline int N ## _ ## M ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
404+ { return N ## _add(B, NU ## _as_ ## M (ref)); }\
405+ __flatbuffers_build_string_field_ops(NS, N ## _ ## M)
342406
343407/* NS: common namespace, ID: table field id (not offset), TN: name of type T,
344408 * S: sizeof of scalar type, A: alignment of type T, default value V of type T. */
@@ -348,13 +412,13 @@ static inline int N ## _add(NS ## builder_t *B, const T v)\
348412 TN ## _assign_to_pe(_p, v); return 0; }\
349413static inline int N ## _force_add(NS ## builder_t *B, const T v)\
350414{ T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
351- TN ## _assign_to_pe(_p, v); return 0; }\
415+ TN ## _assign_to_pe(_p, v); return 0; }
352416
353417#define __flatbuffers_build_struct_field (ID , NS , N , TN , S , A )\
354418static inline TN ## _t *N ## _start(NS ## builder_t *B)\
355419{ return (TN ## _t *)flatcc_builder_table_add(B, ID, S, A); }\
356420static inline int N ## _end(NS ## builder_t *B)\
357- { if (!NS ## is_native_pe()) { TN ## _to_pe(flatcc_builder_table_edit(B, S)); } return 0; }\
421+ { if (!NS ## is_native_pe()) { TN ## _to_pe((TN ## _t *) flatcc_builder_table_edit(B, S)); } return 0; }\
358422static inline int N ## _end_pe(NS ## builder_t *B) { return 0; }\
359423static inline int N ## _create(NS ## builder_t *B __ ## TN ## _formal_args)\
360424{ TN ## _t *_p = N ## _start(B); if (!_p) return 0; TN ##_assign_to_pe(_p __ ## TN ## _call_args);\
@@ -394,9 +458,7 @@ static inline int N ## _create(NS ## builder_t *B, const TN ## _ref_t *data, siz
394458{ return N ## _add(B, flatcc_builder_create_offset_vector(B, data, len)); }\
395459__flatbuffers_build_offset_vector_ops(NS, N, N, TN)
396460
397- #define __flatbuffers_build_string_field (ID , NS , N )\
398- static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
399- { NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
461+ #define __flatbuffers_build_string_field_ops (NS , N )\
400462static inline int N ## _start(NS ## builder_t *B)\
401463{ return flatcc_builder_start_string(B); }\
402464static inline int N ## _end(NS ## builder_t *B)\
@@ -413,10 +475,66 @@ static inline int N ## _slice(NS ## builder_t *B, NS ## string_t string, size_t
413475{ return N ## _add(B, NS ## string_slice(B, string, index, len)); }\
414476__flatbuffers_build_string_ops(NS, N)
415477
478+ #define __flatbuffers_build_string_field (ID , NS , N )\
479+ static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
480+ { NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
481+ __flatbuffers_build_string_field_ops(NS, N)
482+
416483#define __flatbuffers_build_table_vector_field (ID , NS , N , TN )\
417484__flatbuffers_build_offset_vector_field(ID, NS, N, TN)\
418485__flatbuffers_build_table_vector_ops(NS, N, TN)
419486
487+ #define __flatbuffers_build_union_vector_field (ID , NS , N , TN )\
488+ static inline int N ## _add(NS ## builder_t *B, TN ## _union_vec_ref_t uvref)\
489+ { NS ## vec_ref_t *_p; if (!uvref.types || !uvref.members) return uvref.types == uvref.members ? 0 : -1;\
490+ if (!(_p = flatcc_builder_table_add_offset(B, ID - 1))) return -1; *_p = uvref.types;\
491+ if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uvref.members; return 0; }\
492+ static inline int N ## _start(NS ## builder_t *B)\
493+ { return flatcc_builder_start_union_vector(B); }\
494+ static inline int N ## _end(NS ## builder_t *B)\
495+ { return N ## _add(B, flatcc_builder_end_union_vector(B)); }\
496+ static inline int N ## _create(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\
497+ { return N ## _add(B, flatcc_builder_create_union_vector(B, data, len)); }\
498+ __flatbuffers_build_union_vector_ops(NS, N, N, TN)
499+
500+ #define __flatbuffers_build_union_table_vector_member_field (NS , N , NU , M , T )\
501+ static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\
502+ { return T ## _start(B); }\
503+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
504+ { return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\
505+ static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\
506+ { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
507+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\
508+ { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }
509+
510+ #define __flatbuffers_build_union_struct_vector_member_field (NS , N , NU , M , T )\
511+ static inline T ## _t *N ## _ ## M ## _push_start(NS ## builder_t *B)\
512+ { return T ## _start(B); }\
513+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
514+ { return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\
515+ static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\
516+ { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
517+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\
518+ { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }
519+
520+ #define __flatbuffers_build_union_string_vector_member_field (NS , N , NU , M )\
521+ static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, NS ## string_ref_t ref)\
522+ { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
523+ static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\
524+ { return NS ## string_start(B); }\
525+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
526+ { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_end(B))); }\
527+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B, const char *s, size_t len)\
528+ { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create(B, s, len))); }\
529+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_str(NS ## builder_t *B, const char *s)\
530+ { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_str(B, s))); }\
531+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
532+ { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_strn(B, s, max_len))); }\
533+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, NS ## string_t string)\
534+ { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_clone(B, string))); }\
535+ static inline NU ## _union_ref_t *N ## _ ## M ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
536+ { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_slice(B, string, index, len))); }
537+
420538#define __flatbuffers_build_string_vector_field (ID , NS , N )\
421539__flatbuffers_build_offset_vector_field(ID, NS, N, NS ## string)\
422540__flatbuffers_build_string_vector_ops(NS, N)
0 commit comments