15 #ifndef RAPIDJSON_RAPIDJSON_H_
16 #define RAPIDJSON_RAPIDJSON_H_
50 #define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
51 #define RAPIDJSON_DO_STRINGIFY(x) #x
54 #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
55 #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
56 #define RAPIDJSON_DO_JOIN2(X, Y) X##Y
75 #define RAPIDJSON_MAJOR_VERSION 1
76 #define RAPIDJSON_MINOR_VERSION 1
77 #define RAPIDJSON_PATCH_VERSION 0
78 #define RAPIDJSON_VERSION_STRING \
79 RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
117 #ifndef RAPIDJSON_NAMESPACE
118 #define RAPIDJSON_NAMESPACE rapidjson
120 #ifndef RAPIDJSON_NAMESPACE_BEGIN
121 #define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
123 #ifndef RAPIDJSON_NAMESPACE_END
124 #define RAPIDJSON_NAMESPACE_END }
132 #if defined(_MSC_VER)
133 #define RAPIDJSON_CPLUSPLUS _MSVC_LANG
135 #define RAPIDJSON_CPLUSPLUS __cplusplus
143 #ifndef RAPIDJSON_HAS_STDSTRING
144 #ifdef RAPIDJSON_DOXYGEN_RUNNING
145 #define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
147 #define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
159 #endif // !defined(RAPIDJSON_HAS_STDSTRING)
161 #if RAPIDJSON_HAS_STDSTRING
163 #endif // RAPIDJSON_HAS_STDSTRING
179 #ifndef RAPIDJSON_USE_MEMBERSMAP
180 #define RAPIDJSON_USE_MEMBERSMAP 0 // not by default
196 #ifndef RAPIDJSON_NO_INT64DEFINE
198 #if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013
199 #include "msinttypes/stdint.h"
200 #include "msinttypes/inttypes.h"
204 #include <inttypes.h>
207 #ifdef RAPIDJSON_DOXYGEN_RUNNING
208 #define RAPIDJSON_NO_INT64DEFINE
210 #endif // RAPIDJSON_NO_INT64TYPEDEF
215 #ifndef RAPIDJSON_FORCEINLINE
217 #if defined(_MSC_VER) && defined(NDEBUG)
218 #define RAPIDJSON_FORCEINLINE __forceinline
219 #elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
220 #define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
222 #define RAPIDJSON_FORCEINLINE
225 #endif // RAPIDJSON_FORCEINLINE
229 #define RAPIDJSON_LITTLEENDIAN 0
230 #define RAPIDJSON_BIGENDIAN 1
245 #ifndef RAPIDJSON_ENDIAN
247 # ifdef __BYTE_ORDER__
248 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
249 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
250 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
251 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
253 # error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
254 # endif // __BYTE_ORDER__
256 # elif defined(__GLIBC__)
258 # if (__BYTE_ORDER == __LITTLE_ENDIAN)
259 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
260 # elif (__BYTE_ORDER == __BIG_ENDIAN)
261 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
263 # error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
266 # elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
267 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
268 # elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
269 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
271 # elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
272 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
273 # elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__bfin__)
274 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
275 # elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
276 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
277 # elif defined(RAPIDJSON_DOXYGEN_RUNNING)
278 # define RAPIDJSON_ENDIAN
280 # error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
282 #endif // RAPIDJSON_ENDIAN
288 #ifndef RAPIDJSON_64BIT
289 #if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
290 #define RAPIDJSON_64BIT 1
292 #define RAPIDJSON_64BIT 0
294 #endif // RAPIDJSON_64BIT
306 #ifndef RAPIDJSON_ALIGN
307 #define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
319 #ifndef RAPIDJSON_UINT64_C2
320 #define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
334 #ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
335 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
336 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
338 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
340 #endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
342 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
343 #if RAPIDJSON_64BIT != 1
344 #error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
346 #define RAPIDJSON_SETPOINTER(type, p, x) (p = reinterpret_cast<type *>((reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | reinterpret_cast<uintptr_t>(reinterpret_cast<const void*>(x))))
347 #define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
349 #define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
350 #define RAPIDJSON_GETPOINTER(type, p) (p)
382 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
383 || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
384 #define RAPIDJSON_SIMD
390 #ifndef RAPIDJSON_NO_SIZETYPEDEFINE
406 #ifdef RAPIDJSON_DOXYGEN_RUNNING
407 #define RAPIDJSON_NO_SIZETYPEDEFINE
409 RAPIDJSON_NAMESPACE_BEGIN
416 RAPIDJSON_NAMESPACE_END
420 RAPIDJSON_NAMESPACE_BEGIN
422 RAPIDJSON_NAMESPACE_END
435 #ifndef RAPIDJSON_ASSERT
437 #define RAPIDJSON_ASSERT(x) assert(x)
438 #endif // RAPIDJSON_ASSERT
444 #ifndef RAPIDJSON_STATIC_ASSERT
445 #if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
446 #define RAPIDJSON_STATIC_ASSERT(x) \
447 static_assert(x, RAPIDJSON_STRINGIFY(x))
449 #endif // RAPIDJSON_STATIC_ASSERT
452 #ifndef RAPIDJSON_STATIC_ASSERT
456 RAPIDJSON_NAMESPACE_BEGIN
457 template <
bool x>
struct STATIC_ASSERTION_FAILURE;
458 template <>
struct STATIC_ASSERTION_FAILURE<true> {
enum { value = 1 }; };
459 template <
size_t x>
struct StaticAssertTest {};
460 RAPIDJSON_NAMESPACE_END
462 #if defined(__GNUC__) || defined(__clang__)
463 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
465 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
476 #define RAPIDJSON_STATIC_ASSERT(x) \
477 typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
478 sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
479 RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
480 #endif // RAPIDJSON_STATIC_ASSERT
490 #ifndef RAPIDJSON_LIKELY
491 #if defined(__GNUC__) || defined(__clang__)
492 #define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
494 #define RAPIDJSON_LIKELY(x) (x)
503 #ifndef RAPIDJSON_UNLIKELY
504 #if defined(__GNUC__) || defined(__clang__)
505 #define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
507 #define RAPIDJSON_UNLIKELY(x) (x)
516 #define RAPIDJSON_MULTILINEMACRO_BEGIN do {
517 #define RAPIDJSON_MULTILINEMACRO_END \
521 #define RAPIDJSON_VERSION_CODE(x,y,z) \
522 (((x)*100000) + ((y)*100) + (z))
524 #if defined(__has_builtin)
525 #define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x)
527 #define RAPIDJSON_HAS_BUILTIN(x) 0
533 #if defined(__GNUC__)
534 #define RAPIDJSON_GNUC \
535 RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
538 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
540 #define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
541 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
542 #define RAPIDJSON_DIAG_OFF(x) \
543 RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
546 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
547 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
548 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
549 #else // GCC >= 4.2, < 4.6
550 #define RAPIDJSON_DIAG_PUSH
551 #define RAPIDJSON_DIAG_POP
554 #elif defined(_MSC_VER)
557 #define RAPIDJSON_PRAGMA(x) __pragma(x)
558 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
560 #define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
561 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
562 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
566 #define RAPIDJSON_DIAG_OFF(x)
567 #define RAPIDJSON_DIAG_PUSH
568 #define RAPIDJSON_DIAG_POP
570 #endif // RAPIDJSON_DIAG_*
575 #ifndef RAPIDJSON_HAS_CXX11
576 #define RAPIDJSON_HAS_CXX11 (RAPIDJSON_CPLUSPLUS >= 201103L)
579 #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
580 #if RAPIDJSON_HAS_CXX11
581 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
582 #elif defined(__clang__)
583 #if __has_feature(cxx_rvalue_references) && \
584 (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
585 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
587 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
589 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
590 (defined(_MSC_VER) && _MSC_VER >= 1600) || \
591 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
593 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
595 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
597 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
599 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
603 #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
604 #if RAPIDJSON_HAS_CXX11
605 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
606 #elif defined(__clang__)
607 #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
608 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
609 (defined(_MSC_VER) && _MSC_VER >= 1900) || \
610 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
611 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
613 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
616 #ifndef RAPIDJSON_NOEXCEPT
617 #if RAPIDJSON_HAS_CXX11_NOEXCEPT
618 #define RAPIDJSON_NOEXCEPT noexcept
620 #define RAPIDJSON_NOEXCEPT throw()
621 #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
625 #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
626 #if (defined(_MSC_VER) && _MSC_VER >= 1700)
627 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 1
629 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
633 #ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
634 #if defined(__clang__)
635 #define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
636 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
637 (defined(_MSC_VER) && _MSC_VER >= 1700) || \
638 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
639 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
641 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
643 #endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
648 #ifndef RAPIDJSON_HAS_CXX17
649 #define RAPIDJSON_HAS_CXX17 (RAPIDJSON_CPLUSPLUS >= 201703L)
652 #if RAPIDJSON_HAS_CXX17
653 # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
654 #elif defined(__has_cpp_attribute)
655 # if __has_cpp_attribute(clang::fallthrough)
656 # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
657 # elif __has_cpp_attribute(fallthrough)
658 # define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
660 # define RAPIDJSON_DELIBERATE_FALLTHROUGH
663 # define RAPIDJSON_DELIBERATE_FALLTHROUGH
682 #ifndef RAPIDJSON_NOEXCEPT_ASSERT
683 #ifdef RAPIDJSON_ASSERT_THROWS
685 #define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x)
687 #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
688 #endif // RAPIDJSON_ASSERT_THROWS
689 #endif // RAPIDJSON_NOEXCEPT_ASSERT
694 #ifndef RAPIDJSON_MALLOC
696 #define RAPIDJSON_MALLOC(size) std::malloc(size)
698 #ifndef RAPIDJSON_REALLOC
700 #define RAPIDJSON_REALLOC(ptr, new_size) std::realloc(ptr, new_size)
702 #ifndef RAPIDJSON_FREE
704 #define RAPIDJSON_FREE(ptr) std::free(ptr)
710 #ifndef RAPIDJSON_NEW
712 #define RAPIDJSON_NEW(TypeName) new TypeName
714 #ifndef RAPIDJSON_DELETE
716 #define RAPIDJSON_DELETE(x) delete x
726 RAPIDJSON_NAMESPACE_BEGIN
739 RAPIDJSON_NAMESPACE_END
741 #endif // RAPIDJSON_RAPIDJSON_H_