3rdparty/flatbuffers/base.h
Go to the documentation of this file.
1 #ifndef FLATBUFFERS_BASE_H_
2 #define FLATBUFFERS_BASE_H_
3 
4 // clang-format off
5 
6 // If activate should be declared and included first.
7 #if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
8  defined(_MSC_VER) && defined(_DEBUG)
9  // The _CRTDBG_MAP_ALLOC inside <crtdbg.h> will replace
10  // calloc/free (etc) to its debug version using #define directives.
11  #define _CRTDBG_MAP_ALLOC
12  #include <stdlib.h>
13  #include <crtdbg.h>
14  // Replace operator new by trace-enabled version.
15  #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
16  #define new DEBUG_NEW
17 #endif
18 
19 #if !defined(FLATBUFFERS_ASSERT)
20 #include <assert.h>
21 #define FLATBUFFERS_ASSERT assert
22 #elif defined(FLATBUFFERS_ASSERT_INCLUDE)
23 // Include file with forward declaration
24 #include FLATBUFFERS_ASSERT_INCLUDE
25 #endif
26 
27 #ifndef ARDUINO
28 #include <cstdint>
29 #endif
30 
31 #include <cstddef>
32 #include <cstdlib>
33 #include <cstring>
34 
35 #if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
36  #include <utility.h>
37 #else
38  #include <utility>
39 #endif
40 
41 #include <string>
42 #include <type_traits>
43 #include <vector>
44 #include <set>
45 #include <algorithm>
46 #include <iterator>
47 #include <memory>
48 
49 #ifdef _STLPORT_VERSION
50  #define FLATBUFFERS_CPP98_STL
51 #endif
52 #ifndef FLATBUFFERS_CPP98_STL
53  #include <functional>
54 #endif
55 
57 
58 // Note the __clang__ check is needed, because clang presents itself
59 // as an older GNUC compiler (4.2).
60 // Clang 3.3 and later implement all of the ISO C++ 2011 standard.
61 // Clang 3.4 and later implement all of the ISO C++ 2014 standard.
62 // http://clang.llvm.org/cxx_status.html
63 
64 // Note the MSVC value '__cplusplus' may be incorrect:
65 // The '__cplusplus' predefined macro in the MSVC stuck at the value 199711L,
66 // indicating (erroneously!) that the compiler conformed to the C++98 Standard.
67 // This value should be correct starting from MSVC2017-15.7-Preview-3.
68 // The '__cplusplus' will be valid only if MSVC2017-15.7-P3 and the `/Zc:__cplusplus` switch is set.
69 // Workaround (for details see MSDN):
70 // Use the _MSC_VER and _MSVC_LANG definition instead of the __cplusplus for compatibility.
71 // The _MSVC_LANG macro reports the Standard version regardless of the '/Zc:__cplusplus' switch.
72 
73 #if defined(__GNUC__) && !defined(__clang__)
74  #define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
75 #else
76  #define FLATBUFFERS_GCC 0
77 #endif
78 
79 #if defined(__clang__)
80  #define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
81 #else
82  #define FLATBUFFERS_CLANG 0
83 #endif
84 
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__
93 #endif
94 
95 #if !defined(__clang__) && \
96  defined(__GNUC__) && \
97  (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600)
98  // Backwards compatability for g++ 4.4, and 4.5 which don't have the nullptr
99  // and constexpr keywords. Note the __clang__ check is needed, because clang
100  // presents itself as an older GNUC compiler.
101  #ifndef nullptr_t
102  const class nullptr_t {
103  public:
104  template<class T> inline operator T*() const { return 0; }
105  private:
106  void operator&() const;
107  } nullptr = {};
108  #endif
109  #ifndef constexpr
110  #define constexpr const
111  #endif
112 #endif
113 
114 // The wire format uses a little endian encoding (since that's efficient for
115 // the common platforms).
116 #if defined(__s390x__)
117  #define FLATBUFFERS_LITTLEENDIAN 0
118 #endif // __s390x__
119 #if !defined(FLATBUFFERS_LITTLEENDIAN)
120  #if defined(__GNUC__) || defined(__clang__)
121  #ifdef __BIG_ENDIAN__
122  #define FLATBUFFERS_LITTLEENDIAN 0
123  #else
124  #define FLATBUFFERS_LITTLEENDIAN 1
125  #endif // __BIG_ENDIAN__
126  #elif defined(_MSC_VER)
127  #if defined(_M_PPC)
128  #define FLATBUFFERS_LITTLEENDIAN 0
129  #else
130  #define FLATBUFFERS_LITTLEENDIAN 1
131  #endif
132  #else
133  #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN.
134  #endif
135 #endif // !defined(FLATBUFFERS_LITTLEENDIAN)
136 
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)
142 
143 #if (!defined(_MSC_VER) || _MSC_VER > 1600) && \
144  (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \
145  defined(__clang__)
146  #define FLATBUFFERS_FINAL_CLASS final
147  #define FLATBUFFERS_OVERRIDE override
148  #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
149 #else
150  #define FLATBUFFERS_FINAL_CLASS
151  #define FLATBUFFERS_OVERRIDE
152  #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE
153 #endif
154 
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
159 #else
160  #define FLATBUFFERS_CONSTEXPR const
161 #endif
162 
163 #if (defined(__cplusplus) && __cplusplus >= 201402L) || \
164  (defined(__cpp_constexpr) && __cpp_constexpr >= 201304)
165  #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR
166 #else
167  #define FLATBUFFERS_CONSTEXPR_CPP14
168 #endif
169 
170 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \
171  (defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \
172  defined(__clang__)
173  #define FLATBUFFERS_NOEXCEPT noexcept
174 #else
175  #define FLATBUFFERS_NOEXCEPT
176 #endif
177 
178 // NOTE: the FLATBUFFERS_DELETE_FUNC macro may change the access mode to
179 // private, so be sure to put it at the end or reset access mode explicitly.
180 #if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
181  (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \
182  defined(__clang__)
183  #define FLATBUFFERS_DELETE_FUNC(func) func = delete;
184 #else
185  #define FLATBUFFERS_DELETE_FUNC(func) private: func;
186 #endif
187 
188 #ifndef FLATBUFFERS_HAS_STRING_VIEW
189  // Only provide flatbuffers::string_view if __has_include can be used
190  // to detect a header that provides an implementation
191  #if defined(__has_include)
192  // Check for std::string_view (in c++17)
193  #if __has_include(<string_view>) && (__cplusplus >= 201606 || _HAS_CXX17)
194  #include <string_view>
195  namespace flatbuffers {
196  typedef std::string_view string_view;
197  }
198  #define FLATBUFFERS_HAS_STRING_VIEW 1
199  // Check for std::experimental::string_view (in c++14, compiler-dependent)
200  #elif __has_include(<experimental/string_view>) && (__cplusplus >= 201411)
201  #include <experimental/string_view>
202  namespace flatbuffers {
203  typedef std::experimental::string_view string_view;
204  }
205  #define FLATBUFFERS_HAS_STRING_VIEW 1
206  #endif
207  #endif // __has_include
208 #endif // !FLATBUFFERS_HAS_STRING_VIEW
209 
210 #ifndef FLATBUFFERS_HAS_NEW_STRTOD
211  // Modern (C++11) strtod and strtof functions are available for use.
212  // 1) nan/inf strings as argument of strtod;
213  // 2) hex-float as argument of strtod/strtof.
214  #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
215  (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \
216  (defined(__clang__))
217  #define FLATBUFFERS_HAS_NEW_STRTOD 1
218  #endif
219 #endif // !FLATBUFFERS_HAS_NEW_STRTOD
220 
221 #ifndef FLATBUFFERS_LOCALE_INDEPENDENT
222  // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}.
223  // They are part of the POSIX-2008 but not part of the C/C++ standard.
224  // GCC/Clang have definition (_XOPEN_SOURCE>=700) if POSIX-2008.
225  #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \
226  (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE>=700)))
227  #define FLATBUFFERS_LOCALE_INDEPENDENT 1
228  #else
229  #define FLATBUFFERS_LOCALE_INDEPENDENT 0
230  #endif
231 #endif // !FLATBUFFERS_LOCALE_INDEPENDENT
232 
233 // Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
234 // - __supress_ubsan__("undefined")
235 // - __supress_ubsan__("signed-integer-overflow")
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))
240 #else
241  #define __supress_ubsan__(type)
242 #endif
243 
244 // This is constexpr function used for checking compile-time constants.
245 // Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
246 template<typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) {
247  return !!t;
248 }
249 
250 // Enable C++ attribute [[]] if std:c++17 or higher.
251 #if ((__cplusplus >= 201703L) \
252  || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
253  // All attributes unknown to an implementation are ignored without causing an error.
254  #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]]
255 
256  #define FLATBUFFERS_FALLTHROUGH() [[fallthrough]]
257 #else
258  #define FLATBUFFERS_ATTRIBUTE(attr)
259 
260  #if FLATBUFFERS_CLANG >= 30800
261  #define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]]
262  #elif FLATBUFFERS_GCC >= 70300
263  #define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]]
264  #else
265  #define FLATBUFFERS_FALLTHROUGH()
266  #endif
267 #endif
268 
270 
272 namespace flatbuffers {
273 
275 // Our default offset / size type, 32bit on purpose on 64bit systems.
276 // Also, using a consistent offset type maintains compatibility of serialized
277 // offset values between 32bit and 64bit systems.
278 typedef uint32_t uoffset_t;
279 
280 // Signed offsets for references that can go in both directions.
281 typedef int32_t soffset_t;
282 
283 // Offset/index used in v-tables, can be changed to uint8_t in
284 // format forks to save a bit of space if desired.
285 typedef uint16_t voffset_t;
286 
287 typedef uintmax_t largest_scalar_t;
288 
289 // In 32bits, this evaluates to 2GB - 1
290 #define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(soffset_t) * 8 - 1)) - 1)
291 
292 // We support aligning the contents of buffers up to this size.
293 #define FLATBUFFERS_MAX_ALIGNMENT 16
294 
295 #if defined(_MSC_VER)
296  #pragma warning(push)
297  #pragma warning(disable: 4127) // C4127: conditional expression is constant
298 #endif
299 
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
305  #else
306  #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__)
307  // __builtin_bswap16 was missing prior to GCC 4.8.
308  #define FLATBUFFERS_BYTESWAP16(x) \
309  static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
310  #else
311  #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16
312  #endif
313  #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32
314  #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64
315  #endif
316  if (sizeof(T) == 1) { // Compile-time if-then's.
317  return t;
318  } else if (sizeof(T) == 2) {
319  union { T t; uint16_t i; } u;
320  u.t = t;
321  u.i = FLATBUFFERS_BYTESWAP16(u.i);
322  return u.t;
323  } else if (sizeof(T) == 4) {
324  union { T t; uint32_t i; } u;
325  u.t = t;
326  u.i = FLATBUFFERS_BYTESWAP32(u.i);
327  return u.t;
328  } else if (sizeof(T) == 8) {
329  union { T t; uint64_t i; } u;
330  u.t = t;
331  u.i = FLATBUFFERS_BYTESWAP64(u.i);
332  return u.t;
333  } else {
335  }
336 }
337 
338 #if defined(_MSC_VER)
339  #pragma warning(pop)
340 #endif
341 
342 
343 template<typename T> T EndianScalar(T t) {
344  #if FLATBUFFERS_LITTLEENDIAN
345  return t;
346  #else
347  return EndianSwap(t);
348  #endif
349 }
350 
351 template<typename T>
352 // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
353 __supress_ubsan__("alignment")
354 T ReadScalar(const void *p) {
355  return EndianScalar(*reinterpret_cast<const T *>(p));
356 }
357 
358 template<typename T>
359 // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
360 __supress_ubsan__("alignment")
361 void WriteScalar(void *p, T t) {
362  *reinterpret_cast<T *>(p) = EndianScalar(t);
363 }
364 
365 // Computes how many bytes you'd have to pad to be able to write an
366 // "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
367 // memory).
368 inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
369  return ((~buf_size) + 1) & (scalar_size - 1);
370 }
371 
372 } // namespace flatbuffers
373 #endif // FLATBUFFERS_BASE_H_
#define FLATBUFFERS_ASSERT
__supress_ubsan__("float-cast-overflow") inline void strtoval_impl(float *val


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04