rapidjson.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_RAPIDJSON_H_
20 #define RAPIDJSON_RAPIDJSON_H_
21 
44 #include <cstdlib> // malloc(), realloc(), free(), size_t
45 #include <cstring> // memset(), memcpy(), memmove(), memcmp()
46 
48 // RAPIDJSON_VERSION_STRING
49 //
50 // ALWAYS synchronize the following 3 macros with corresponding variables in
51 // /CMakeLists.txt.
52 //
53 
55 // token stringification
56 #define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
57 #define RAPIDJSON_DO_STRINGIFY(x) #x
58 
59 // token concatenation
60 #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
61 #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
62 #define RAPIDJSON_DO_JOIN2(X, Y) X##Y
63 
81 #define RAPIDJSON_MAJOR_VERSION 1
82 #define RAPIDJSON_MINOR_VERSION 1
83 #define RAPIDJSON_PATCH_VERSION 0
84 #define RAPIDJSON_VERSION_STRING \
85  RAPIDJSON_STRINGIFY( \
86  RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
87 
89 // RAPIDJSON_NAMESPACE_(BEGIN|END)
124 #ifndef RAPIDJSON_NAMESPACE
125 #define RAPIDJSON_NAMESPACE rapidjson
126 #endif
127 #ifndef RAPIDJSON_NAMESPACE_BEGIN
128 #define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
129 #endif
130 #ifndef RAPIDJSON_NAMESPACE_END
131 #define RAPIDJSON_NAMESPACE_END }
132 #endif
133 
135 // RAPIDJSON_HAS_STDSTRING
136 
137 #ifndef RAPIDJSON_HAS_STDSTRING
138 #ifdef RAPIDJSON_DOXYGEN_RUNNING
139 #define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
140 #else
141 #define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
142 #endif
143 
153 #endif // !defined(RAPIDJSON_HAS_STDSTRING)
154 
155 #if RAPIDJSON_HAS_STDSTRING
156 #include <string>
157 #endif // RAPIDJSON_HAS_STDSTRING
158 
160 // RAPIDJSON_NO_INT64DEFINE
161 
172 #ifndef RAPIDJSON_NO_INT64DEFINE
173 #if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013
175 #include "msinttypes/inttypes.h"
176 #include "msinttypes/stdint.h"
177 #else
178 // Other compilers should have this.
179 #include <inttypes.h>
180 #include <stdint.h>
181 #endif
182 #ifdef RAPIDJSON_DOXYGEN_RUNNING
184 #define RAPIDJSON_NO_INT64DEFINE
185 #endif
186 #endif // RAPIDJSON_NO_INT64TYPEDEF
187 
189 // RAPIDJSON_FORCEINLINE
190 
191 #ifndef RAPIDJSON_FORCEINLINE
192 #if defined(_MSC_VER) && defined(NDEBUG)
194 #define RAPIDJSON_FORCEINLINE __forceinline
195 #elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
196 #define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
197 #else
198 #define RAPIDJSON_FORCEINLINE
199 #endif
200 #endif // RAPIDJSON_FORCEINLINE
202 
204 // RAPIDJSON_ENDIAN
205 #define RAPIDJSON_LITTLEENDIAN 0
206 #define RAPIDJSON_BIGENDIAN 1
207 
208 
222 #ifndef RAPIDJSON_ENDIAN
223 // Detect with GCC 4.6's macro
224 #ifdef __BYTE_ORDER__
225 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
226 #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
227 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
228 #define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
229 #else
230 # error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
231 #endif // __BYTE_ORDER__
232 // Detect with GLIBC's endian.h
233 #elif defined(__GLIBC__)
234 #include <endian.h>
235 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
236 #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
237 #elif (__BYTE_ORDER == __BIG_ENDIAN)
238 #define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
239 #else
240 # error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
241 #endif // __GLIBC__
242 // Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
243 #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
244 #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
245 #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
246 #define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
247 // Detect with architecture macros
248 #elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || \
249  defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || \
250  defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || \
251  defined(__s390__)
252 #define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
253 #elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || \
254  defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || \
255  defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || \
256  defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || \
257  defined(_M_X64) || defined(__bfin__)
258 #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
259 #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
260 #define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
261 #elif defined(RAPIDJSON_DOXYGEN_RUNNING)
262 #define RAPIDJSON_ENDIAN
263 #else
264 # error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
265 #endif
266 #endif // RAPIDJSON_ENDIAN
267 
269 // RAPIDJSON_64BIT
270 
272 #ifndef RAPIDJSON_64BIT
273 #if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || \
274  defined(_WIN64) || defined(__EMSCRIPTEN__)
275 #define RAPIDJSON_64BIT 1
276 #else
277 #define RAPIDJSON_64BIT 0
278 #endif
279 #endif // RAPIDJSON_64BIT
280 
282 // RAPIDJSON_ALIGN
283 
285 
291 #ifndef RAPIDJSON_ALIGN
292 #define RAPIDJSON_ALIGN(x) \
293  (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
294 #endif
295 
297 // RAPIDJSON_UINT64_C2
298 
300 
305 #ifndef RAPIDJSON_UINT64_C2
306 #define RAPIDJSON_UINT64_C2(high32, low32) \
307  ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
308 #endif
309 
311 // RAPIDJSON_48BITPOINTER_OPTIMIZATION
312 
314 
322 #ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
323 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \
324  defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
325 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
326 #else
327 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
328 #endif
329 #endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
330 
331 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
332 #if RAPIDJSON_64BIT != 1
333 #error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
334 #endif
335 #define RAPIDJSON_SETPOINTER(type, p, x) \
336  (p = reinterpret_cast<type *>( \
337  (reinterpret_cast<uintptr_t>(p) & \
338  static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | \
339  reinterpret_cast<uintptr_t>(reinterpret_cast<const void *>(x))))
340 #define RAPIDJSON_GETPOINTER(type, p) \
341  (reinterpret_cast<type *>( \
342  reinterpret_cast<uintptr_t>(p) & \
343  static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
344 #else
345 #define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
346 #define RAPIDJSON_GETPOINTER(type, p) (p)
347 #endif
348 
350 // RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_NEON/RAPIDJSON_SIMD
351 
378 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) || \
379  defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
380 #define RAPIDJSON_SIMD
381 #endif
382 
384 // RAPIDJSON_NO_SIZETYPEDEFINE
385 
386 #ifndef RAPIDJSON_NO_SIZETYPEDEFINE
387 
402 #ifdef RAPIDJSON_DOXYGEN_RUNNING
403 #define RAPIDJSON_NO_SIZETYPEDEFINE
404 #endif
407 
411 typedef unsigned SizeType;
413 #endif
414 
415 // always import std::size_t to rapidjson namespace
417 using std::size_t;
419 
421 // RAPIDJSON_ASSERT
422 
424 
431 #ifndef RAPIDJSON_ASSERT
432 #include <cassert>
433 #define RAPIDJSON_ASSERT(x) assert(x)
434 #endif // RAPIDJSON_ASSERT
435 
437 // RAPIDJSON_STATIC_ASSERT
438 
439 // Prefer C++11 static_assert, if available
440 #ifndef RAPIDJSON_STATIC_ASSERT
441 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
442 #define RAPIDJSON_STATIC_ASSERT(x) static_assert(x, RAPIDJSON_STRINGIFY(x))
443 #endif // C++11
444 #endif // RAPIDJSON_STATIC_ASSERT
445 
446 // Adopt C++03 implementation from boost
447 #ifndef RAPIDJSON_STATIC_ASSERT
448 #ifndef __clang__
449 #endif
452 template <bool x>
453 struct STATIC_ASSERTION_FAILURE;
454 template <>
455 struct STATIC_ASSERTION_FAILURE<true> {
456  enum { value = 1 };
457 };
458 template <size_t x>
459 struct StaticAssertTest {};
461 
462 #if defined(__GNUC__) || defined(__clang__)
463 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
464 #else
465 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
466 #endif
467 #ifndef __clang__
468 #endif
470 
476 #define RAPIDJSON_STATIC_ASSERT(x) \
477  typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest<sizeof( \
478  ::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x)>)> \
479  RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) \
480  RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
481 #endif // RAPIDJSON_STATIC_ASSERT
482 
484 // RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY
485 
487 
491 #ifndef RAPIDJSON_LIKELY
492 #if defined(__GNUC__) || defined(__clang__)
493 #define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
494 #else
495 #define RAPIDJSON_LIKELY(x) (x)
496 #endif
497 #endif
498 
500 
504 #ifndef RAPIDJSON_UNLIKELY
505 #if defined(__GNUC__) || defined(__clang__)
506 #define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
507 #else
508 #define RAPIDJSON_UNLIKELY(x) (x)
509 #endif
510 #endif
511 
513 // Helpers
514 
516 
517 #define RAPIDJSON_MULTILINEMACRO_BEGIN do {
518 #define RAPIDJSON_MULTILINEMACRO_END \
519  } \
520  while ((void)0, 0)
521 
522 // adopted from Boost
523 #define RAPIDJSON_VERSION_CODE(x, y, z) (((x)*100000) + ((y)*100) + (z))
524 
525 #if defined(__has_builtin)
526 #define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x)
527 #else
528 #define RAPIDJSON_HAS_BUILTIN(x) 0
529 #endif
530 
532 // RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
533 
534 #if defined(__GNUC__)
535 #define RAPIDJSON_GNUC \
536  RAPIDJSON_VERSION_CODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
537 #endif
538 
539 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && \
540  RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 2, 0))
541 
542 #define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
543 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
544 #define RAPIDJSON_DIAG_OFF(x) \
545  RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W, x)))
546 
547 // push/pop support in Clang and GCC>=4.6
548 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && \
549  RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 6, 0))
550 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
551 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
552 #else // GCC >= 4.2, < 4.6
553 #define RAPIDJSON_DIAG_PUSH /* ignored */
554 #define RAPIDJSON_DIAG_POP /* ignored */
555 #endif
556 
557 #elif defined(_MSC_VER)
558 
559 // pragma (MSVC specific)
560 #define RAPIDJSON_PRAGMA(x) __pragma(x)
561 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
562 
563 #define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable : x)
564 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
565 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
566 
567 #else
568 
569 #define RAPIDJSON_DIAG_OFF(x) /* ignored */
570 #define RAPIDJSON_DIAG_PUSH /* ignored */
571 #define RAPIDJSON_DIAG_POP /* ignored */
572 
573 #endif // RAPIDJSON_DIAG_*
574 
576 // C++11 features
577 
578 #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
579 #if defined(__clang__)
580 #if __has_feature(cxx_rvalue_references) && \
581  (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || \
582  defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
583 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
584 #else
585 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
586 #endif
587 #elif (defined(RAPIDJSON_GNUC) && \
588  (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 3, 0)) && \
589  defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
590  (defined(_MSC_VER) && _MSC_VER >= 1600) || \
591  (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && \
592  defined(__GXX_EXPERIMENTAL_CXX0X__))
593 
594 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
595 #else
596 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
597 #endif
598 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
599 
600 #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
601 #if defined(__clang__)
602 #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
603 #elif (defined(RAPIDJSON_GNUC) && \
604  (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 6, 0)) && \
605  defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
606  (defined(_MSC_VER) && _MSC_VER >= 1900) || \
607  (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && \
608  defined(__GXX_EXPERIMENTAL_CXX0X__))
609 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
610 #else
611 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
612 #endif
613 #endif
614 #if RAPIDJSON_HAS_CXX11_NOEXCEPT
615 #define RAPIDJSON_NOEXCEPT noexcept
616 #else
617 #define RAPIDJSON_NOEXCEPT /* noexcept */
618 #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
619 
620 // no automatic detection, yet
621 #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
622 #if (defined(_MSC_VER) && _MSC_VER >= 1700)
623 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 1
624 #else
625 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
626 #endif
627 #endif
628 
629 #ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
630 #if defined(__clang__)
631 #define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
632 #elif (defined(RAPIDJSON_GNUC) && \
633  (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 6, 0)) && \
634  defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
635  (defined(_MSC_VER) && _MSC_VER >= 1700) || \
636  (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && \
637  defined(__GXX_EXPERIMENTAL_CXX0X__))
638 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
639 #else
640 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
641 #endif
642 #endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
643 
645 // C++17 features
646 
647 #if defined(__has_cpp_attribute)
648 #if __has_cpp_attribute(fallthrough)
649 #define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
650 #else
651 #define RAPIDJSON_DELIBERATE_FALLTHROUGH
652 #endif
653 #else
654 #define RAPIDJSON_DELIBERATE_FALLTHROUGH
655 #endif
656 
658 
660 
670 // RAPIDJSON_NOEXCEPT_ASSERT
672 
673 #ifndef RAPIDJSON_NOEXCEPT_ASSERT
674 #ifdef RAPIDJSON_ASSERT_THROWS
675 #if RAPIDJSON_HAS_CXX11_NOEXCEPT
676 #define RAPIDJSON_NOEXCEPT_ASSERT(x)
677 #else
678 #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
679 #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
680 #else
681 #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
682 #endif // RAPIDJSON_ASSERT_THROWS
683 #endif // RAPIDJSON_NOEXCEPT_ASSERT
684 
686 // new/delete
687 
688 #ifndef RAPIDJSON_NEW
689 #define RAPIDJSON_NEW(TypeName) new TypeName
691 #endif
692 #ifndef RAPIDJSON_DELETE
693 #define RAPIDJSON_DELETE(x) delete x
695 #endif
696 
698 // Type
699 
705 
707 enum Type {
708  kNullType = 0,
710  kTrueType = 2,
715 };
716 
718 
719 #endif // RAPIDJSON_RAPIDJSON_H_
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:411
object
Definition: rapidjson.h:711
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
array
Definition: rapidjson.h:712
false
Definition: rapidjson.h:709
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
string
Definition: rapidjson.h:713
number
Definition: rapidjson.h:714
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1518
true
Definition: rapidjson.h:710
Type
Type of JSON value.
Definition: rapidjson.h:707
null
Definition: rapidjson.h:708


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46