Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/rapidjson/rapidjson.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Tencent is pleased to support the open source community by making RapidJSON available.
0002 //
0003 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
0004 //
0005 // Licensed under the MIT License (the "License"); you may not use this file except
0006 // in compliance with the License. You may obtain a copy of the License at
0007 //
0008 // http://opensource.org/licenses/MIT
0009 //
0010 // Unless required by applicable law or agreed to in writing, software distributed
0011 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
0012 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
0013 // specific language governing permissions and limitations under the License.
0014 
0015 #ifndef RAPIDJSON_RAPIDJSON_H_
0016 #define RAPIDJSON_RAPIDJSON_H_
0017 
0018 /*!\file rapidjson.h
0019     \brief common definitions and configuration
0020 
0021     \see RAPIDJSON_CONFIG
0022  */
0023 
0024 /*! \defgroup RAPIDJSON_CONFIG RapidJSON configuration
0025     \brief Configuration macros for library features
0026 
0027     Some RapidJSON features are configurable to adapt the library to a wide
0028     variety of platforms, environments and usage scenarios.  Most of the
0029     features can be configured in terms of overridden or predefined
0030     preprocessor macros at compile-time.
0031 
0032     Some additional customization is available in the \ref RAPIDJSON_ERRORS APIs.
0033 
0034     \note These macros should be given on the compiler command-line
0035           (where applicable)  to avoid inconsistent values when compiling
0036           different translation units of a single application.
0037  */
0038 
0039 #include <cstdlib>  // malloc(), realloc(), free(), size_t
0040 #include <cstring>  // memset(), memcpy(), memmove(), memcmp()
0041 
0042 ///////////////////////////////////////////////////////////////////////////////
0043 // RAPIDJSON_VERSION_STRING
0044 //
0045 // ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt.
0046 //
0047 
0048 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
0049 // token stringification
0050 #define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
0051 #define RAPIDJSON_DO_STRINGIFY(x) #x
0052 
0053 // token concatenation
0054 #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
0055 #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
0056 #define RAPIDJSON_DO_JOIN2(X, Y) X##Y
0057 //!@endcond
0058 
0059 /*! \def RAPIDJSON_MAJOR_VERSION
0060     \ingroup RAPIDJSON_CONFIG
0061     \brief Major version of RapidJSON in integer.
0062 */
0063 /*! \def RAPIDJSON_MINOR_VERSION
0064     \ingroup RAPIDJSON_CONFIG
0065     \brief Minor version of RapidJSON in integer.
0066 */
0067 /*! \def RAPIDJSON_PATCH_VERSION
0068     \ingroup RAPIDJSON_CONFIG
0069     \brief Patch version of RapidJSON in integer.
0070 */
0071 /*! \def RAPIDJSON_VERSION_STRING
0072     \ingroup RAPIDJSON_CONFIG
0073     \brief Version of RapidJSON in "<major>.<minor>.<patch>" string format.
0074 */
0075 #define RAPIDJSON_MAJOR_VERSION 1
0076 #define RAPIDJSON_MINOR_VERSION 1
0077 #define RAPIDJSON_PATCH_VERSION 0
0078 #define RAPIDJSON_VERSION_STRING \
0079     RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
0080 
0081 ///////////////////////////////////////////////////////////////////////////////
0082 // RAPIDJSON_NAMESPACE_(BEGIN|END)
0083 /*! \def RAPIDJSON_NAMESPACE
0084     \ingroup RAPIDJSON_CONFIG
0085     \brief   provide custom rapidjson namespace
0086 
0087     In order to avoid symbol clashes and/or "One Definition Rule" errors
0088     between multiple inclusions of (different versions of) RapidJSON in
0089     a single binary, users can customize the name of the main RapidJSON
0090     namespace.
0091 
0092     In case of a single nesting level, defining \c RAPIDJSON_NAMESPACE
0093     to a custom name (e.g. \c MyRapidJSON) is sufficient.  If multiple
0094     levels are needed, both \ref RAPIDJSON_NAMESPACE_BEGIN and \ref
0095     RAPIDJSON_NAMESPACE_END need to be defined as well:
0096 
0097     \code
0098     // in some .cpp file
0099     #define RAPIDJSON_NAMESPACE my::rapidjson
0100     #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson {
0101     #define RAPIDJSON_NAMESPACE_END   } }
0102     #include "rapidjson/..."
0103     \endcode
0104 
0105     \see rapidjson
0106  */
0107 /*! \def RAPIDJSON_NAMESPACE_BEGIN
0108     \ingroup RAPIDJSON_CONFIG
0109     \brief   provide custom rapidjson namespace (opening expression)
0110     \see RAPIDJSON_NAMESPACE
0111 */
0112 /*! \def RAPIDJSON_NAMESPACE_END
0113     \ingroup RAPIDJSON_CONFIG
0114     \brief   provide custom rapidjson namespace (closing expression)
0115     \see RAPIDJSON_NAMESPACE
0116 */
0117 #ifndef RAPIDJSON_NAMESPACE
0118 #define RAPIDJSON_NAMESPACE rapidjson
0119 #endif
0120 #ifndef RAPIDJSON_NAMESPACE_BEGIN
0121 #define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
0122 #endif
0123 #ifndef RAPIDJSON_NAMESPACE_END
0124 #define RAPIDJSON_NAMESPACE_END }
0125 #endif
0126 
0127 ///////////////////////////////////////////////////////////////////////////////
0128 // __cplusplus macro
0129 
0130 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
0131 
0132 #if defined(_MSC_VER)
0133 #define RAPIDJSON_CPLUSPLUS _MSVC_LANG
0134 #else
0135 #define RAPIDJSON_CPLUSPLUS __cplusplus
0136 #endif
0137 
0138 //!@endcond
0139 
0140 ///////////////////////////////////////////////////////////////////////////////
0141 // RAPIDJSON_HAS_STDSTRING
0142 
0143 #ifndef RAPIDJSON_HAS_STDSTRING
0144 #ifdef RAPIDJSON_DOXYGEN_RUNNING
0145 #define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
0146 #else
0147 #define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
0148 #endif
0149 /*! \def RAPIDJSON_HAS_STDSTRING
0150     \ingroup RAPIDJSON_CONFIG
0151     \brief Enable RapidJSON support for \c std::string
0152 
0153     By defining this preprocessor symbol to \c 1, several convenience functions for using
0154     \ref rapidjson::GenericValue with \c std::string are enabled, especially
0155     for construction and comparison.
0156 
0157     \hideinitializer
0158 */
0159 #endif // !defined(RAPIDJSON_HAS_STDSTRING)
0160 
0161 #if RAPIDJSON_HAS_STDSTRING
0162 #include <string>
0163 #endif // RAPIDJSON_HAS_STDSTRING
0164 
0165 ///////////////////////////////////////////////////////////////////////////////
0166 // RAPIDJSON_USE_MEMBERSMAP
0167 
0168 /*! \def RAPIDJSON_USE_MEMBERSMAP
0169     \ingroup RAPIDJSON_CONFIG
0170     \brief Enable RapidJSON support for object members handling in a \c std::multimap
0171 
0172     By defining this preprocessor symbol to \c 1, \ref rapidjson::GenericValue object
0173     members are stored in a \c std::multimap for faster lookup and deletion times, a
0174     trade off with a slightly slower insertion time and a small object allocat(or)ed
0175     memory overhead.
0176 
0177     \hideinitializer
0178 */
0179 #ifndef RAPIDJSON_USE_MEMBERSMAP
0180 #define RAPIDJSON_USE_MEMBERSMAP 0 // not by default
0181 #endif
0182 
0183 ///////////////////////////////////////////////////////////////////////////////
0184 // RAPIDJSON_NO_INT64DEFINE
0185 
0186 /*! \def RAPIDJSON_NO_INT64DEFINE
0187     \ingroup RAPIDJSON_CONFIG
0188     \brief Use external 64-bit integer types.
0189 
0190     RapidJSON requires the 64-bit integer types \c int64_t and  \c uint64_t types
0191     to be available at global scope.
0192 
0193     If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to
0194     prevent RapidJSON from defining its own types.
0195 */
0196 #ifndef RAPIDJSON_NO_INT64DEFINE
0197 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
0198 #if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013
0199 #include "msinttypes/stdint.h"
0200 #include "msinttypes/inttypes.h"
0201 #else
0202 // Other compilers should have this.
0203 #include <stdint.h>
0204 #include <inttypes.h>
0205 #endif
0206 //!@endcond
0207 #ifdef RAPIDJSON_DOXYGEN_RUNNING
0208 #define RAPIDJSON_NO_INT64DEFINE
0209 #endif
0210 #endif // RAPIDJSON_NO_INT64TYPEDEF
0211 
0212 ///////////////////////////////////////////////////////////////////////////////
0213 // RAPIDJSON_FORCEINLINE
0214 
0215 #ifndef RAPIDJSON_FORCEINLINE
0216 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
0217 #if defined(_MSC_VER) && defined(NDEBUG)
0218 #define RAPIDJSON_FORCEINLINE __forceinline
0219 #elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
0220 #define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
0221 #else
0222 #define RAPIDJSON_FORCEINLINE
0223 #endif
0224 //!@endcond
0225 #endif // RAPIDJSON_FORCEINLINE
0226 
0227 ///////////////////////////////////////////////////////////////////////////////
0228 // RAPIDJSON_ENDIAN
0229 #define RAPIDJSON_LITTLEENDIAN  0   //!< Little endian machine
0230 #define RAPIDJSON_BIGENDIAN     1   //!< Big endian machine
0231 
0232 //! Endianness of the machine.
0233 /*!
0234     \def RAPIDJSON_ENDIAN
0235     \ingroup RAPIDJSON_CONFIG
0236 
0237     GCC 4.6 provided macro for detecting endianness of the target machine. But other
0238     compilers may not have this. User can define RAPIDJSON_ENDIAN to either
0239     \ref RAPIDJSON_LITTLEENDIAN or \ref RAPIDJSON_BIGENDIAN.
0240 
0241     Default detection implemented with reference to
0242     \li https://gcc.gnu.org/onlinedocs/gcc-4.6.0/cpp/Common-Predefined-Macros.html
0243     \li http://www.boost.org/doc/libs/1_42_0/boost/detail/endian.hpp
0244 */
0245 #ifndef RAPIDJSON_ENDIAN
0246 // Detect with GCC 4.6's macro
0247 #  ifdef __BYTE_ORDER__
0248 #    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
0249 #      define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
0250 #    elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
0251 #      define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
0252 #    else
0253 #      error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
0254 #    endif // __BYTE_ORDER__
0255 // Detect with GLIBC's endian.h
0256 #  elif defined(__GLIBC__)
0257 #    include <endian.h>
0258 #    if (__BYTE_ORDER == __LITTLE_ENDIAN)
0259 #      define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
0260 #    elif (__BYTE_ORDER == __BIG_ENDIAN)
0261 #      define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
0262 #    else
0263 #      error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
0264 #   endif // __GLIBC__
0265 // Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
0266 #  elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
0267 #    define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
0268 #  elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
0269 #    define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
0270 // Detect with architecture macros
0271 #  elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
0272 #    define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
0273 #  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__)
0274 #    define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
0275 #  elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
0276 #    define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
0277 #  elif defined(RAPIDJSON_DOXYGEN_RUNNING)
0278 #    define RAPIDJSON_ENDIAN
0279 #  else
0280 #    error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
0281 #  endif
0282 #endif // RAPIDJSON_ENDIAN
0283 
0284 ///////////////////////////////////////////////////////////////////////////////
0285 // RAPIDJSON_64BIT
0286 
0287 //! Whether using 64-bit architecture
0288 #ifndef RAPIDJSON_64BIT
0289 #if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
0290 #define RAPIDJSON_64BIT 1
0291 #else
0292 #define RAPIDJSON_64BIT 0
0293 #endif
0294 #endif // RAPIDJSON_64BIT
0295 
0296 ///////////////////////////////////////////////////////////////////////////////
0297 // RAPIDJSON_ALIGN
0298 
0299 //! Data alignment of the machine.
0300 /*! \ingroup RAPIDJSON_CONFIG
0301     \param x pointer to align
0302 
0303     Some machines require strict data alignment. The default is 8 bytes.
0304     User can customize by defining the RAPIDJSON_ALIGN function macro.
0305 */
0306 #ifndef RAPIDJSON_ALIGN
0307 #define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
0308 #endif
0309 
0310 ///////////////////////////////////////////////////////////////////////////////
0311 // RAPIDJSON_UINT64_C2
0312 
0313 //! Construct a 64-bit literal by a pair of 32-bit integer.
0314 /*!
0315     64-bit literal with or without ULL suffix is prone to compiler warnings.
0316     UINT64_C() is C macro which cause compilation problems.
0317     Use this macro to define 64-bit constants by a pair of 32-bit integer.
0318 */
0319 #ifndef RAPIDJSON_UINT64_C2
0320 #define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
0321 #endif
0322 
0323 ///////////////////////////////////////////////////////////////////////////////
0324 // RAPIDJSON_48BITPOINTER_OPTIMIZATION
0325 
0326 //! Use only lower 48-bit address for some pointers.
0327 /*!
0328     \ingroup RAPIDJSON_CONFIG
0329 
0330     This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address.
0331     The higher 16-bit can be used for storing other data.
0332     \c GenericValue uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture.
0333 */
0334 #ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
0335 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
0336 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
0337 #else
0338 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
0339 #endif
0340 #endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
0341 
0342 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
0343 #if RAPIDJSON_64BIT != 1
0344 #error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
0345 #endif
0346 #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))))
0347 #define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
0348 #else
0349 #define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
0350 #define RAPIDJSON_GETPOINTER(type, p) (p)
0351 #endif
0352 
0353 ///////////////////////////////////////////////////////////////////////////////
0354 // RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_NEON/RAPIDJSON_SIMD
0355 
0356 /*! \def RAPIDJSON_SIMD
0357     \ingroup RAPIDJSON_CONFIG
0358     \brief Enable SSE2/SSE4.2/Neon optimization.
0359 
0360     RapidJSON supports optimized implementations for some parsing operations
0361     based on the SSE2, SSE4.2 or NEon SIMD extensions on modern Intel
0362     or ARM compatible processors.
0363 
0364     To enable these optimizations, three different symbols can be defined;
0365     \code
0366     // Enable SSE2 optimization.
0367     #define RAPIDJSON_SSE2
0368 
0369     // Enable SSE4.2 optimization.
0370     #define RAPIDJSON_SSE42
0371     \endcode
0372 
0373     // Enable ARM Neon optimization.
0374     #define RAPIDJSON_NEON
0375     \endcode
0376 
0377     \c RAPIDJSON_SSE42 takes precedence over SSE2, if both are defined.
0378 
0379     If any of these symbols is defined, RapidJSON defines the macro
0380     \c RAPIDJSON_SIMD to indicate the availability of the optimized code.
0381 */
0382 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
0383     || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
0384 #define RAPIDJSON_SIMD
0385 #endif
0386 
0387 ///////////////////////////////////////////////////////////////////////////////
0388 // RAPIDJSON_NO_SIZETYPEDEFINE
0389 
0390 #ifndef RAPIDJSON_NO_SIZETYPEDEFINE
0391 /*! \def RAPIDJSON_NO_SIZETYPEDEFINE
0392     \ingroup RAPIDJSON_CONFIG
0393     \brief User-provided \c SizeType definition.
0394 
0395     In order to avoid using 32-bit size types for indexing strings and arrays,
0396     define this preprocessor symbol and provide the type rapidjson::SizeType
0397     before including RapidJSON:
0398     \code
0399     #define RAPIDJSON_NO_SIZETYPEDEFINE
0400     namespace rapidjson { typedef ::std::size_t SizeType; }
0401     #include "rapidjson/..."
0402     \endcode
0403 
0404     \see rapidjson::SizeType
0405 */
0406 #ifdef RAPIDJSON_DOXYGEN_RUNNING
0407 #define RAPIDJSON_NO_SIZETYPEDEFINE
0408 #endif
0409 RAPIDJSON_NAMESPACE_BEGIN
0410 //! Size type (for string lengths, array sizes, etc.)
0411 /*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms,
0412     instead of using \c size_t. Users may override the SizeType by defining
0413     \ref RAPIDJSON_NO_SIZETYPEDEFINE.
0414 */
0415 typedef unsigned SizeType;
0416 RAPIDJSON_NAMESPACE_END
0417 #endif
0418 
0419 // always import std::size_t to rapidjson namespace
0420 RAPIDJSON_NAMESPACE_BEGIN
0421 using std::size_t;
0422 RAPIDJSON_NAMESPACE_END
0423 
0424 ///////////////////////////////////////////////////////////////////////////////
0425 // RAPIDJSON_ASSERT
0426 
0427 //! Assertion.
0428 /*! \ingroup RAPIDJSON_CONFIG
0429     By default, rapidjson uses C \c assert() for internal assertions.
0430     User can override it by defining RAPIDJSON_ASSERT(x) macro.
0431 
0432     \note Parsing errors are handled and can be customized by the
0433           \ref RAPIDJSON_ERRORS APIs.
0434 */
0435 #ifndef RAPIDJSON_ASSERT
0436 #include <cassert>
0437 #define RAPIDJSON_ASSERT(x) assert(x)
0438 #endif // RAPIDJSON_ASSERT
0439 
0440 ///////////////////////////////////////////////////////////////////////////////
0441 // RAPIDJSON_STATIC_ASSERT
0442 
0443 // Prefer C++11 static_assert, if available
0444 #ifndef RAPIDJSON_STATIC_ASSERT
0445 #if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
0446 #define RAPIDJSON_STATIC_ASSERT(x) \
0447    static_assert(x, RAPIDJSON_STRINGIFY(x))
0448 #endif // C++11
0449 #endif // RAPIDJSON_STATIC_ASSERT
0450 
0451 // Adopt C++03 implementation from boost
0452 #ifndef RAPIDJSON_STATIC_ASSERT
0453 #ifndef __clang__
0454 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
0455 #endif
0456 RAPIDJSON_NAMESPACE_BEGIN
0457 template <bool x> struct STATIC_ASSERTION_FAILURE;
0458 template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
0459 template <size_t x> struct StaticAssertTest {};
0460 RAPIDJSON_NAMESPACE_END
0461 
0462 #if defined(__GNUC__) || defined(__clang__)
0463 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
0464 #else
0465 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE 
0466 #endif
0467 #ifndef __clang__
0468 //!@endcond
0469 #endif
0470 
0471 /*! \def RAPIDJSON_STATIC_ASSERT
0472     \brief (Internal) macro to check for conditions at compile-time
0473     \param x compile-time condition
0474     \hideinitializer
0475  */
0476 #define RAPIDJSON_STATIC_ASSERT(x) \
0477     typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
0478       sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
0479     RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
0480 #endif // RAPIDJSON_STATIC_ASSERT
0481 
0482 ///////////////////////////////////////////////////////////////////////////////
0483 // RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY
0484 
0485 //! Compiler branching hint for expression with high probability to be true.
0486 /*!
0487     \ingroup RAPIDJSON_CONFIG
0488     \param x Boolean expression likely to be true.
0489 */
0490 #ifndef RAPIDJSON_LIKELY
0491 #if defined(__GNUC__) || defined(__clang__)
0492 #define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
0493 #else
0494 #define RAPIDJSON_LIKELY(x) (x)
0495 #endif
0496 #endif
0497 
0498 //! Compiler branching hint for expression with low probability to be true.
0499 /*!
0500     \ingroup RAPIDJSON_CONFIG
0501     \param x Boolean expression unlikely to be true.
0502 */
0503 #ifndef RAPIDJSON_UNLIKELY
0504 #if defined(__GNUC__) || defined(__clang__)
0505 #define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
0506 #else
0507 #define RAPIDJSON_UNLIKELY(x) (x)
0508 #endif
0509 #endif
0510 
0511 ///////////////////////////////////////////////////////////////////////////////
0512 // Helpers
0513 
0514 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
0515 
0516 #define RAPIDJSON_MULTILINEMACRO_BEGIN do {
0517 #define RAPIDJSON_MULTILINEMACRO_END \
0518 } while((void)0, 0)
0519 
0520 // adopted from Boost
0521 #define RAPIDJSON_VERSION_CODE(x,y,z) \
0522   (((x)*100000) + ((y)*100) + (z))
0523 
0524 #if defined(__has_builtin)
0525 #define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x)
0526 #else
0527 #define RAPIDJSON_HAS_BUILTIN(x) 0
0528 #endif
0529 
0530 ///////////////////////////////////////////////////////////////////////////////
0531 // RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
0532 
0533 #if defined(__GNUC__)
0534 #define RAPIDJSON_GNUC \
0535     RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
0536 #endif
0537 
0538 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
0539 
0540 #define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
0541 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
0542 #define RAPIDJSON_DIAG_OFF(x) \
0543     RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
0544 
0545 // push/pop support in Clang and GCC>=4.6
0546 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
0547 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
0548 #define RAPIDJSON_DIAG_POP  RAPIDJSON_DIAG_PRAGMA(pop)
0549 #else // GCC >= 4.2, < 4.6
0550 #define RAPIDJSON_DIAG_PUSH /* ignored */
0551 #define RAPIDJSON_DIAG_POP /* ignored */
0552 #endif
0553 
0554 #elif defined(_MSC_VER)
0555 
0556 // pragma (MSVC specific)
0557 #define RAPIDJSON_PRAGMA(x) __pragma(x)
0558 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
0559 
0560 #define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
0561 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
0562 #define RAPIDJSON_DIAG_POP  RAPIDJSON_DIAG_PRAGMA(pop)
0563 
0564 #else
0565 
0566 #define RAPIDJSON_DIAG_OFF(x) /* ignored */
0567 #define RAPIDJSON_DIAG_PUSH   /* ignored */
0568 #define RAPIDJSON_DIAG_POP    /* ignored */
0569 
0570 #endif // RAPIDJSON_DIAG_*
0571 
0572 ///////////////////////////////////////////////////////////////////////////////
0573 // C++11 features
0574 
0575 #ifndef RAPIDJSON_HAS_CXX11
0576 #define RAPIDJSON_HAS_CXX11 (RAPIDJSON_CPLUSPLUS >= 201103L)
0577 #endif
0578 
0579 #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
0580 #if RAPIDJSON_HAS_CXX11
0581 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
0582 #elif defined(__clang__)
0583 #if __has_feature(cxx_rvalue_references) && \
0584     (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
0585 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
0586 #else
0587 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
0588 #endif
0589 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
0590       (defined(_MSC_VER) && _MSC_VER >= 1600) || \
0591       (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
0592 
0593 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
0594 #else
0595 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
0596 #endif
0597 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
0598 
0599 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
0600 #include <utility> // std::move
0601 #endif
0602 
0603 #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
0604 #if RAPIDJSON_HAS_CXX11
0605 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
0606 #elif defined(__clang__)
0607 #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
0608 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
0609     (defined(_MSC_VER) && _MSC_VER >= 1900) || \
0610     (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
0611 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
0612 #else
0613 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
0614 #endif
0615 #endif
0616 #ifndef RAPIDJSON_NOEXCEPT
0617 #if RAPIDJSON_HAS_CXX11_NOEXCEPT
0618 #define RAPIDJSON_NOEXCEPT noexcept
0619 #else
0620 #define RAPIDJSON_NOEXCEPT throw()
0621 #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
0622 #endif
0623 
0624 // no automatic detection, yet
0625 #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
0626 #if (defined(_MSC_VER) && _MSC_VER >= 1700)
0627 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 1
0628 #else
0629 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
0630 #endif
0631 #endif
0632 
0633 #ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
0634 #if defined(__clang__)
0635 #define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
0636 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
0637       (defined(_MSC_VER) && _MSC_VER >= 1700) || \
0638       (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
0639 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
0640 #else
0641 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
0642 #endif
0643 #endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
0644 
0645 ///////////////////////////////////////////////////////////////////////////////
0646 // C++17 features
0647 
0648 #ifndef RAPIDJSON_HAS_CXX17
0649 #define RAPIDJSON_HAS_CXX17 (RAPIDJSON_CPLUSPLUS >= 201703L)
0650 #endif
0651 
0652 #if RAPIDJSON_HAS_CXX17
0653 # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
0654 #elif defined(__has_cpp_attribute)
0655 # if __has_cpp_attribute(clang::fallthrough)
0656 #  define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
0657 # elif __has_cpp_attribute(fallthrough)
0658 #  define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
0659 # else
0660 #  define RAPIDJSON_DELIBERATE_FALLTHROUGH
0661 # endif
0662 #else
0663 # define RAPIDJSON_DELIBERATE_FALLTHROUGH
0664 #endif
0665 
0666 //!@endcond
0667 
0668 //! Assertion (in non-throwing contexts).
0669  /*! \ingroup RAPIDJSON_CONFIG
0670     Some functions provide a \c noexcept guarantee, if the compiler supports it.
0671     In these cases, the \ref RAPIDJSON_ASSERT macro cannot be overridden to
0672     throw an exception.  This macro adds a separate customization point for
0673     such cases.
0674 
0675     Defaults to C \c assert() (as \ref RAPIDJSON_ASSERT), if \c noexcept is
0676     supported, and to \ref RAPIDJSON_ASSERT otherwise.
0677  */
0678 
0679 ///////////////////////////////////////////////////////////////////////////////
0680 // RAPIDJSON_NOEXCEPT_ASSERT
0681 
0682 #ifndef RAPIDJSON_NOEXCEPT_ASSERT
0683 #ifdef RAPIDJSON_ASSERT_THROWS
0684 #include <cassert>
0685 #define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x)
0686 #else
0687 #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
0688 #endif // RAPIDJSON_ASSERT_THROWS
0689 #endif // RAPIDJSON_NOEXCEPT_ASSERT
0690 
0691 ///////////////////////////////////////////////////////////////////////////////
0692 // malloc/realloc/free
0693 
0694 #ifndef RAPIDJSON_MALLOC
0695 ///! customization point for global \c malloc
0696 #define RAPIDJSON_MALLOC(size) std::malloc(size)
0697 #endif
0698 #ifndef RAPIDJSON_REALLOC
0699 ///! customization point for global \c realloc
0700 #define RAPIDJSON_REALLOC(ptr, new_size) std::realloc(ptr, new_size)
0701 #endif
0702 #ifndef RAPIDJSON_FREE
0703 ///! customization point for global \c free
0704 #define RAPIDJSON_FREE(ptr) std::free(ptr)
0705 #endif
0706 
0707 ///////////////////////////////////////////////////////////////////////////////
0708 // new/delete
0709 
0710 #ifndef RAPIDJSON_NEW
0711 ///! customization point for global \c new
0712 #define RAPIDJSON_NEW(TypeName) new TypeName
0713 #endif
0714 #ifndef RAPIDJSON_DELETE
0715 ///! customization point for global \c delete
0716 #define RAPIDJSON_DELETE(x) delete x
0717 #endif
0718 
0719 ///////////////////////////////////////////////////////////////////////////////
0720 // Type
0721 
0722 /*! \namespace rapidjson
0723     \brief main RapidJSON namespace
0724     \see RAPIDJSON_NAMESPACE
0725 */
0726 RAPIDJSON_NAMESPACE_BEGIN
0727 
0728 //! Type of JSON value
0729 enum Type {
0730     kNullType = 0,      //!< null
0731     kFalseType = 1,     //!< false
0732     kTrueType = 2,      //!< true
0733     kObjectType = 3,    //!< object
0734     kArrayType = 4,     //!< array
0735     kStringType = 5,    //!< string
0736     kNumberType = 6     //!< number
0737 };
0738 
0739 RAPIDJSON_NAMESPACE_END
0740 
0741 #endif // RAPIDJSON_RAPIDJSON_H_