17#ifndef FLATBUFFERS_BASE_H_
18#define FLATBUFFERS_BASE_H_
23#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
24 defined(_MSC_VER) && defined(_DEBUG)
27 #define _CRTDBG_MAP_ALLOC
31 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
35#if !defined(FLATBUFFERS_ASSERT)
37#define FLATBUFFERS_ASSERT assert
38#elif defined(FLATBUFFERS_ASSERT_INCLUDE)
40#include FLATBUFFERS_ASSERT_INCLUDE
51#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
65#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT)
69#ifdef _STLPORT_VERSION
70 #define FLATBUFFERS_CPP98_STL
74 #include <android/api-level.h>
77#if defined(__ICCARM__)
78#include <intrinsics.h>
96#if defined(__GNUC__) && !defined(__clang__)
97 #define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
99 #define FLATBUFFERS_GCC 0
102#if defined(__clang__)
103 #define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
105 #define FLATBUFFERS_CLANG 0
109#if __cplusplus <= 199711L && \
110 (!defined(_MSC_VER) || _MSC_VER < 1600) && \
111 (!defined(__GNUC__) || \
112 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400))
113 #error A C++11 compatible compiler with support for the auto typing is \
114 required for FlatBuffers.
115 #error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
118#if !defined(__clang__) && \
119 defined(__GNUC__) && \
120 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600)
125 const class nullptr_t {
127 template<
class T>
inline operator T*()
const {
return 0; }
129 void operator&()
const;
133 #define constexpr const
139#if defined(__s390x__)
140 #define FLATBUFFERS_LITTLEENDIAN 0
142#if !defined(FLATBUFFERS_LITTLEENDIAN)
143 #if defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__)
144 #if (defined(__BIG_ENDIAN__) || \
145 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
146 #define FLATBUFFERS_LITTLEENDIAN 0
148 #define FLATBUFFERS_LITTLEENDIAN 1
150 #elif defined(_MSC_VER)
152 #define FLATBUFFERS_LITTLEENDIAN 0
154 #define FLATBUFFERS_LITTLEENDIAN 1
157 #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN.
161#define FLATBUFFERS_VERSION_MAJOR 2
162#define FLATBUFFERS_VERSION_MINOR 0
163#define FLATBUFFERS_VERSION_REVISION 0
164#define FLATBUFFERS_STRING_EXPAND(X) #X
165#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
168 const char* FLATBUFFERS_VERSION();
171#if (!defined(_MSC_VER) || _MSC_VER > 1600) && \
172 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \
174 #define FLATBUFFERS_FINAL_CLASS final
175 #define FLATBUFFERS_OVERRIDE override
176 #define FLATBUFFERS_EXPLICIT_CPP11 explicit
177 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
179 #define FLATBUFFERS_FINAL_CLASS
180 #define FLATBUFFERS_OVERRIDE
181 #define FLATBUFFERS_EXPLICIT_CPP11
182 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE
185#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
186 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
187 (defined(__cpp_constexpr) && __cpp_constexpr >= 200704)
188 #define FLATBUFFERS_CONSTEXPR constexpr
189 #define FLATBUFFERS_CONSTEXPR_CPP11 constexpr
190 #define FLATBUFFERS_CONSTEXPR_DEFINED
192 #define FLATBUFFERS_CONSTEXPR const
193 #define FLATBUFFERS_CONSTEXPR_CPP11
196#if (defined(__cplusplus) && __cplusplus >= 201402L) || \
197 (defined(__cpp_constexpr) && __cpp_constexpr >= 201304)
198 #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR_CPP11
200 #define FLATBUFFERS_CONSTEXPR_CPP14
203#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
204 (defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \
206 #define FLATBUFFERS_NOEXCEPT noexcept
208 #define FLATBUFFERS_NOEXCEPT
213#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
214 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \
216 #define FLATBUFFERS_DELETE_FUNC(func) func = delete
218 #define FLATBUFFERS_DELETE_FUNC(func) private: func
221#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
222 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \
224 #define FLATBUFFERS_DEFAULT_DECLARATION
231#if (defined(_MSC_VER) && _MSC_VER > 1700 ) \
232 || (defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \
233 || (defined(__cplusplus) && __cplusplus >= 201103L)
234 #define FLATBUFFERS_TEMPLATES_ALIASES
237#ifndef FLATBUFFERS_HAS_STRING_VIEW
240 #if defined(__has_include)
242 #if __has_include(<string_view>) && (__cplusplus >= 201606 || (defined(_HAS_CXX17) && _HAS_CXX17))
243 #include <string_view>
245 typedef std::string_view string_view;
247 #define FLATBUFFERS_HAS_STRING_VIEW 1
249 #elif __has_include(<experimental/string_view>) && (__cplusplus >= 201411)
250 #include <experimental/string_view>
252 typedef std::experimental::string_view string_view;
254 #define FLATBUFFERS_HAS_STRING_VIEW 1
256 #elif __has_include("absl/strings/string_view.h")
257 #include "absl/strings/string_view.h"
259 typedef absl::string_view string_view;
261 #define FLATBUFFERS_HAS_STRING_VIEW 1
266#ifndef FLATBUFFERS_HAS_NEW_STRTOD
270 #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
271 (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \
273 #define FLATBUFFERS_HAS_NEW_STRTOD 1
277#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
279 #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \
280 (defined(_XOPEN_VERSION) && (_XOPEN_VERSION>=700)) && (!defined(__ANDROID_API__) || (defined(__ANDROID_API__) && (__ANDROID_API__>=21))))
281 #define FLATBUFFERS_LOCALE_INDEPENDENT 1
283 #define FLATBUFFERS_LOCALE_INDEPENDENT 0
290#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
291 #define __supress_ubsan__(type) __attribute__((no_sanitize(type)))
292#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
293 #define __supress_ubsan__(type) __attribute__((no_sanitize_undefined))
295 #define __supress_ubsan__(type)
300template<
typename T> FLATBUFFERS_CONSTEXPR
inline bool IsConstTrue(T t) {
305#if ((__cplusplus >= 201703L) \
306 || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
308 #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]]
310 #define FLATBUFFERS_FALLTHROUGH() [[fallthrough]]
312 #define FLATBUFFERS_ATTRIBUTE(attr)
314 #if FLATBUFFERS_CLANG >= 30800
315 #define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]]
316 #elif FLATBUFFERS_GCC >= 70300
317 #define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]]
319 #define FLATBUFFERS_FALLTHROUGH()
332typedef uint32_t uoffset_t;
335typedef int32_t soffset_t;
339typedef uint16_t voffset_t;
341typedef uintmax_t largest_scalar_t;
344#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(::flatbuffers::soffset_t) * 8 - 1)) - 1)
347#define FLATBUFFERS_MAX_ALIGNMENT 16
349inline bool VerifyAlignmentRequirements(
size_t align,
size_t min_align = 1) {
350 return (min_align <= align) && (align <= (FLATBUFFERS_MAX_ALIGNMENT)) &&
351 (align & (align - 1)) == 0;
355 #pragma warning(disable: 4351)
356 #pragma warning(push)
357 #pragma warning(disable: 4127)
360template<
typename T> T EndianSwap(T t) {
361 #if defined(_MSC_VER)
362 #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort
363 #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong
364 #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64
365 #elif defined(__ICCARM__)
366 #define FLATBUFFERS_BYTESWAP16 __REV16
367 #define FLATBUFFERS_BYTESWAP32 __REV
368 #define FLATBUFFERS_BYTESWAP64(x) \
369 ((__REV(static_cast<uint32_t>(x >> 32U))) | (static_cast<uint64_t>(__REV(static_cast<uint32_t>(x)))) << 32U)
371 #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__)
373 #define FLATBUFFERS_BYTESWAP16(x) \
374 static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
376 #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16
378 #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32
379 #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64
381 if (
sizeof(T) == 1) {
383 }
else if (
sizeof(T) == 2) {
384 union { T t; uint16_t i; } u = { t };
385 u.i = FLATBUFFERS_BYTESWAP16(u.i);
387 }
else if (
sizeof(T) == 4) {
388 union { T t; uint32_t i; } u = { t };
389 u.i = FLATBUFFERS_BYTESWAP32(u.i);
391 }
else if (
sizeof(T) == 8) {
392 union { T t; uint64_t i; } u = { t };
393 u.i = FLATBUFFERS_BYTESWAP64(u.i);
406template<
typename T> T EndianScalar(T t) {
407 #if FLATBUFFERS_LITTLEENDIAN
410 return EndianSwap(t);
417T ReadScalar(const
void *p) {
418 return EndianScalar(*
reinterpret_cast<const T *
>(p));
423#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
424 #pragma GCC diagnostic push
425 #pragma GCC diagnostic ignored "-Wstringop-overflow"
431void WriteScalar(
void *p, T t) {
432 *
reinterpret_cast<T *
>(p) = EndianScalar(t);
435template<
typename T>
struct Offset;
437 *
reinterpret_cast<uoffset_t *
>(p) = EndianScalar(t.o);
440#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
441 #pragma GCC diagnostic pop
448inline
size_t PaddingBytes(
size_t buf_size,
size_t scalar_size) {
449 return ((~buf_size) + 1) & (scalar_size - 1);
int Offset(const Dims< 4 > &dims, int i0, int i1, int i2, int i3)
#define FLATBUFFERS_ASSERT
__supress_ubsan__("float-cast-overflow") inline void strtoval_impl(float *val