rapidjson.h

Engine/source/persistence/rapidjson/rapidjson.h

common definitions and configuration

More...

Namespaces:

namespace

main RapidJSON namespace

Public Defines

define

Use only lower 48-bit address for some pointers.

define

Whether using 64-bit architecture.

define
RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))

Data alignment of the machine.

define
RAPIDJSON_ASSERT(x) assert(x)

Assertion.

define

Big endian machine.

define
RAPIDJSON_DELETE(x) delete x

! customization point for global

delete

define
RAPIDJSON_GETPOINTER(type, p) (p)
define

Enable RapidJSON support for

std::string
.

define

Compiler branching hint for expression with high probability to be true.

define

Little endian machine.

define

Major version of RapidJSON in integer.

define

Minor version of RapidJSON in integer.

define
RAPIDJSON_NAMESPACE() rapidjson

provide custom rapidjson namespace

define

provide custom rapidjson namespace (opening expression)

define

provide custom rapidjson namespace (closing expression)

define
RAPIDJSON_NEW(TypeName)  TypeName

! customization point for global

new

define

Assertion (in non-throwing contexts).

define

Patch version of RapidJSON in integer.

define
RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
define

(Internal) macro to check for conditions at compile-time

define
RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<>(high32) << 32) | static_cast<>(low32))

Construct a 64-bit literal by a pair of 32-bit integer.

define

Compiler branching hint for expression with low probability to be true.

define
RAPIDJSON_VERSION_STRING()     RAPIDJSON_STRINGIFY()

Version of RapidJSON in ".." string format.

Public Enumerations

enum
Type {
  kNullType = 0
  kFalseType = 1
  kTrueType = 2
  kObjectType = 3
  kArrayType = 4
  kStringType = 5
  kNumberType = 6
}

Type of JSON value.

Public Variables

RAPIDJSON_NAMESPACE_BEGIN typedef unsigned

Size type (for string lengths, array sizes, etc.)

Detailed Description

common definitions and configuration

Public Defines

RAPIDJSON_48BITPOINTER_OPTIMIZATION() 0

Use only lower 48-bit address for some pointers.

This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address. The higher 16-bit can be used for storing other data.

GenericValue
uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture.

RAPIDJSON_64BIT() 0

Whether using 64-bit architecture.

RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))

Data alignment of the machine.

Parameters:

x

pointer to align

Some machines require strict data alignment. The default is 8 bytes. User can customize by defining the RAPIDJSON_ALIGN function macro.

RAPIDJSON_ASSERT(x) assert(x)

Assertion.

By default, rapidjson uses C

assert()
for internal assertions. User can override it by defining RAPIDJSON_ASSERT(x) macro.

note:

Parsing errors are handled and can be customized by the RapidJSON error handling APIs.

RAPIDJSON_BIGENDIAN() 1

Big endian machine.

RAPIDJSON_DELETE(x) delete x

! customization point for global

delete

RAPIDJSON_GETPOINTER(type, p) (p)
RAPIDJSON_HAS_STDSTRING() 

Enable RapidJSON support for

std::string
.

By defining this preprocessor symbol to

1
, several convenience functions for using rapidjson::GenericValue with
std::string
are enabled, especially for construction and comparison.

RAPIDJSON_LIKELY(x) (x)

Compiler branching hint for expression with high probability to be true.

Parameters:

x

Boolean expression likely to be true.

RAPIDJSON_LITTLEENDIAN() 0

Little endian machine.

RAPIDJSON_MAJOR_VERSION() 1

Major version of RapidJSON in integer.

RAPIDJSON_MINOR_VERSION() 1

Minor version of RapidJSON in integer.

RAPIDJSON_NAMESPACE() rapidjson

provide custom rapidjson namespace

In order to avoid symbol clashes and/or "One Definition Rule" errors between multiple inclusions of (different versions of) RapidJSON in a single binary, users can customize the name of the main RapidJSON namespace.

In case of a single nesting level, defining

RAPIDJSON_NAMESPACE
to a custom name (e.g.
MyRapidJSON
) is sufficient. If multiple levels are needed, both RAPIDJSON_NAMESPACE_BEGIN and RAPIDJSON_NAMESPACE_END need to be defined as well:

// in some .cpp file
#define RAPIDJSON_NAMESPACE my::rapidjson
#define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson {
#define RAPIDJSON_NAMESPACE_END   } }
#include "rapidjson/..."

RAPIDJSON_NAMESPACE_BEGIN() namespace  {

provide custom rapidjson namespace (opening expression)

RAPIDJSON_NAMESPACE_END() }

provide custom rapidjson namespace (closing expression)

RAPIDJSON_NEW(TypeName)  TypeName

! customization point for global

new

RAPIDJSON_NOEXCEPT_ASSERT(x) (x)

Assertion (in non-throwing contexts).

Some functions provide a

noexcept
guarantee, if the compiler supports it. In these cases, the RAPIDJSON_ASSERT macro cannot be overridden to throw an exception. This macro adds a separate customization point for such cases.

Defaults to C

assert()
(as RAPIDJSON_ASSERT), if
noexcept
is supported, and to RAPIDJSON_ASSERT otherwise.

RAPIDJSON_PATCH_VERSION() 0

Patch version of RapidJSON in integer.

RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
RAPIDJSON_STATIC_ASSERT(x) 

(Internal) macro to check for conditions at compile-time

Parameters:

x

compile-time condition

RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<>(high32) << 32) | static_cast<>(low32))

Construct a 64-bit literal by a pair of 32-bit integer.

64-bit literal with or without ULL suffix is prone to compiler warnings. UINT64_C() is C macro which cause compilation problems. Use this macro to define 64-bit constants by a pair of 32-bit integer.

RAPIDJSON_UNLIKELY(x) (x)

Compiler branching hint for expression with low probability to be true.

Parameters:

x

Boolean expression unlikely to be true.

RAPIDJSON_VERSION_STRING()     RAPIDJSON_STRINGIFY()

Version of RapidJSON in ".." string format.

Public Enumerations

Type

Enumerator

kNullType = 0

null

kFalseType = 1

false

kTrueType = 2

true

kObjectType = 3

object

kArrayType = 4

array

kStringType = 5

string

kNumberType = 6

number

Type of JSON value.

Public Variables

RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType 

Size type (for string lengths, array sizes, etc.)

RapidJSON uses 32-bit array/string indices even on 64-bit platforms, instead of using

size_t
. Users may override the SizeType by defining RAPIDJSON_NO_SIZETYPEDEFINE.

  1
  2// Tencent is pleased to support the open source community by making RapidJSON available.
  3// 
  4// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
  5//
  6// Licensed under the MIT License (the "License"); you may not use this file except
  7// in compliance with the License. You may obtain a copy of the License at
  8//
  9// http://opensource.org/licenses/MIT
 10//
 11// Unless required by applicable law or agreed to in writing, software distributed 
 12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 13// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 14// specific language governing permissions and limitations under the License.
 15
 16#ifndef RAPIDJSON_RAPIDJSON_H_
 17#define RAPIDJSON_RAPIDJSON_H_
 18
 19/*!\file rapidjson.h
 20    \brief common definitions and configuration
 21    
 22    \see RAPIDJSON_CONFIG
 23 */
 24
 25/*! \defgroup RAPIDJSON_CONFIG RapidJSON configuration
 26    \brief Configuration macros for library features
 27
 28    Some RapidJSON features are configurable to adapt the library to a wide
 29    variety of platforms, environments and usage scenarios.  Most of the
 30    features can be configured in terms of overridden or predefined
 31    preprocessor macros at compile-time.
 32
 33    Some additional customization is available in the \ref RAPIDJSON_ERRORS APIs.
 34
 35    \note These macros should be given on the compiler command-line
 36          (where applicable)  to avoid inconsistent values when compiling
 37          different translation units of a single application.
 38 */
 39
 40#include <cstdlib>  // malloc(), realloc(), free(), size_t
 41#include <cstring>  // memset(), memcpy(), memmove(), memcmp()
 42
 43///////////////////////////////////////////////////////////////////////////////
 44// RAPIDJSON_VERSION_STRING
 45//
 46// ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt.
 47//
 48
 49//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
 50// token stringification
 51#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
 52#define RAPIDJSON_DO_STRINGIFY(x) #x
 53
 54// token concatenation
 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
 58//!@endcond
 59
 60/*! \def RAPIDJSON_MAJOR_VERSION
 61    \ingroup RAPIDJSON_CONFIG
 62    \brief Major version of RapidJSON in integer.
 63*/
 64/*! \def RAPIDJSON_MINOR_VERSION
 65    \ingroup RAPIDJSON_CONFIG
 66    \brief Minor version of RapidJSON in integer.
 67*/
 68/*! \def RAPIDJSON_PATCH_VERSION
 69    \ingroup RAPIDJSON_CONFIG
 70    \brief Patch version of RapidJSON in integer.
 71*/
 72/*! \def RAPIDJSON_VERSION_STRING
 73    \ingroup RAPIDJSON_CONFIG
 74    \brief Version of RapidJSON in "<major>.<minor>.<patch>" string format.
 75*/
 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)
 81
 82///////////////////////////////////////////////////////////////////////////////
 83// RAPIDJSON_NAMESPACE_(BEGIN|END)
 84/*! \def RAPIDJSON_NAMESPACE
 85    \ingroup RAPIDJSON_CONFIG
 86    \brief   provide custom rapidjson namespace
 87
 88    In order to avoid symbol clashes and/or "One Definition Rule" errors
 89    between multiple inclusions of (different versions of) RapidJSON in
 90    a single binary, users can customize the name of the main RapidJSON
 91    namespace.
 92
 93    In case of a single nesting level, defining \c RAPIDJSON_NAMESPACE
 94    to a custom name (e.g. \c MyRapidJSON) is sufficient.  If multiple
 95    levels are needed, both \ref RAPIDJSON_NAMESPACE_BEGIN and \ref
 96    RAPIDJSON_NAMESPACE_END need to be defined as well:
 97
 98    \code
 99    // in some .cpp file
100    #define RAPIDJSON_NAMESPACE my::rapidjson
101    #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson {
102    #define RAPIDJSON_NAMESPACE_END   } }
103    #include "rapidjson/..."
104    \endcode
105
106    \see rapidjson
107 */
108/*! \def RAPIDJSON_NAMESPACE_BEGIN
109    \ingroup RAPIDJSON_CONFIG
110    \brief   provide custom rapidjson namespace (opening expression)
111    \see RAPIDJSON_NAMESPACE
112*/
113/*! \def RAPIDJSON_NAMESPACE_END
114    \ingroup RAPIDJSON_CONFIG
115    \brief   provide custom rapidjson namespace (closing expression)
116    \see RAPIDJSON_NAMESPACE
117*/
118#ifndef RAPIDJSON_NAMESPACE
119#define RAPIDJSON_NAMESPACE rapidjson
120#endif
121#ifndef RAPIDJSON_NAMESPACE_BEGIN
122#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
123#endif
124#ifndef RAPIDJSON_NAMESPACE_END
125#define RAPIDJSON_NAMESPACE_END }
126#endif
127
128///////////////////////////////////////////////////////////////////////////////
129// RAPIDJSON_HAS_STDSTRING
130
131#ifndef RAPIDJSON_HAS_STDSTRING
132#ifdef RAPIDJSON_DOXYGEN_RUNNING
133#define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
134#else
135#define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
136#endif
137/*! \def RAPIDJSON_HAS_STDSTRING
138    \ingroup RAPIDJSON_CONFIG
139    \brief Enable RapidJSON support for \c std::string
140
141    By defining this preprocessor symbol to \c 1, several convenience functions for using
142    \ref rapidjson::GenericValue with \c std::string are enabled, especially
143    for construction and comparison.
144
145    \hideinitializer
146*/
147#endif // !defined(RAPIDJSON_HAS_STDSTRING)
148
149#if RAPIDJSON_HAS_STDSTRING
150#include <string>
151#endif // RAPIDJSON_HAS_STDSTRING
152
153///////////////////////////////////////////////////////////////////////////////
154// RAPIDJSON_NO_INT64DEFINE
155
156/*! \def RAPIDJSON_NO_INT64DEFINE
157    \ingroup RAPIDJSON_CONFIG
158    \brief Use external 64-bit integer types.
159
160    RapidJSON requires the 64-bit integer types \c int64_t and  \c uint64_t types
161    to be available at global scope.
162
163    If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to
164    prevent RapidJSON from defining its own types.
165*/
166#ifndef RAPIDJSON_NO_INT64DEFINE
167//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
168#if defined(_MSC_VER) && (_MSC_VER < 1800)   // Visual Studio 2013
169#include "msinttypes/stdint.h"
170#include "msinttypes/inttypes.h"
171#else
172// Other compilers should have this.
173#include <stdint.h>
174#include <inttypes.h>
175#endif
176//!@endcond
177#ifdef RAPIDJSON_DOXYGEN_RUNNING
178#define RAPIDJSON_NO_INT64DEFINE
179#endif
180#endif // RAPIDJSON_NO_INT64TYPEDEF
181
182///////////////////////////////////////////////////////////////////////////////
183// RAPIDJSON_FORCEINLINE
184
185#ifndef RAPIDJSON_FORCEINLINE
186//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
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))
191#else
192#define RAPIDJSON_FORCEINLINE
193#endif
194//!@endcond
195#endif // RAPIDJSON_FORCEINLINE
196
197///////////////////////////////////////////////////////////////////////////////
198// RAPIDJSON_ENDIAN
199#define RAPIDJSON_LITTLEENDIAN  0   //!< Little endian machine
200#define RAPIDJSON_BIGENDIAN     1   //!< Big endian machine
201
202//! Endianness of the machine.
203/*!
204    \def RAPIDJSON_ENDIAN
205    \ingroup RAPIDJSON_CONFIG
206
207    GCC 4.6 provided macro for detecting endianness of the target machine. But other
208    compilers may not have this. User can define RAPIDJSON_ENDIAN to either
209    \ref RAPIDJSON_LITTLEENDIAN or \ref RAPIDJSON_BIGENDIAN.
210
211    Default detection implemented with reference to
212    \li https://gcc.gnu.org/onlinedocs/gcc-4.6.0/cpp/Common-Predefined-Macros.html
213    \li http://www.boost.org/doc/libs/1_42_0/boost/detail/endian.hpp
214*/
215#ifndef RAPIDJSON_ENDIAN
216// Detect with GCC 4.6's macro
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
222#    else
223#      error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
224#    endif // __BYTE_ORDER__
225// Detect with GLIBC's endian.h
226#  elif defined(__GLIBC__)
227#    include <endian.h>
228#    if (__BYTE_ORDER == __LITTLE_ENDIAN)
229#      define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
230#    elif (__BYTE_ORDER == __BIG_ENDIAN)
231#      define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
232#    else
233#      error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
234#   endif // __GLIBC__
235// Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
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
240// Detect with architecture macros
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
249#  else
250#    error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.   
251#  endif
252#endif // RAPIDJSON_ENDIAN
253
254///////////////////////////////////////////////////////////////////////////////
255// RAPIDJSON_64BIT
256
257//! Whether using 64-bit architecture
258#ifndef RAPIDJSON_64BIT
259#if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
260#define RAPIDJSON_64BIT 1
261#else
262#define RAPIDJSON_64BIT 0
263#endif
264#endif // RAPIDJSON_64BIT
265
266///////////////////////////////////////////////////////////////////////////////
267// RAPIDJSON_ALIGN
268
269//! Data alignment of the machine.
270/*! \ingroup RAPIDJSON_CONFIG
271    \param x pointer to align
272
273    Some machines require strict data alignment. The default is 8 bytes.
274    User can customize by defining the RAPIDJSON_ALIGN function macro.
275*/
276#ifndef RAPIDJSON_ALIGN
277#define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
278#endif
279
280///////////////////////////////////////////////////////////////////////////////
281// RAPIDJSON_UINT64_C2
282
283//! Construct a 64-bit literal by a pair of 32-bit integer.
284/*!
285    64-bit literal with or without ULL suffix is prone to compiler warnings.
286    UINT64_C() is C macro which cause compilation problems.
287    Use this macro to define 64-bit constants by a pair of 32-bit integer.
288*/
289#ifndef RAPIDJSON_UINT64_C2
290#define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
291#endif
292
293///////////////////////////////////////////////////////////////////////////////
294// RAPIDJSON_48BITPOINTER_OPTIMIZATION
295
296//! Use only lower 48-bit address for some pointers.
297/*!
298    \ingroup RAPIDJSON_CONFIG
299
300    This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address.
301    The higher 16-bit can be used for storing other data.
302    \c GenericValue uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture.
303*/
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
307#else
308#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
309#endif
310#endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
311
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
315#endif
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))))
318#else
319#define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
320#define RAPIDJSON_GETPOINTER(type, p) (p)
321#endif
322
323///////////////////////////////////////////////////////////////////////////////
324// RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_NEON/RAPIDJSON_SIMD
325
326/*! \def RAPIDJSON_SIMD
327    \ingroup RAPIDJSON_CONFIG
328    \brief Enable SSE2/SSE4.2/Neon optimization.
329
330    RapidJSON supports optimized implementations for some parsing operations
331    based on the SSE2, SSE4.2 or NEon SIMD extensions on modern Intel
332    or ARM compatible processors.
333
334    To enable these optimizations, three different symbols can be defined;
335    \code
336    // Enable SSE2 optimization.
337    #define RAPIDJSON_SSE2
338
339    // Enable SSE4.2 optimization.
340    #define RAPIDJSON_SSE42
341    \endcode
342
343    // Enable ARM Neon optimization.
344    #define RAPIDJSON_NEON
345    \endcode
346
347    \c RAPIDJSON_SSE42 takes precedence over SSE2, if both are defined.
348
349    If any of these symbols is defined, RapidJSON defines the macro
350    \c RAPIDJSON_SIMD to indicate the availability of the optimized code.
351*/
352#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
353    || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
354#define RAPIDJSON_SIMD
355#endif
356
357///////////////////////////////////////////////////////////////////////////////
358// RAPIDJSON_NO_SIZETYPEDEFINE
359
360#ifndef RAPIDJSON_NO_SIZETYPEDEFINE
361/*! \def RAPIDJSON_NO_SIZETYPEDEFINE
362    \ingroup RAPIDJSON_CONFIG
363    \brief User-provided \c SizeType definition.
364
365    In order to avoid using 32-bit size types for indexing strings and arrays,
366    define this preprocessor symbol and provide the type rapidjson::SizeType
367    before including RapidJSON:
368    \code
369    #define RAPIDJSON_NO_SIZETYPEDEFINE
370    namespace rapidjson { typedef ::std::size_t SizeType; }
371    #include "rapidjson/..."
372    \endcode
373
374    \see rapidjson::SizeType
375*/
376#ifdef RAPIDJSON_DOXYGEN_RUNNING
377#define RAPIDJSON_NO_SIZETYPEDEFINE
378#endif
379RAPIDJSON_NAMESPACE_BEGIN
380//! Size type (for string lengths, array sizes, etc.)
381/*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms,
382    instead of using \c size_t. Users may override the SizeType by defining
383    \ref RAPIDJSON_NO_SIZETYPEDEFINE.
384*/
385typedef unsigned SizeType;
386RAPIDJSON_NAMESPACE_END
387#endif
388
389// always import std::size_t to rapidjson namespace
390RAPIDJSON_NAMESPACE_BEGIN
391using std::size_t;
392RAPIDJSON_NAMESPACE_END
393
394///////////////////////////////////////////////////////////////////////////////
395// RAPIDJSON_ASSERT
396
397//! Assertion.
398/*! \ingroup RAPIDJSON_CONFIG
399    By default, rapidjson uses C \c assert() for internal assertions.
400    User can override it by defining RAPIDJSON_ASSERT(x) macro.
401
402    \note Parsing errors are handled and can be customized by the
403          \ref RAPIDJSON_ERRORS APIs.
404*/
405#ifndef RAPIDJSON_ASSERT
406#include <cassert>
407#define RAPIDJSON_ASSERT(x) assert(x)
408#endif // RAPIDJSON_ASSERT
409
410///////////////////////////////////////////////////////////////////////////////
411// RAPIDJSON_STATIC_ASSERT
412
413// Prefer C++11 static_assert, if available
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))
418#endif // C++11
419#endif // RAPIDJSON_STATIC_ASSERT
420
421// Adopt C++03 implementation from boost
422#ifndef RAPIDJSON_STATIC_ASSERT
423#ifndef __clang__
424//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
425#endif
426RAPIDJSON_NAMESPACE_BEGIN
427template <bool x> struct STATIC_ASSERTION_FAILURE;
428template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
429template <size_t x> struct StaticAssertTest {};
430RAPIDJSON_NAMESPACE_END
431
432#if defined(__GNUC__) || defined(__clang__)
433#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
434#else
435#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE 
436#endif
437#ifndef __clang__
438//!@endcond
439#endif
440
441/*! \def RAPIDJSON_STATIC_ASSERT
442    \brief (Internal) macro to check for conditions at compile-time
443    \param x compile-time condition
444    \hideinitializer
445 */
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
450#endif // RAPIDJSON_STATIC_ASSERT
451
452///////////////////////////////////////////////////////////////////////////////
453// RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY
454
455//! Compiler branching hint for expression with high probability to be true.
456/*!
457    \ingroup RAPIDJSON_CONFIG
458    \param x Boolean expression likely to be true.
459*/
460#ifndef RAPIDJSON_LIKELY
461#if defined(__GNUC__) || defined(__clang__)
462#define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
463#else
464#define RAPIDJSON_LIKELY(x) (x)
465#endif
466#endif
467
468//! Compiler branching hint for expression with low probability to be true.
469/*!
470    \ingroup RAPIDJSON_CONFIG
471    \param x Boolean expression unlikely to be true.
472*/
473#ifndef RAPIDJSON_UNLIKELY
474#if defined(__GNUC__) || defined(__clang__)
475#define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
476#else
477#define RAPIDJSON_UNLIKELY(x) (x)
478#endif
479#endif
480
481///////////////////////////////////////////////////////////////////////////////
482// Helpers
483
484//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
485
486#define RAPIDJSON_MULTILINEMACRO_BEGIN do {  
487#define RAPIDJSON_MULTILINEMACRO_END \
488} while((void)0, 0)
489
490// adopted from Boost
491#define RAPIDJSON_VERSION_CODE(x,y,z) \
492  (((x)*100000) + ((y)*100) + (z))
493
494///////////////////////////////////////////////////////////////////////////////
495// RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
496
497#if defined(__GNUC__)
498#define RAPIDJSON_GNUC \
499    RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
500#endif
501
502#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
503
504#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
505#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
506#define RAPIDJSON_DIAG_OFF(x) \
507    RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
508
509// push/pop support in Clang and GCC>=4.6
510#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
511#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
512#define RAPIDJSON_DIAG_POP  RAPIDJSON_DIAG_PRAGMA(pop)
513#else // GCC >= 4.2, < 4.6
514#define RAPIDJSON_DIAG_PUSH /* ignored */
515#define RAPIDJSON_DIAG_POP /* ignored */
516#endif
517
518#elif defined(_MSC_VER)
519
520// pragma (MSVC specific)
521#define RAPIDJSON_PRAGMA(x) __pragma(x)
522#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
523
524#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
525#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
526#define RAPIDJSON_DIAG_POP  RAPIDJSON_DIAG_PRAGMA(pop)
527
528#else
529
530#define RAPIDJSON_DIAG_OFF(x) /* ignored */
531#define RAPIDJSON_DIAG_PUSH   /* ignored */
532#define RAPIDJSON_DIAG_POP    /* ignored */
533
534#endif // RAPIDJSON_DIAG_*
535
536///////////////////////////////////////////////////////////////////////////////
537// C++11 features
538
539#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
540#if defined(__clang__)
541#if __has_feature(cxx_rvalue_references) && \
542    (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
543#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
544#else
545#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
546#endif
547#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
548      (defined(_MSC_VER) && _MSC_VER >= 1600) || \
549      (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
550
551#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
552#else
553#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
554#endif
555#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
556
557#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
558#if defined(__clang__)
559#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
560#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
561    (defined(_MSC_VER) && _MSC_VER >= 1900) || \
562    (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
563#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
564#else
565#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
566#endif
567#endif
568#if RAPIDJSON_HAS_CXX11_NOEXCEPT
569#define RAPIDJSON_NOEXCEPT noexcept
570#else
571#define RAPIDJSON_NOEXCEPT /* noexcept */
572#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
573
574// no automatic detection, yet
575#ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
576#if (defined(_MSC_VER) && _MSC_VER >= 1700)
577#define RAPIDJSON_HAS_CXX11_TYPETRAITS 1
578#else
579#define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
580#endif
581#endif
582
583#ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
584#if defined(__clang__)
585#define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
586#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
587      (defined(_MSC_VER) && _MSC_VER >= 1700) || \
588      (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
589#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
590#else
591#define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
592#endif
593#endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
594
595//!@endcond
596
597//! Assertion (in non-throwing contexts).
598 /*! \ingroup RAPIDJSON_CONFIG
599    Some functions provide a \c noexcept guarantee, if the compiler supports it.
600    In these cases, the \ref RAPIDJSON_ASSERT macro cannot be overridden to
601    throw an exception.  This macro adds a separate customization point for
602    such cases.
603
604    Defaults to C \c assert() (as \ref RAPIDJSON_ASSERT), if \c noexcept is
605    supported, and to \ref RAPIDJSON_ASSERT otherwise.
606 */
607
608///////////////////////////////////////////////////////////////////////////////
609// RAPIDJSON_NOEXCEPT_ASSERT
610
611#ifndef RAPIDJSON_NOEXCEPT_ASSERT
612#ifdef RAPIDJSON_ASSERT_THROWS
613#if RAPIDJSON_HAS_CXX11_NOEXCEPT
614#define RAPIDJSON_NOEXCEPT_ASSERT(x)
615#else
616#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
617#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
618#else
619#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
620#endif // RAPIDJSON_ASSERT_THROWS
621#endif // RAPIDJSON_NOEXCEPT_ASSERT
622
623///////////////////////////////////////////////////////////////////////////////
624// new/delete
625
626#ifndef RAPIDJSON_NEW
627///! customization point for global \c new
628#define RAPIDJSON_NEW(TypeName) new TypeName
629#endif
630#ifndef RAPIDJSON_DELETE
631///! customization point for global \c delete
632#define RAPIDJSON_DELETE(x) delete x
633#endif
634
635///////////////////////////////////////////////////////////////////////////////
636// Type
637
638/*! \namespace rapidjson
639    \brief main RapidJSON namespace
640    \see RAPIDJSON_NAMESPACE
641*/
642RAPIDJSON_NAMESPACE_BEGIN
643
644//! Type of JSON value
645enum Type {
646    kNullType = 0,      //!< null
647    kFalseType = 1,     //!< false
648    kTrueType = 2,      //!< true
649    kObjectType = 3,    //!< object
650    kArrayType = 4,     //!< array 
651    kStringType = 5,    //!< string
652    kNumberType = 6     //!< number
653};
654
655RAPIDJSON_NAMESPACE_END
656
657#endif // RAPIDJSON_RAPIDJSON_H_
658