32
32
#include < cstdlib>
33
33
#include < cstring>
34
34
35
- #if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
35
+ #if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) && defined(__AVR__)
36
36
#include < utility.h>
37
37
#else
38
38
#include < utility>
43
43
#include < vector>
44
44
#include < set>
45
45
#include < algorithm>
46
+ #include < limits>
46
47
#include < iterator>
47
48
#include < memory>
48
49
49
50
#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT)
50
51
#include < unistd.h>
51
52
#endif
52
53
53
- #ifdef _STLPORT_VERSION
54
- #define FLATBUFFERS_CPP98_STL
55
- #endif
56
-
57
54
#ifdef __ANDROID__
58
55
#include < android/api-level.h>
59
56
#endif
142
139
#endif
143
140
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
144
141
145
- #define FLATBUFFERS_VERSION_MAJOR 1
146
- #define FLATBUFFERS_VERSION_MINOR 12
147
- #define FLATBUFFERS_VERSION_REVISION 0
142
+ #define FLATBUFFERS_VERSION_MAJOR 24
143
+ #define FLATBUFFERS_VERSION_MINOR 3
144
+ #define FLATBUFFERS_VERSION_REVISION 25
148
145
#define FLATBUFFERS_STRING_EXPAND (X ) #X
149
146
#define FLATBUFFERS_STRING (X ) FLATBUFFERS_STRING_EXPAND(X)
150
147
namespace flatbuffers {
@@ -158,7 +155,7 @@ namespace flatbuffers {
158
155
#define FLATBUFFERS_FINAL_CLASS final
159
156
#define FLATBUFFERS_OVERRIDE override
160
157
#define FLATBUFFERS_EXPLICIT_CPP11 explicit
161
- #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
158
+ #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : :: flatbuffers::voffset_t
162
159
#else
163
160
#define FLATBUFFERS_FINAL_CLASS
164
161
#define FLATBUFFERS_OVERRIDE
@@ -237,16 +234,26 @@ namespace flatbuffers {
237
234
}
238
235
#define FLATBUFFERS_HAS_STRING_VIEW 1
239
236
// Check for absl::string_view
240
- #elif __has_include("absl/strings/string_view.h")
241
- #include " absl/strings/string_view.h"
242
- namespace flatbuffers {
243
- typedef absl::string_view string_view;
244
- }
245
- #define FLATBUFFERS_HAS_STRING_VIEW 1
237
+ #elif __has_include("absl/strings/string_view.h") && \
238
+ __has_include (" absl/base/config.h" ) && \
239
+ (__cplusplus >= 201411 )
240
+ #include " absl/base/config.h"
241
+ #if !defined(ABSL_USES_STD_STRING_VIEW)
242
+ #include " absl/strings/string_view.h"
243
+ namespace flatbuffers {
244
+ typedef absl::string_view string_view;
245
+ }
246
+ #define FLATBUFFERS_HAS_STRING_VIEW 1
247
+ #endif
246
248
#endif
247
249
#endif // __has_include
248
250
#endif // !FLATBUFFERS_HAS_STRING_VIEW
249
251
252
+ #ifndef FLATBUFFERS_GENERAL_HEAP_ALLOC_OK
253
+ // Allow heap allocations to be used
254
+ #define FLATBUFFERS_GENERAL_HEAP_ALLOC_OK 1
255
+ #endif // !FLATBUFFERS_GENERAL_HEAP_ALLOC_OK
256
+
250
257
#ifndef FLATBUFFERS_HAS_NEW_STRTOD
251
258
// Modern (C++11) strtod and strtof functions are available for use.
252
259
// 1) nan/inf strings as argument of strtod;
@@ -259,37 +266,42 @@ namespace flatbuffers {
259
266
#endif // !FLATBUFFERS_HAS_NEW_STRTOD
260
267
261
268
#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
262
- // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}.
263
- #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \
264
- (defined(_XOPEN_VERSION) && (_XOPEN_VERSION>=700 )) && (!defined(__ANDROID_API__) || (defined(__ANDROID_API__) && (__ANDROID_API__>=21 ))))
269
+ // Enable locale independent functions {strtof_l, strtod_l,strtoll_l,
270
+ // strtoull_l}.
271
+ #if (defined(_MSC_VER) && _MSC_VER >= 1800) || \
272
+ (defined(__ANDROID_API__) && __ANDROID_API__>= 21 ) || \
273
+ (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700 )) && \
274
+ (!defined(__Fuchsia__) && !defined(__ANDROID_API__))
265
275
#define FLATBUFFERS_LOCALE_INDEPENDENT 1
266
276
#else
267
277
#define FLATBUFFERS_LOCALE_INDEPENDENT 0
268
278
#endif
269
279
#endif // !FLATBUFFERS_LOCALE_INDEPENDENT
270
280
271
281
// Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
272
- // - __supress_ubsan__ ("undefined")
273
- // - __supress_ubsan__ ("signed-integer-overflow")
282
+ // - FLATBUFFERS_SUPPRESS_UBSAN ("undefined")
283
+ // - FLATBUFFERS_SUPPRESS_UBSAN ("signed-integer-overflow")
274
284
#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
275
- #define __supress_ubsan__ (type ) __attribute__((no_sanitize(type)))
285
+ #define FLATBUFFERS_SUPPRESS_UBSAN (type ) __attribute__((no_sanitize(type)))
276
286
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
277
- #define __supress_ubsan__ (type ) __attribute__((no_sanitize_undefined))
287
+ #define FLATBUFFERS_SUPPRESS_UBSAN (type ) __attribute__((no_sanitize_undefined))
278
288
#else
279
- #define __supress_ubsan__ (type )
289
+ #define FLATBUFFERS_SUPPRESS_UBSAN (type )
280
290
#endif
281
291
282
- // This is constexpr function used for checking compile-time constants.
283
- // Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
284
- template <typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue (T t) {
285
- return !!t;
292
+ namespace flatbuffers {
293
+ // This is constexpr function used for checking compile-time constants.
294
+ // Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
295
+ template <typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue (T t) {
296
+ return !!t;
297
+ }
286
298
}
287
299
288
300
// Enable C++ attribute [[]] if std:c++17 or higher.
289
301
#if ((__cplusplus >= 201703L) \
290
302
|| (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L )))
291
303
// All attributes unknown to an implementation are ignored without causing an error.
292
- #define FLATBUFFERS_ATTRIBUTE (attr ) [[ attr]]
304
+ #define FLATBUFFERS_ATTRIBUTE (attr ) attr
293
305
294
306
#define FLATBUFFERS_FALLTHROUGH () [[fallthrough]]
295
307
#else
@@ -314,9 +326,11 @@ namespace flatbuffers {
314
326
// Also, using a consistent offset type maintains compatibility of serialized
315
327
// offset values between 32bit and 64bit systems.
316
328
typedef uint32_t uoffset_t ;
329
+ typedef uint64_t uoffset64_t ;
317
330
318
331
// Signed offsets for references that can go in both directions.
319
332
typedef int32_t soffset_t ;
333
+ typedef int64_t soffset64_t ;
320
334
321
335
// Offset/index used in v-tables, can be changed to uint8_t in
322
336
// format forks to save a bit of space if desired.
@@ -325,18 +339,30 @@ typedef uint16_t voffset_t;
325
339
typedef uintmax_t largest_scalar_t ;
326
340
327
341
// In 32bits, this evaluates to 2GB - 1
328
- #define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof (::flatbuffers::soffset_t ) * 8 - 1 )) - 1 )
342
+ #define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t >::max()
343
+ #define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t >::max()
344
+
345
+ // The minimum size buffer that can be a valid flatbuffer.
346
+ // Includes the offset to the root table (uoffset_t), the offset to the vtable
347
+ // of the root table (soffset_t), the size of the vtable (uint16_t), and the
348
+ // size of the referring table (uint16_t).
349
+ #define FLATBUFFERS_MIN_BUFFER_SIZE sizeof (uoffset_t ) + sizeof (soffset_t ) + \
350
+ sizeof (uint16_t ) + sizeof (uint16_t )
329
351
330
352
// We support aligning the contents of buffers up to this size.
331
- #define FLATBUFFERS_MAX_ALIGNMENT 16
353
+ #ifndef FLATBUFFERS_MAX_ALIGNMENT
354
+ #define FLATBUFFERS_MAX_ALIGNMENT 32
355
+ #endif
356
+
357
+ // / @brief The length of a FlatBuffer file header.
358
+ static const size_t kFileIdentifierLength = 4 ;
332
359
333
360
inline bool VerifyAlignmentRequirements (size_t align, size_t min_align = 1 ) {
334
361
return (min_align <= align) && (align <= (FLATBUFFERS_MAX_ALIGNMENT)) &&
335
362
(align & (align - 1 )) == 0 ; // must be power of 2
336
363
}
337
364
338
365
#if defined(_MSC_VER)
339
- #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized
340
366
#pragma warning(push)
341
367
#pragma warning(disable: 4127) // C4127: conditional expression is constant
342
368
#endif
@@ -397,7 +423,7 @@ template<typename T> T EndianScalar(T t) {
397
423
398
424
template <typename T>
399
425
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
400
- __supress_ubsan__ (" alignment" )
426
+ FLATBUFFERS_SUPPRESS_UBSAN (" alignment" )
401
427
T ReadScalar (const void *p) {
402
428
return EndianScalar (*reinterpret_cast <const T *>(p));
403
429
}
@@ -411,13 +437,13 @@ T ReadScalar(const void *p) {
411
437
412
438
template <typename T>
413
439
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
414
- __supress_ubsan__ (" alignment" )
440
+ FLATBUFFERS_SUPPRESS_UBSAN (" alignment" )
415
441
void WriteScalar (void *p, T t) {
416
442
*reinterpret_cast <T *>(p) = EndianScalar (t);
417
443
}
418
444
419
445
template <typename T> struct Offset ;
420
- template <typename T> __supress_ubsan__ (" alignment" ) void WriteScalar(void *p, Offset<T> t) {
446
+ template <typename T> FLATBUFFERS_SUPPRESS_UBSAN (" alignment" ) void WriteScalar(void *p, Offset<T> t) {
421
447
*reinterpret_cast <uoffset_t *>(p) = EndianScalar (t.o );
422
448
}
423
449
@@ -428,10 +454,43 @@ template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Of
428
454
// Computes how many bytes you'd have to pad to be able to write an
429
455
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
430
456
// memory).
431
- __supress_ubsan__ (" unsigned-integer-overflow" )
457
+ FLATBUFFERS_SUPPRESS_UBSAN (" unsigned-integer-overflow" )
432
458
inline size_t PaddingBytes (size_t buf_size, size_t scalar_size) {
433
459
return ((~buf_size) + 1 ) & (scalar_size - 1 );
434
460
}
435
461
462
+ // Generic 'operator==' with conditional specialisations.
463
+ // T e - new value of a scalar field.
464
+ // T def - default of scalar (is known at compile-time).
465
+ template <typename T> inline bool IsTheSameAs (T e, T def) { return e == def; }
466
+
467
+ #if defined(FLATBUFFERS_NAN_DEFAULTS) && \
468
+ defined (FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0 )
469
+ // Like `operator==(e, def)` with weak NaN if T=(float|double).
470
+ template<typename T> inline bool IsFloatTheSameAs(T e, T def) {
471
+ return (e == def) || ((def != def) && (e != e));
472
+ }
473
+ template <> inline bool IsTheSameAs<float >(float e, float def) {
474
+ return IsFloatTheSameAs (e, def);
475
+ }
476
+ template <> inline bool IsTheSameAs<double >(double e, double def) {
477
+ return IsFloatTheSameAs (e, def);
478
+ }
479
+ #endif
480
+
481
+ // Check 'v' is out of closed range [low; high].
482
+ // Workaround for GCC warning [-Werror=type-limits]:
483
+ // comparison is always true due to limited range of data type.
484
+ template <typename T>
485
+ inline bool IsOutRange (const T &v, const T &low, const T &high) {
486
+ return (v < low) || (high < v);
487
+ }
488
+
489
+ // Check 'v' is in closed range [low; high].
490
+ template <typename T>
491
+ inline bool IsInRange (const T &v, const T &low, const T &high) {
492
+ return !IsOutRange (v, low, high);
493
+ }
494
+
436
495
} // namespace flatbuffers
437
496
#endif // FLATBUFFERS_BASE_H_
0 commit comments