base.h
Go to the documentation of this file.
00001 #ifndef FLATBUFFERS_BASE_H_
00002 #define FLATBUFFERS_BASE_H_
00003 
00004 // clang-format off
00005 
00006 // If activate should be declared and included first.
00007 #if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
00008     defined(_MSC_VER) && defined(_DEBUG)
00009   // The _CRTDBG_MAP_ALLOC inside <crtdbg.h> will replace
00010   // calloc/free (etc) to its debug version using #define directives.
00011   #define _CRTDBG_MAP_ALLOC
00012   #include <stdlib.h>
00013   #include <crtdbg.h>
00014   // Replace operator new by trace-enabled version.
00015   #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
00016   #define new DEBUG_NEW
00017 #endif
00018 
00019 #if !defined(FLATBUFFERS_ASSERT)
00020 #include <assert.h>
00021 #define FLATBUFFERS_ASSERT assert
00022 #elif defined(FLATBUFFERS_ASSERT_INCLUDE)
00023 // Include file with forward declaration
00024 #include FLATBUFFERS_ASSERT_INCLUDE
00025 #endif
00026 
00027 #ifndef ARDUINO
00028 #include <cstdint>
00029 #endif
00030 
00031 #include <cstddef>
00032 #include <cstdlib>
00033 #include <cstring>
00034 
00035 #if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
00036   #include <utility.h>
00037 #else
00038   #include <utility>
00039 #endif
00040 
00041 #include <string>
00042 #include <type_traits>
00043 #include <vector>
00044 #include <set>
00045 #include <algorithm>
00046 #include <iterator>
00047 #include <memory>
00048 
00049 #ifdef _STLPORT_VERSION
00050   #define FLATBUFFERS_CPP98_STL
00051 #endif
00052 #ifndef FLATBUFFERS_CPP98_STL
00053   #include <functional>
00054 #endif
00055 
00056 #include "flatbuffers/stl_emulation.h"
00057 
00058 // Note the __clang__ check is needed, because clang presents itself
00059 // as an older GNUC compiler (4.2).
00060 // Clang 3.3 and later implement all of the ISO C++ 2011 standard.
00061 // Clang 3.4 and later implement all of the ISO C++ 2014 standard.
00062 // http://clang.llvm.org/cxx_status.html
00063 
00064 // Note the MSVC value '__cplusplus' may be incorrect:
00065 // The '__cplusplus' predefined macro in the MSVC stuck at the value 199711L,
00066 // indicating (erroneously!) that the compiler conformed to the C++98 Standard.
00067 // This value should be correct starting from MSVC2017-15.7-Preview-3.
00068 // The '__cplusplus' will be valid only if MSVC2017-15.7-P3 and the `/Zc:__cplusplus` switch is set.
00069 // Workaround (for details see MSDN):
00070 // Use the _MSC_VER and _MSVC_LANG definition instead of the __cplusplus  for compatibility.
00071 // The _MSVC_LANG macro reports the Standard version regardless of the '/Zc:__cplusplus' switch.
00072 
00073 #if defined(__GNUC__) && !defined(__clang__)
00074   #define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
00075 #else
00076   #define FLATBUFFERS_GCC 0
00077 #endif
00078 
00079 #if defined(__clang__)
00080   #define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
00081 #else
00082   #define FLATBUFFERS_CLANG 0
00083 #endif
00084 
00086 #if __cplusplus <= 199711L && \
00087     (!defined(_MSC_VER) || _MSC_VER < 1600) && \
00088     (!defined(__GNUC__) || \
00089       (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400))
00090   #error A C++11 compatible compiler with support for the auto typing is \
00091          required for FlatBuffers.
00092   #error __cplusplus _MSC_VER __GNUC__  __GNUC_MINOR__  __GNUC_PATCHLEVEL__
00093 #endif
00094 
00095 #if !defined(__clang__) && \
00096     defined(__GNUC__) && \
00097     (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600)
00098   // Backwards compatability for g++ 4.4, and 4.5 which don't have the nullptr
00099   // and constexpr keywords. Note the __clang__ check is needed, because clang
00100   // presents itself as an older GNUC compiler.
00101   #ifndef nullptr_t
00102     const class nullptr_t {
00103     public:
00104       template<class T> inline operator T*() const { return 0; }
00105     private:
00106       void operator&() const;
00107     } nullptr = {};
00108   #endif
00109   #ifndef constexpr
00110     #define constexpr const
00111   #endif
00112 #endif
00113 
00114 // The wire format uses a little endian encoding (since that's efficient for
00115 // the common platforms).
00116 #if defined(__s390x__)
00117   #define FLATBUFFERS_LITTLEENDIAN 0
00118 #endif // __s390x__
00119 #if !defined(FLATBUFFERS_LITTLEENDIAN)
00120   #if defined(__GNUC__) || defined(__clang__)
00121     #ifdef __BIG_ENDIAN__
00122       #define FLATBUFFERS_LITTLEENDIAN 0
00123     #else
00124       #define FLATBUFFERS_LITTLEENDIAN 1
00125     #endif // __BIG_ENDIAN__
00126   #elif defined(_MSC_VER)
00127     #if defined(_M_PPC)
00128       #define FLATBUFFERS_LITTLEENDIAN 0
00129     #else
00130       #define FLATBUFFERS_LITTLEENDIAN 1
00131     #endif
00132   #else
00133     #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN.
00134   #endif
00135 #endif // !defined(FLATBUFFERS_LITTLEENDIAN)
00136 
00137 #define FLATBUFFERS_VERSION_MAJOR 1
00138 #define FLATBUFFERS_VERSION_MINOR 10
00139 #define FLATBUFFERS_VERSION_REVISION 0
00140 #define FLATBUFFERS_STRING_EXPAND(X) #X
00141 #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
00142 
00143 #if (!defined(_MSC_VER) || _MSC_VER > 1600) && \
00144     (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \
00145     defined(__clang__)
00146   #define FLATBUFFERS_FINAL_CLASS final
00147   #define FLATBUFFERS_OVERRIDE override
00148   #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
00149 #else
00150   #define FLATBUFFERS_FINAL_CLASS
00151   #define FLATBUFFERS_OVERRIDE
00152   #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE
00153 #endif
00154 
00155 #if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
00156     (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
00157     (defined(__cpp_constexpr) && __cpp_constexpr >= 200704)
00158   #define FLATBUFFERS_CONSTEXPR constexpr
00159 #else
00160   #define FLATBUFFERS_CONSTEXPR const
00161 #endif
00162 
00163 #if (defined(__cplusplus) && __cplusplus >= 201402L) || \
00164     (defined(__cpp_constexpr) && __cpp_constexpr >= 201304)
00165   #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR
00166 #else
00167   #define FLATBUFFERS_CONSTEXPR_CPP14
00168 #endif
00169 
00170 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
00171     (defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \
00172     defined(__clang__)
00173   #define FLATBUFFERS_NOEXCEPT noexcept
00174 #else
00175   #define FLATBUFFERS_NOEXCEPT
00176 #endif
00177 
00178 // NOTE: the FLATBUFFERS_DELETE_FUNC macro may change the access mode to
00179 // private, so be sure to put it at the end or reset access mode explicitly.
00180 #if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
00181     (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \
00182     defined(__clang__)
00183   #define FLATBUFFERS_DELETE_FUNC(func) func = delete;
00184 #else
00185   #define FLATBUFFERS_DELETE_FUNC(func) private: func;
00186 #endif
00187 
00188 #ifndef FLATBUFFERS_HAS_STRING_VIEW
00189   // Only provide flatbuffers::string_view if __has_include can be used
00190   // to detect a header that provides an implementation
00191   #if defined(__has_include)
00192     // Check for std::string_view (in c++17)
00193     #if __has_include(<string_view>) && (__cplusplus >= 201606 || _HAS_CXX17)
00194       #include <string_view>
00195       namespace flatbuffers {
00196         typedef std::string_view string_view;
00197       }
00198       #define FLATBUFFERS_HAS_STRING_VIEW 1
00199     // Check for std::experimental::string_view (in c++14, compiler-dependent)
00200     #elif __has_include(<experimental/string_view>) && (__cplusplus >= 201411)
00201       #include <experimental/string_view>
00202       namespace flatbuffers {
00203         typedef std::experimental::string_view string_view;
00204       }
00205       #define FLATBUFFERS_HAS_STRING_VIEW 1
00206     #endif
00207   #endif // __has_include
00208 #endif // !FLATBUFFERS_HAS_STRING_VIEW
00209 
00210 #ifndef FLATBUFFERS_HAS_NEW_STRTOD
00211   // Modern (C++11) strtod and strtof functions are available for use.
00212   // 1) nan/inf strings as argument of strtod;
00213   // 2) hex-float  as argument of  strtod/strtof.
00214   #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
00215       (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \
00216       (defined(__clang__))
00217     #define FLATBUFFERS_HAS_NEW_STRTOD 1
00218   #endif
00219 #endif // !FLATBUFFERS_HAS_NEW_STRTOD
00220 
00221 #ifndef FLATBUFFERS_LOCALE_INDEPENDENT
00222   // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}.
00223   // They are part of the POSIX-2008 but not part of the C/C++ standard.
00224   // GCC/Clang have definition (_XOPEN_SOURCE>=700) if POSIX-2008.
00225   #if ((defined(_MSC_VER) && _MSC_VER >= 1800)            || \
00226        (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE>=700)))
00227     #define FLATBUFFERS_LOCALE_INDEPENDENT 1
00228   #else
00229     #define FLATBUFFERS_LOCALE_INDEPENDENT 0
00230   #endif
00231 #endif  // !FLATBUFFERS_LOCALE_INDEPENDENT
00232 
00233 // Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
00234 // - __supress_ubsan__("undefined")
00235 // - __supress_ubsan__("signed-integer-overflow")
00236 #if defined(__clang__)
00237   #define __supress_ubsan__(type) __attribute__((no_sanitize(type)))
00238 #elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
00239   #define __supress_ubsan__(type) __attribute__((no_sanitize_undefined))
00240 #else
00241   #define __supress_ubsan__(type)
00242 #endif
00243 
00244 // This is constexpr function used for checking compile-time constants.
00245 // Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
00246 template<typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) {
00247   return !!t;
00248 }
00249 
00250 // Enable C++ attribute [[]] if std:c++17 or higher.
00251 #if ((__cplusplus >= 201703L) \
00252     || (defined(_MSVC_LANG) &&  (_MSVC_LANG >= 201703L)))
00253   // All attributes unknown to an implementation are ignored without causing an error.
00254   #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]]
00255 
00256   #define FLATBUFFERS_FALLTHROUGH() [[fallthrough]]
00257 #else
00258   #define FLATBUFFERS_ATTRIBUTE(attr)
00259 
00260   #if FLATBUFFERS_CLANG >= 30800
00261     #define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]]
00262   #elif FLATBUFFERS_GCC >= 70300
00263     #define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]]
00264   #else
00265     #define FLATBUFFERS_FALLTHROUGH()
00266   #endif
00267 #endif
00268 
00270 
00272 namespace flatbuffers {
00273 
00275 // Our default offset / size type, 32bit on purpose on 64bit systems.
00276 // Also, using a consistent offset type maintains compatibility of serialized
00277 // offset values between 32bit and 64bit systems.
00278 typedef uint32_t uoffset_t;
00279 
00280 // Signed offsets for references that can go in both directions.
00281 typedef int32_t soffset_t;
00282 
00283 // Offset/index used in v-tables, can be changed to uint8_t in
00284 // format forks to save a bit of space if desired.
00285 typedef uint16_t voffset_t;
00286 
00287 typedef uintmax_t largest_scalar_t;
00288 
00289 // In 32bits, this evaluates to 2GB - 1
00290 #define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(soffset_t) * 8 - 1)) - 1)
00291 
00292 // We support aligning the contents of buffers up to this size.
00293 #define FLATBUFFERS_MAX_ALIGNMENT 16
00294 
00295 #if defined(_MSC_VER)
00296   #pragma warning(push)
00297   #pragma warning(disable: 4127) // C4127: conditional expression is constant
00298 #endif
00299 
00300 template<typename T> T EndianSwap(T t) {
00301   #if defined(_MSC_VER)
00302     #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort
00303     #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong
00304     #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64
00305   #else
00306     #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__)
00307       // __builtin_bswap16 was missing prior to GCC 4.8.
00308       #define FLATBUFFERS_BYTESWAP16(x) \
00309         static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
00310     #else
00311       #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16
00312     #endif
00313     #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32
00314     #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64
00315   #endif
00316   if (sizeof(T) == 1) {   // Compile-time if-then's.
00317     return t;
00318   } else if (sizeof(T) == 2) {
00319     union { T t; uint16_t i; } u;
00320     u.t = t;
00321     u.i = FLATBUFFERS_BYTESWAP16(u.i);
00322     return u.t;
00323   } else if (sizeof(T) == 4) {
00324     union { T t; uint32_t i; } u;
00325     u.t = t;
00326     u.i = FLATBUFFERS_BYTESWAP32(u.i);
00327     return u.t;
00328   } else if (sizeof(T) == 8) {
00329     union { T t; uint64_t i; } u;
00330     u.t = t;
00331     u.i = FLATBUFFERS_BYTESWAP64(u.i);
00332     return u.t;
00333   } else {
00334     FLATBUFFERS_ASSERT(0);
00335   }
00336 }
00337 
00338 #if defined(_MSC_VER)
00339   #pragma warning(pop)
00340 #endif
00341 
00342 
00343 template<typename T> T EndianScalar(T t) {
00344   #if FLATBUFFERS_LITTLEENDIAN
00345     return t;
00346   #else
00347     return EndianSwap(t);
00348   #endif
00349 }
00350 
00351 template<typename T>
00352 // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
00353 __supress_ubsan__("alignment")
00354 T ReadScalar(const void *p) {
00355   return EndianScalar(*reinterpret_cast<const T *>(p));
00356 }
00357 
00358 template<typename T>
00359 // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
00360 __supress_ubsan__("alignment")
00361 void WriteScalar(void *p, T t) {
00362   *reinterpret_cast<T *>(p) = EndianScalar(t);
00363 }
00364 
00365 // Computes how many bytes you'd have to pad to be able to write an
00366 // "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
00367 // memory).
00368 inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
00369   return ((~buf_size) + 1) & (scalar_size - 1);
00370 }
00371 
00372 }  // namespace flatbuffers
00373 #endif  // FLATBUFFERS_BASE_H_


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 20:17:15