16#ifndef RAPIDJSON_RAPIDJSON_H_
17#define RAPIDJSON_RAPIDJSON_H_
51#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
52#define RAPIDJSON_DO_STRINGIFY(x) #x
55#define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
56#define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
57#define RAPIDJSON_DO_JOIN2(X, Y) X##Y
76#define RAPIDJSON_MAJOR_VERSION 1
77#define RAPIDJSON_MINOR_VERSION 1
78#define RAPIDJSON_PATCH_VERSION 0
79#define RAPIDJSON_VERSION_STRING \
80 RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
118#ifndef RAPIDJSON_NAMESPACE
119#define RAPIDJSON_NAMESPACE rapidjson
121#ifndef RAPIDJSON_NAMESPACE_BEGIN
122#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
124#ifndef RAPIDJSON_NAMESPACE_END
125#define RAPIDJSON_NAMESPACE_END }
131#ifndef RAPIDJSON_HAS_STDSTRING
132#ifdef RAPIDJSON_DOXYGEN_RUNNING
133#define RAPIDJSON_HAS_STDSTRING 1
135#define RAPIDJSON_HAS_STDSTRING 0
149#if RAPIDJSON_HAS_STDSTRING
166#ifndef RAPIDJSON_NO_INT64DEFINE
168#if defined(_MSC_VER) && (_MSC_VER < 1800)
169#include "msinttypes/stdint.h"
170#include "msinttypes/inttypes.h"
177#ifdef RAPIDJSON_DOXYGEN_RUNNING
178#define RAPIDJSON_NO_INT64DEFINE
185#ifndef RAPIDJSON_FORCEINLINE
187#if defined(_MSC_VER) && defined(NDEBUG)
188#define RAPIDJSON_FORCEINLINE __forceinline
189#elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
190#define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
192#define RAPIDJSON_FORCEINLINE
199#define RAPIDJSON_LITTLEENDIAN 0
200#define RAPIDJSON_BIGENDIAN 1
215#ifndef RAPIDJSON_ENDIAN
217# ifdef __BYTE_ORDER__
218# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
219# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
220# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
221# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
223# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
226# elif defined(__GLIBC__)
228# if (__BYTE_ORDER == __LITTLE_ENDIAN)
229# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
230# elif (__BYTE_ORDER == __BIG_ENDIAN)
231# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
233# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
236# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
237# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
238# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
239# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
241# elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
242# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
243# 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__)
244# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
245# elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
246# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
247# elif defined(RAPIDJSON_DOXYGEN_RUNNING)
248# define RAPIDJSON_ENDIAN
250# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
258#ifndef RAPIDJSON_64BIT
259#if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
260#define RAPIDJSON_64BIT 1
262#define RAPIDJSON_64BIT 0
276#ifndef RAPIDJSON_ALIGN
277#define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
289#ifndef RAPIDJSON_UINT64_C2
290#define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
304#ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
305#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
306#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
308#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
312#if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
313#if RAPIDJSON_64BIT != 1
314#error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
316#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))))
317#define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
319#define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
320#define RAPIDJSON_GETPOINTER(type, p) (p)
352#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
353 || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
354#define RAPIDJSON_SIMD
360#ifndef RAPIDJSON_NO_SIZETYPEDEFINE
376#ifdef RAPIDJSON_DOXYGEN_RUNNING
377#define RAPIDJSON_NO_SIZETYPEDEFINE
405#ifndef RAPIDJSON_ASSERT
407#define RAPIDJSON_ASSERT(x) assert(x)
414#ifndef RAPIDJSON_STATIC_ASSERT
415#if __cplusplus >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
416#define RAPIDJSON_STATIC_ASSERT(x) \
417 static_assert(x, RAPIDJSON_STRINGIFY(x))
422#ifndef RAPIDJSON_STATIC_ASSERT
427template <
bool x>
struct STATIC_ASSERTION_FAILURE;
428template <>
struct STATIC_ASSERTION_FAILURE<true> {
enum { value = 1 }; };
429template <
size_t x>
struct StaticAssertTest {};
432#if defined(__GNUC__) || defined(__clang__)
433#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
435#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
446#define RAPIDJSON_STATIC_ASSERT(x) \
447 typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
448 sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
449 RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
460#ifndef RAPIDJSON_LIKELY
461#if defined(__GNUC__) || defined(__clang__)
462#define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
464#define RAPIDJSON_LIKELY(x) (x)
473#ifndef RAPIDJSON_UNLIKELY
474#if defined(__GNUC__) || defined(__clang__)
475#define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
477#define RAPIDJSON_UNLIKELY(x) (x)
486#define RAPIDJSON_MULTILINEMACRO_BEGIN do {
487#define RAPIDJSON_MULTILINEMACRO_END \
491#define RAPIDJSON_VERSION_CODE(x,y,z) \
492 (((x)*100000) + ((y)*100) + (z))
494#if defined(__has_builtin)
495#define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x)
497#define RAPIDJSON_HAS_BUILTIN(x) 0
504#define RAPIDJSON_GNUC \
505 RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
508#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
510#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
511#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
512#define RAPIDJSON_DIAG_OFF(x) \
513 RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
516#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
517#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
518#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
520#define RAPIDJSON_DIAG_PUSH
521#define RAPIDJSON_DIAG_POP
524#elif defined(_MSC_VER)
527#define RAPIDJSON_PRAGMA(x) __pragma(x)
528#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
530#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
531#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
532#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
536#define RAPIDJSON_DIAG_OFF(x)
537#define RAPIDJSON_DIAG_PUSH
538#define RAPIDJSON_DIAG_POP
545#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
546#if defined(__clang__)
547#if __has_feature(cxx_rvalue_references) && \
548 (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
549#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
551#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
553#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
554 (defined(_MSC_VER) && _MSC_VER >= 1600) || \
555 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
557#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
559#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
563#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
564#if defined(__clang__)
565#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
566#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
567 (defined(_MSC_VER) && _MSC_VER >= 1900) || \
568 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
569#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
571#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
574#if RAPIDJSON_HAS_CXX11_NOEXCEPT
575#define RAPIDJSON_NOEXCEPT noexcept
577#define RAPIDJSON_NOEXCEPT
581#ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
582#if (defined(_MSC_VER) && _MSC_VER >= 1700)
583#define RAPIDJSON_HAS_CXX11_TYPETRAITS 1
585#define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
589#ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
590#if defined(__clang__)
591#define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
592#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
593 (defined(_MSC_VER) && _MSC_VER >= 1700) || \
594 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
595#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
597#define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
604#if defined(__has_cpp_attribute)
605# if __has_cpp_attribute(fallthrough)
606# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
608# define RAPIDJSON_DELIBERATE_FALLTHROUGH
611# define RAPIDJSON_DELIBERATE_FALLTHROUGH
630#ifndef RAPIDJSON_NOEXCEPT_ASSERT
631#ifdef RAPIDJSON_ASSERT_THROWS
632#if RAPIDJSON_HAS_CXX11_NOEXCEPT
633#define RAPIDJSON_NOEXCEPT_ASSERT(x)
636#define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x)
639#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
648#define RAPIDJSON_NEW(TypeName) new TypeName
650#ifndef RAPIDJSON_DELETE
652#define RAPIDJSON_DELETE(x) delete x
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)