1 #ifndef FLATBUFFERS_BASE_H_ 2 #define FLATBUFFERS_BASE_H_ 5 #if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \ 6 defined(_MSC_VER) && defined(_DEBUG) 7 #define _CRTDBG_MAP_ALLOC 12 #if !defined(FLATBUFFERS_ASSERT) 13 #define FLATBUFFERS_ASSERT assert 24 #if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \ 25 defined(_MSC_VER) && defined(_DEBUG) 27 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 31 #if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) 38 #include <type_traits> 45 #ifdef _STLPORT_VERSION 46 #define FLATBUFFERS_CPP98_STL 48 #ifndef FLATBUFFERS_CPP98_STL 55 #if __cplusplus <= 199711L && \ 56 (!defined(_MSC_VER) || _MSC_VER < 1600) && \ 57 (!defined(__GNUC__) || \ 58 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400)) 59 #error A C++11 compatible compiler with support for the auto typing is \ 60 required for FlatBuffers. 61 #error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ 64 #if !defined(__clang__) && \ 65 defined(__GNUC__) && \ 66 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600) 71 const class nullptr_t {
73 template<
class T>
inline operator T*()
const {
return 0; }
75 void operator&()
const;
79 #define constexpr const 85 #if defined(__s390x__) 86 #define FLATBUFFERS_LITTLEENDIAN 0 88 #if !defined(FLATBUFFERS_LITTLEENDIAN) 89 #if defined(__GNUC__) || defined(__clang__) 91 #define FLATBUFFERS_LITTLEENDIAN 0 93 #define FLATBUFFERS_LITTLEENDIAN 1 94 #endif // __BIG_ENDIAN__ 95 #elif defined(_MSC_VER) 97 #define FLATBUFFERS_LITTLEENDIAN 0 99 #define FLATBUFFERS_LITTLEENDIAN 1 102 #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN. 104 #endif // !defined(FLATBUFFERS_LITTLEENDIAN) 106 #define FLATBUFFERS_VERSION_MAJOR 1 107 #define FLATBUFFERS_VERSION_MINOR 9 108 #define FLATBUFFERS_VERSION_REVISION 0 109 #define FLATBUFFERS_STRING_EXPAND(X) #X 110 #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) 112 #if (!defined(_MSC_VER) || _MSC_VER > 1600) && \ 113 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) 114 #define FLATBUFFERS_FINAL_CLASS final 115 #define FLATBUFFERS_OVERRIDE override 117 #define FLATBUFFERS_FINAL_CLASS 118 #define FLATBUFFERS_OVERRIDE 121 #if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \ 122 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) 123 #define FLATBUFFERS_CONSTEXPR constexpr 125 #define FLATBUFFERS_CONSTEXPR 128 #if (defined(__cplusplus) && __cplusplus >= 201402L) || \ 129 (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) 130 #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR 132 #define FLATBUFFERS_CONSTEXPR_CPP14 135 #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \ 136 defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 137 #define FLATBUFFERS_NOEXCEPT noexcept 139 #define FLATBUFFERS_NOEXCEPT 144 #if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \ 145 (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) 146 #define FLATBUFFERS_DELETE_FUNC(func) func = delete; 148 #define FLATBUFFERS_DELETE_FUNC(func) private: func; 151 #if defined(_MSC_VER) 152 #pragma warning(push) 153 #pragma warning(disable: 4127) // C4127: conditional expression is constant 156 #ifndef FLATBUFFERS_HAS_STRING_VIEW 159 #if defined(__has_include) 161 #if __has_include(<string_view>) && (__cplusplus > 201402) 162 #include <string_view> 164 typedef std::string_view string_view;
166 #define FLATBUFFERS_HAS_STRING_VIEW 1 168 #elif __has_include(<experimental/string_view>) && (__cplusplus > 201103) 169 #include <experimental/string_view> 171 typedef std::experimental::string_view string_view;
173 #define FLATBUFFERS_HAS_STRING_VIEW 1 175 #endif // __has_include 176 #endif // !FLATBUFFERS_HAS_STRING_VIEW 187 typedef uint32_t uoffset_t;
190 typedef int32_t soffset_t;
194 typedef uint16_t voffset_t;
196 typedef uintmax_t largest_scalar_t;
199 #define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(soffset_t) * 8 - 1)) - 1) 202 #define FLATBUFFERS_MAX_ALIGNMENT 16 204 template<
typename T> T EndianSwap(T t) {
205 #if defined(_MSC_VER) 206 #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort 207 #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong 208 #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64 210 #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__) 212 #define FLATBUFFERS_BYTESWAP16(x) \ 213 static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16)) 215 #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16 217 #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32 218 #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64 220 if (
sizeof(T) == 1) {
222 }
else if (
sizeof(T) == 2) {
223 union { T t; uint16_t i; } u;
225 u.i = FLATBUFFERS_BYTESWAP16(u.i);
227 }
else if (
sizeof(T) == 4) {
228 union { T t; uint32_t i; } u;
230 u.i = FLATBUFFERS_BYTESWAP32(u.i);
232 }
else if (
sizeof(T) == 8) {
233 union { T t; uint64_t i; } u;
235 u.i = FLATBUFFERS_BYTESWAP64(u.i);
243 template<
typename T> T EndianScalar(T t) {
244 #if FLATBUFFERS_LITTLEENDIAN 247 return EndianSwap(t);
251 template<
typename T> T ReadScalar(
const void *p) {
252 return EndianScalar(*reinterpret_cast<const T *>(p));
255 template<
typename T>
void WriteScalar(
void *p, T t) {
256 *
reinterpret_cast<T *
>(p) = EndianScalar(t);
262 inline size_t PaddingBytes(
size_t buf_size,
size_t scalar_size) {
263 return ((~buf_size) + 1) & (scalar_size - 1);
267 #endif // FLATBUFFERS_BASE_H_
#define FLATBUFFERS_ASSERT