1 #ifndef FLATBUFFERS_BASE_H_ 2 #define FLATBUFFERS_BASE_H_ 7 #if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \ 8 defined(_MSC_VER) && defined(_DEBUG) 11 #define _CRTDBG_MAP_ALLOC 15 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 19 #if !defined(FLATBUFFERS_ASSERT) 21 #define FLATBUFFERS_ASSERT assert 22 #elif defined(FLATBUFFERS_ASSERT_INCLUDE) 24 #include FLATBUFFERS_ASSERT_INCLUDE 35 #if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) 42 #include <type_traits> 49 #ifdef _STLPORT_VERSION 50 #define FLATBUFFERS_CPP98_STL 52 #ifndef FLATBUFFERS_CPP98_STL 73 #if defined(__GNUC__) && !defined(__clang__) 74 #define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 76 #define FLATBUFFERS_GCC 0 79 #if defined(__clang__) 80 #define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) 82 #define FLATBUFFERS_CLANG 0 86 #if __cplusplus <= 199711L && \ 87 (!defined(_MSC_VER) || _MSC_VER < 1600) && \ 88 (!defined(__GNUC__) || \ 89 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400)) 90 #error A C++11 compatible compiler with support for the auto typing is \ 91 required for FlatBuffers. 92 #error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ 95 #if !defined(__clang__) && \ 96 defined(__GNUC__) && \ 97 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600) 102 const class nullptr_t {
104 template<
class T>
inline operator T*()
const {
return 0; }
106 void operator&()
const;
110 #define constexpr const 116 #if defined(__s390x__) 117 #define FLATBUFFERS_LITTLEENDIAN 0 119 #if !defined(FLATBUFFERS_LITTLEENDIAN) 120 #if defined(__GNUC__) || defined(__clang__) 121 #ifdef __BIG_ENDIAN__ 122 #define FLATBUFFERS_LITTLEENDIAN 0 124 #define FLATBUFFERS_LITTLEENDIAN 1 125 #endif // __BIG_ENDIAN__ 126 #elif defined(_MSC_VER) 128 #define FLATBUFFERS_LITTLEENDIAN 0 130 #define FLATBUFFERS_LITTLEENDIAN 1 133 #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN. 135 #endif // !defined(FLATBUFFERS_LITTLEENDIAN) 137 #define FLATBUFFERS_VERSION_MAJOR 1 138 #define FLATBUFFERS_VERSION_MINOR 10 139 #define FLATBUFFERS_VERSION_REVISION 0 140 #define FLATBUFFERS_STRING_EXPAND(X) #X 141 #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) 143 #if (!defined(_MSC_VER) || _MSC_VER > 1600) && \ 144 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \ 146 #define FLATBUFFERS_FINAL_CLASS final 147 #define FLATBUFFERS_OVERRIDE override 148 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t 150 #define FLATBUFFERS_FINAL_CLASS 151 #define FLATBUFFERS_OVERRIDE 152 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE 155 #if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \ 156 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ 157 (defined(__cpp_constexpr) && __cpp_constexpr >= 200704) 158 #define FLATBUFFERS_CONSTEXPR constexpr 160 #define FLATBUFFERS_CONSTEXPR const 163 #if (defined(__cplusplus) && __cplusplus >= 201402L) || \ 164 (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) 165 #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR 167 #define FLATBUFFERS_CONSTEXPR_CPP14 170 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ 171 (defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \ 173 #define FLATBUFFERS_NOEXCEPT noexcept 175 #define FLATBUFFERS_NOEXCEPT 180 #if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \ 181 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \ 183 #define FLATBUFFERS_DELETE_FUNC(func) func = delete; 185 #define FLATBUFFERS_DELETE_FUNC(func) private: func; 188 #ifndef FLATBUFFERS_HAS_STRING_VIEW 191 #if defined(__has_include) 193 #if __has_include(<string_view>) && (__cplusplus >= 201606 || _HAS_CXX17) 194 #include <string_view> 196 typedef std::string_view string_view;
198 #define FLATBUFFERS_HAS_STRING_VIEW 1 200 #elif __has_include(<experimental/string_view>) && (__cplusplus >= 201411) 201 #include <experimental/string_view> 203 typedef std::experimental::string_view string_view;
205 #define FLATBUFFERS_HAS_STRING_VIEW 1 207 #endif // __has_include 208 #endif // !FLATBUFFERS_HAS_STRING_VIEW 210 #ifndef FLATBUFFERS_HAS_NEW_STRTOD 214 #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \ 215 (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \ 217 #define FLATBUFFERS_HAS_NEW_STRTOD 1 219 #endif // !FLATBUFFERS_HAS_NEW_STRTOD 221 #ifndef FLATBUFFERS_LOCALE_INDEPENDENT 225 #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \ 226 (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE>=700))) 227 #define FLATBUFFERS_LOCALE_INDEPENDENT 1 229 #define FLATBUFFERS_LOCALE_INDEPENDENT 0 231 #endif // !FLATBUFFERS_LOCALE_INDEPENDENT 236 #if defined(__clang__) 237 #define __supress_ubsan__(type) __attribute__((no_sanitize(type))) 238 #elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409) 239 #define __supress_ubsan__(type) __attribute__((no_sanitize_undefined)) 241 #define __supress_ubsan__(type) 246 template<
typename T> FLATBUFFERS_CONSTEXPR
inline bool IsConstTrue(T t) {
251 #if ((__cplusplus >= 201703L) \ 252 || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) 254 #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]] 256 #define FLATBUFFERS_FALLTHROUGH() [[fallthrough]] 258 #define FLATBUFFERS_ATTRIBUTE(attr) 260 #if FLATBUFFERS_CLANG >= 30800 261 #define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]] 262 #elif FLATBUFFERS_GCC >= 70300 263 #define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]] 265 #define FLATBUFFERS_FALLTHROUGH() 278 typedef uint32_t uoffset_t;
281 typedef int32_t soffset_t;
285 typedef uint16_t voffset_t;
287 typedef uintmax_t largest_scalar_t;
290 #define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(soffset_t) * 8 - 1)) - 1) 293 #define FLATBUFFERS_MAX_ALIGNMENT 16 295 #if defined(_MSC_VER) 296 #pragma warning(push) 297 #pragma warning(disable: 4127) // C4127: conditional expression is constant 300 template<
typename T> T EndianSwap(T t) {
301 #if defined(_MSC_VER) 302 #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort 303 #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong 304 #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64 306 #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__) 308 #define FLATBUFFERS_BYTESWAP16(x) \ 309 static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16)) 311 #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16 313 #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32 314 #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64 316 if (
sizeof(T) == 1) {
318 }
else if (
sizeof(T) == 2) {
319 union { T t; uint16_t i; } u;
321 u.i = FLATBUFFERS_BYTESWAP16(u.i);
323 }
else if (
sizeof(T) == 4) {
324 union { T t; uint32_t i; } u;
326 u.i = FLATBUFFERS_BYTESWAP32(u.i);
328 }
else if (
sizeof(T) == 8) {
329 union { T t; uint64_t i; } u;
331 u.i = FLATBUFFERS_BYTESWAP64(u.i);
338 #if defined(_MSC_VER) 343 template<
typename T> T EndianScalar(T t) {
344 #if FLATBUFFERS_LITTLEENDIAN 347 return EndianSwap(t);
354 T ReadScalar(
const void *p) {
355 return EndianScalar(*reinterpret_cast<const T *>(p));
361 void WriteScalar(
void *p, T t) {
362 *
reinterpret_cast<T *
>(p) = EndianScalar(t);
368 inline size_t PaddingBytes(
size_t buf_size,
size_t scalar_size) {
369 return ((~buf_size) + 1) & (scalar_size - 1);
373 #endif // FLATBUFFERS_BASE_H_ #define FLATBUFFERS_ASSERT
__supress_ubsan__("float-cast-overflow") inline void strtoval_impl(float *val