DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rapidjson.h Source File

rapidjson.h

Go to the documentation of this file.
00001 // Tencent is pleased to support the open source community by making RapidJSON available.
00002 // 
00003 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
00004 //
00005 // Licensed under the MIT License (the "License"); you may not use this file except
00006 // in compliance with the License. You may obtain a copy of the License at
00007 //
00008 // http://opensource.org/licenses/MIT
00009 //
00010 // Unless required by applicable law or agreed to in writing, software distributed 
00011 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
00012 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 
00013 // specific language governing permissions and limitations under the License.
00014 
00015 #ifndef RAPIDJSON_RAPIDJSON_H_
00016 #define RAPIDJSON_RAPIDJSON_H_
00017 
00018 /*!\file rapidjson.h
00019     \brief common definitions and configuration
00020     
00021     \see RAPIDJSON_CONFIG
00022  */
00023 
00024 /*! \defgroup RAPIDJSON_CONFIG RapidJSON configuration
00025     \brief Configuration macros for library features
00026 
00027     Some RapidJSON features are configurable to adapt the library to a wide
00028     variety of platforms, environments and usage scenarios.  Most of the
00029     features can be configured in terms of overriden or predefined
00030     preprocessor macros at compile-time.
00031 
00032     Some additional customization is available in the \ref RAPIDJSON_ERRORS APIs.
00033 
00034     \note These macros should be given on the compiler command-line
00035           (where applicable)  to avoid inconsistent values when compiling
00036           different translation units of a single application.
00037  */
00038 
00039 #include <cstdlib>  // malloc(), realloc(), free(), size_t
00040 #include <cstring>  // memset(), memcpy(), memmove(), memcmp()
00041 
00042 ///////////////////////////////////////////////////////////////////////////////
00043 // RAPIDJSON_VERSION_STRING
00044 //
00045 // ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt.
00046 //
00047 
00048 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
00049 // token stringification
00050 #define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
00051 #define RAPIDJSON_DO_STRINGIFY(x) #x
00052 //!@endcond
00053 
00054 /*! \def RAPIDJSON_MAJOR_VERSION
00055     \ingroup RAPIDJSON_CONFIG
00056     \brief Major version of RapidJSON in integer.
00057 */
00058 /*! \def RAPIDJSON_MINOR_VERSION
00059     \ingroup RAPIDJSON_CONFIG
00060     \brief Minor version of RapidJSON in integer.
00061 */
00062 /*! \def RAPIDJSON_PATCH_VERSION
00063     \ingroup RAPIDJSON_CONFIG
00064     \brief Patch version of RapidJSON in integer.
00065 */
00066 /*! \def RAPIDJSON_VERSION_STRING
00067     \ingroup RAPIDJSON_CONFIG
00068     \brief Version of RapidJSON in "<major>.<minor>.<patch>" string format.
00069 */
00070 #define RAPIDJSON_MAJOR_VERSION 1
00071 #define RAPIDJSON_MINOR_VERSION 1
00072 #define RAPIDJSON_PATCH_VERSION 0
00073 #define RAPIDJSON_VERSION_STRING \
00074     RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
00075 
00076 ///////////////////////////////////////////////////////////////////////////////
00077 // RAPIDJSON_NAMESPACE_(BEGIN|END)
00078 /*! \def RAPIDJSON_NAMESPACE
00079     \ingroup RAPIDJSON_CONFIG
00080     \brief   provide custom rapidjson namespace
00081 
00082     In order to avoid symbol clashes and/or "One Definition Rule" errors
00083     between multiple inclusions of (different versions of) RapidJSON in
00084     a single binary, users can customize the name of the main RapidJSON
00085     namespace.
00086 
00087     In case of a single nesting level, defining \c RAPIDJSON_NAMESPACE
00088     to a custom name (e.g. \c MyRapidJSON) is sufficient.  If multiple
00089     levels are needed, both \ref RAPIDJSON_NAMESPACE_BEGIN and \ref
00090     RAPIDJSON_NAMESPACE_END need to be defined as well:
00091 
00092     \code
00093     // in some .cpp file
00094     #define RAPIDJSON_NAMESPACE my::rapidjson
00095     #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson {
00096     #define RAPIDJSON_NAMESPACE_END   } }
00097     #include "rapidjson/..."
00098     \endcode
00099 
00100     \see rapidjson
00101  */
00102 /*! \def RAPIDJSON_NAMESPACE_BEGIN
00103     \ingroup RAPIDJSON_CONFIG
00104     \brief   provide custom rapidjson namespace (opening expression)
00105     \see RAPIDJSON_NAMESPACE
00106 */
00107 /*! \def RAPIDJSON_NAMESPACE_END
00108     \ingroup RAPIDJSON_CONFIG
00109     \brief   provide custom rapidjson namespace (closing expression)
00110     \see RAPIDJSON_NAMESPACE
00111 */
00112 #ifndef RAPIDJSON_NAMESPACE
00113 #define RAPIDJSON_NAMESPACE rapidjson
00114 #endif
00115 #ifndef RAPIDJSON_NAMESPACE_BEGIN
00116 #define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
00117 #endif
00118 #ifndef RAPIDJSON_NAMESPACE_END
00119 #define RAPIDJSON_NAMESPACE_END }
00120 #endif
00121 
00122 ///////////////////////////////////////////////////////////////////////////////
00123 // RAPIDJSON_HAS_STDSTRING
00124 
00125 #ifndef RAPIDJSON_HAS_STDSTRING
00126 #ifdef RAPIDJSON_DOXYGEN_RUNNING
00127 #define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
00128 #else
00129 #define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
00130 #endif
00131 /*! \def RAPIDJSON_HAS_STDSTRING
00132     \ingroup RAPIDJSON_CONFIG
00133     \brief Enable RapidJSON support for \c std::string
00134 
00135     By defining this preprocessor symbol to \c 1, several convenience functions for using
00136     \ref rapidjson::GenericValue with \c std::string are enabled, especially
00137     for construction and comparison.
00138 
00139     \hideinitializer
00140 */
00141 #endif // !defined(RAPIDJSON_HAS_STDSTRING)
00142 
00143 #if RAPIDJSON_HAS_STDSTRING
00144 #include <string>
00145 #endif // RAPIDJSON_HAS_STDSTRING
00146 
00147 ///////////////////////////////////////////////////////////////////////////////
00148 // RAPIDJSON_NO_INT64DEFINE
00149 
00150 /*! \def RAPIDJSON_NO_INT64DEFINE
00151     \ingroup RAPIDJSON_CONFIG
00152     \brief Use external 64-bit integer types.
00153 
00154     RapidJSON requires the 64-bit integer types \c int64_t and  \c uint64_t types
00155     to be available at global scope.
00156 
00157     If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to
00158     prevent RapidJSON from defining its own types.
00159 */
00160 #ifndef RAPIDJSON_NO_INT64DEFINE
00161 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
00162 #if defined(_MSC_VER) && (_MSC_VER < 1800)  // Visual Studio 2013
00163 #include "msinttypes/stdint.h"
00164 #include "msinttypes/inttypes.h"
00165 #else
00166 // Other compilers should have this.
00167 #include <stdint.h>
00168 #include <inttypes.h>
00169 #endif
00170 //!@endcond
00171 #ifdef RAPIDJSON_DOXYGEN_RUNNING
00172 #define RAPIDJSON_NO_INT64DEFINE
00173 #endif
00174 #endif // RAPIDJSON_NO_INT64TYPEDEF
00175 
00176 ///////////////////////////////////////////////////////////////////////////////
00177 // RAPIDJSON_FORCEINLINE
00178 
00179 #ifndef RAPIDJSON_FORCEINLINE
00180 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
00181 #if defined(_MSC_VER) && defined(NDEBUG)
00182 #define RAPIDJSON_FORCEINLINE __forceinline
00183 #elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
00184 #define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
00185 #else
00186 #define RAPIDJSON_FORCEINLINE
00187 #endif
00188 //!@endcond
00189 #endif // RAPIDJSON_FORCEINLINE
00190 
00191 ///////////////////////////////////////////////////////////////////////////////
00192 // RAPIDJSON_ENDIAN
00193 #define RAPIDJSON_LITTLEENDIAN  0   //!< Little endian machine
00194 #define RAPIDJSON_BIGENDIAN     1   //!< Big endian machine
00195 
00196 //! Endianness of the machine.
00197 /*!
00198     \def RAPIDJSON_ENDIAN
00199     \ingroup RAPIDJSON_CONFIG
00200 
00201     GCC 4.6 provided macro for detecting endianness of the target machine. But other
00202     compilers may not have this. User can define RAPIDJSON_ENDIAN to either
00203     \ref RAPIDJSON_LITTLEENDIAN or \ref RAPIDJSON_BIGENDIAN.
00204 
00205     Default detection implemented with reference to
00206     \li https://gcc.gnu.org/onlinedocs/gcc-4.6.0/cpp/Common-Predefined-Macros.html
00207     \li http://www.boost.org/doc/libs/1_42_0/boost/detail/endian.hpp
00208 */
00209 #ifndef RAPIDJSON_ENDIAN
00210 // Detect with GCC 4.6's macro
00211 #  ifdef __BYTE_ORDER__
00212 #    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
00213 #      define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
00214 #    elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
00215 #      define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
00216 #    else
00217 #      error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
00218 #    endif // __BYTE_ORDER__
00219 // Detect with GLIBC's endian.h
00220 #  elif defined(__GLIBC__)
00221 #    include <endian.h>
00222 #    if (__BYTE_ORDER == __LITTLE_ENDIAN)
00223 #      define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
00224 #    elif (__BYTE_ORDER == __BIG_ENDIAN)
00225 #      define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
00226 #    else
00227 #      error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
00228 #   endif // __GLIBC__
00229 // Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
00230 #  elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
00231 #    define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
00232 #  elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
00233 #    define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
00234 // Detect with architecture macros
00235 #  elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
00236 #    define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
00237 #  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__)
00238 #    define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
00239 #  elif defined(_MSC_VER) && defined(_M_ARM)
00240 #    define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
00241 #  elif defined(RAPIDJSON_DOXYGEN_RUNNING)
00242 #    define RAPIDJSON_ENDIAN
00243 #  else
00244 #    error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.   
00245 #  endif
00246 #endif // RAPIDJSON_ENDIAN
00247 
00248 ///////////////////////////////////////////////////////////////////////////////
00249 // RAPIDJSON_64BIT
00250 
00251 //! Whether using 64-bit architecture
00252 #ifndef RAPIDJSON_64BIT
00253 #if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
00254 #define RAPIDJSON_64BIT 1
00255 #else
00256 #define RAPIDJSON_64BIT 0
00257 #endif
00258 #endif // RAPIDJSON_64BIT
00259 
00260 ///////////////////////////////////////////////////////////////////////////////
00261 // RAPIDJSON_ALIGN
00262 
00263 //! Data alignment of the machine.
00264 /*! \ingroup RAPIDJSON_CONFIG
00265     \param x pointer to align
00266 
00267     Some machines require strict data alignment. Currently the default uses 4 bytes
00268     alignment on 32-bit platforms and 8 bytes alignment for 64-bit platforms.
00269     User can customize by defining the RAPIDJSON_ALIGN function macro.
00270 */
00271 #ifndef RAPIDJSON_ALIGN
00272 #if RAPIDJSON_64BIT == 1
00273 #define RAPIDJSON_ALIGN(x) (((x) + static_cast<uint64_t>(7u)) & ~static_cast<uint64_t>(7u))
00274 #else
00275 #define RAPIDJSON_ALIGN(x) (((x) + 3u) & ~3u)
00276 #endif
00277 #endif
00278 
00279 ///////////////////////////////////////////////////////////////////////////////
00280 // RAPIDJSON_UINT64_C2
00281 
00282 //! Construct a 64-bit literal by a pair of 32-bit integer.
00283 /*!
00284     64-bit literal with or without ULL suffix is prone to compiler warnings.
00285     UINT64_C() is C macro which cause compilation problems.
00286     Use this macro to define 64-bit constants by a pair of 32-bit integer.
00287 */
00288 #ifndef RAPIDJSON_UINT64_C2
00289 #define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
00290 #endif
00291 
00292 ///////////////////////////////////////////////////////////////////////////////
00293 // RAPIDJSON_48BITPOINTER_OPTIMIZATION
00294 
00295 //! Use only lower 48-bit address for some pointers.
00296 /*!
00297     \ingroup RAPIDJSON_CONFIG
00298 
00299     This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address.
00300     The higher 16-bit can be used for storing other data.
00301     \c GenericValue uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture.
00302 */
00303 #ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
00304 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
00305 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
00306 #else
00307 #define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
00308 #endif
00309 #endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
00310 
00311 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
00312 #if RAPIDJSON_64BIT != 1
00313 #error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
00314 #endif
00315 #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))))
00316 #define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
00317 #else
00318 #define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
00319 #define RAPIDJSON_GETPOINTER(type, p) (p)
00320 #endif
00321 
00322 ///////////////////////////////////////////////////////////////////////////////
00323 // RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_SIMD
00324 
00325 /*! \def RAPIDJSON_SIMD
00326     \ingroup RAPIDJSON_CONFIG
00327     \brief Enable SSE2/SSE4.2 optimization.
00328 
00329     RapidJSON supports optimized implementations for some parsing operations
00330     based on the SSE2 or SSE4.2 SIMD extensions on modern Intel-compatible
00331     processors.
00332 
00333     To enable these optimizations, two different symbols can be defined;
00334     \code
00335     // Enable SSE2 optimization.
00336     #define RAPIDJSON_SSE2
00337 
00338     // Enable SSE4.2 optimization.
00339     #define RAPIDJSON_SSE42
00340     \endcode
00341 
00342     \c RAPIDJSON_SSE42 takes precedence, if both are defined.
00343 
00344     If any of these symbols is defined, RapidJSON defines the macro
00345     \c RAPIDJSON_SIMD to indicate the availability of the optimized code.
00346 */
00347 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
00348     || defined(RAPIDJSON_DOXYGEN_RUNNING)
00349 #define RAPIDJSON_SIMD
00350 #endif
00351 
00352 ///////////////////////////////////////////////////////////////////////////////
00353 // RAPIDJSON_NO_SIZETYPEDEFINE
00354 
00355 #ifndef RAPIDJSON_NO_SIZETYPEDEFINE
00356 /*! \def RAPIDJSON_NO_SIZETYPEDEFINE
00357     \ingroup RAPIDJSON_CONFIG
00358     \brief User-provided \c SizeType definition.
00359 
00360     In order to avoid using 32-bit size types for indexing strings and arrays,
00361     define this preprocessor symbol and provide the type rapidjson::SizeType
00362     before including RapidJSON:
00363     \code
00364     #define RAPIDJSON_NO_SIZETYPEDEFINE
00365     namespace rapidjson { typedef ::std::size_t SizeType; }
00366     #include "rapidjson/..."
00367     \endcode
00368 
00369     \see rapidjson::SizeType
00370 */
00371 #ifdef RAPIDJSON_DOXYGEN_RUNNING
00372 #define RAPIDJSON_NO_SIZETYPEDEFINE
00373 #endif
00374 RAPIDJSON_NAMESPACE_BEGIN
00375 //! Size type (for string lengths, array sizes, etc.)
00376 /*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms,
00377     instead of using \c size_t. Users may override the SizeType by defining
00378     \ref RAPIDJSON_NO_SIZETYPEDEFINE.
00379 */
00380 typedef unsigned SizeType;
00381 RAPIDJSON_NAMESPACE_END
00382 #endif
00383 
00384 // always import std::size_t to rapidjson namespace
00385 RAPIDJSON_NAMESPACE_BEGIN
00386 using std::size_t;
00387 RAPIDJSON_NAMESPACE_END
00388 
00389 ///////////////////////////////////////////////////////////////////////////////
00390 // RAPIDJSON_ASSERT
00391 
00392 //! Assertion.
00393 /*! \ingroup RAPIDJSON_CONFIG
00394     By default, rapidjson uses C \c assert() for internal assertions.
00395     User can override it by defining RAPIDJSON_ASSERT(x) macro.
00396 
00397     \note Parsing errors are handled and can be customized by the
00398           \ref RAPIDJSON_ERRORS APIs.
00399 */
00400 #ifndef RAPIDJSON_ASSERT
00401 #include <cassert>
00402 #define RAPIDJSON_ASSERT(x) assert(x)
00403 #endif // RAPIDJSON_ASSERT
00404 
00405 ///////////////////////////////////////////////////////////////////////////////
00406 // RAPIDJSON_STATIC_ASSERT
00407 
00408 // Adopt from boost
00409 #ifndef RAPIDJSON_STATIC_ASSERT
00410 #ifndef __clang__
00411 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
00412 #endif
00413 RAPIDJSON_NAMESPACE_BEGIN
00414 template <bool x> struct STATIC_ASSERTION_FAILURE;
00415 template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
00416 template<int x> struct StaticAssertTest {};
00417 RAPIDJSON_NAMESPACE_END
00418 
00419 #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
00420 #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
00421 #define RAPIDJSON_DO_JOIN2(X, Y) X##Y
00422 
00423 #if defined(__GNUC__)
00424 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
00425 #else
00426 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE 
00427 #endif
00428 #ifndef __clang__
00429 //!@endcond
00430 #endif
00431 
00432 /*! \def RAPIDJSON_STATIC_ASSERT
00433     \brief (Internal) macro to check for conditions at compile-time
00434     \param x compile-time condition
00435     \hideinitializer
00436  */
00437 #define RAPIDJSON_STATIC_ASSERT(x) \
00438     typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
00439       sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
00440     RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
00441 #endif
00442 
00443 ///////////////////////////////////////////////////////////////////////////////
00444 // RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY
00445 
00446 //! Compiler branching hint for expression with high probability to be true.
00447 /*!
00448     \ingroup RAPIDJSON_CONFIG
00449     \param x Boolean expression likely to be true.
00450 */
00451 #ifndef RAPIDJSON_LIKELY
00452 #if defined(__GNUC__) || defined(__clang__)
00453 #define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
00454 #else
00455 #define RAPIDJSON_LIKELY(x) (x)
00456 #endif
00457 #endif
00458 
00459 //! Compiler branching hint for expression with low probability to be true.
00460 /*!
00461     \ingroup RAPIDJSON_CONFIG
00462     \param x Boolean expression unlikely to be true.
00463 */
00464 #ifndef RAPIDJSON_UNLIKELY
00465 #if defined(__GNUC__) || defined(__clang__)
00466 #define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
00467 #else
00468 #define RAPIDJSON_UNLIKELY(x) (x)
00469 #endif
00470 #endif
00471 
00472 ///////////////////////////////////////////////////////////////////////////////
00473 // Helpers
00474 
00475 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
00476 
00477 #define RAPIDJSON_MULTILINEMACRO_BEGIN do {  
00478 #define RAPIDJSON_MULTILINEMACRO_END \
00479 } while((void)0, 0)
00480 
00481 // adopted from Boost
00482 #define RAPIDJSON_VERSION_CODE(x,y,z) \
00483   (((x)*100000) + ((y)*100) + (z))
00484 
00485 ///////////////////////////////////////////////////////////////////////////////
00486 // RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
00487 
00488 #if defined(__GNUC__)
00489 #define RAPIDJSON_GNUC \
00490     RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
00491 #endif
00492 
00493 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
00494 
00495 #define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
00496 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
00497 #define RAPIDJSON_DIAG_OFF(x) \
00498     RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
00499 
00500 // push/pop support in Clang and GCC>=4.6
00501 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
00502 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
00503 #define RAPIDJSON_DIAG_POP  RAPIDJSON_DIAG_PRAGMA(pop)
00504 #else // GCC >= 4.2, < 4.6
00505 #define RAPIDJSON_DIAG_PUSH /* ignored */
00506 #define RAPIDJSON_DIAG_POP /* ignored */
00507 #endif
00508 
00509 #elif defined(_MSC_VER)
00510 
00511 // pragma (MSVC specific)
00512 #define RAPIDJSON_PRAGMA(x) __pragma(x)
00513 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
00514 
00515 #define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
00516 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
00517 #define RAPIDJSON_DIAG_POP  RAPIDJSON_DIAG_PRAGMA(pop)
00518 
00519 #else
00520 
00521 #define RAPIDJSON_DIAG_OFF(x) /* ignored */
00522 #define RAPIDJSON_DIAG_PUSH   /* ignored */
00523 #define RAPIDJSON_DIAG_POP    /* ignored */
00524 
00525 #endif // RAPIDJSON_DIAG_*
00526 
00527 ///////////////////////////////////////////////////////////////////////////////
00528 // C++11 features
00529 
00530 #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
00531 #if defined(__clang__)
00532 #if __has_feature(cxx_rvalue_references) && \
00533     (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
00534 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
00535 #else
00536 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
00537 #endif
00538 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
00539       (defined(_MSC_VER) && _MSC_VER >= 1600)
00540 
00541 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
00542 #else
00543 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
00544 #endif
00545 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
00546 
00547 #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
00548 #if defined(__clang__)
00549 #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
00550 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
00551 //    (defined(_MSC_VER) && _MSC_VER >= ????) // not yet supported
00552 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
00553 #else
00554 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
00555 #endif
00556 #endif
00557 #if RAPIDJSON_HAS_CXX11_NOEXCEPT
00558 #define RAPIDJSON_NOEXCEPT noexcept
00559 #else
00560 #define RAPIDJSON_NOEXCEPT /* noexcept */
00561 #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
00562 
00563 // no automatic detection, yet
00564 #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
00565 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
00566 #endif
00567 
00568 #ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
00569 #if defined(__clang__)
00570 #define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
00571 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
00572       (defined(_MSC_VER) && _MSC_VER >= 1700)
00573 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
00574 #else
00575 #define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
00576 #endif
00577 #endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
00578 
00579 //!@endcond
00580 
00581 ///////////////////////////////////////////////////////////////////////////////
00582 // new/delete
00583 
00584 #ifndef RAPIDJSON_NEW
00585 ///! customization point for global \c new
00586 #define RAPIDJSON_NEW(x) new x
00587 #endif
00588 #ifndef RAPIDJSON_DELETE
00589 ///! customization point for global \c delete
00590 #define RAPIDJSON_DELETE(x) delete x
00591 #endif
00592 
00593 ///////////////////////////////////////////////////////////////////////////////
00594 // Type
00595 
00596 /*! \namespace rapidjson
00597     \brief main RapidJSON namespace
00598     \see RAPIDJSON_NAMESPACE
00599 */
00600 RAPIDJSON_NAMESPACE_BEGIN
00601 
00602 //! Type of JSON value
00603 enum Type {
00604     kNullType = 0,      //!< null
00605     kFalseType = 1,     //!< false
00606     kTrueType = 2,      //!< true
00607     kObjectType = 3,    //!< object
00608     kArrayType = 4,     //!< array 
00609     kStringType = 5,    //!< string
00610     kNumberType = 6     //!< number
00611 };
00612 
00613 RAPIDJSON_NAMESPACE_END
00614 
00615 #endif // RAPIDJSON_RAPIDJSON_H_