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

Dependencies:   MaximInterface

The MAXREFDES155# is an internet-of-things (IoT) embedded-security reference design, built to authenticate and control a sensing node using elliptic-curve-based public-key cryptography with control and notification from a web server.

The hardware includes an ARM® mbed™ shield and attached sensor endpoint. The shield contains a DS2476 DeepCover® ECDSA/SHA-2 coprocessor, Wifi communication, LCD push-button controls, and status LEDs. The sensor endpoint is attached to the shield using a 300mm cable and contains a DS28C36 DeepCover ECDSA/SHA-2 authenticator, IR-thermal sensor, and aiming laser for the IR sensor. The MAXREFDES155# is equipped with a standard Arduino® form-factor shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The combination of these two devices represent an IoT device. Communication to the web server is accomplished with the shield Wifi circuitry. Communication from the shield to the attached sensor module is accomplished over I2C . The sensor module represents an IoT endpoint that generates small data with a requirement for message authenticity/integrity and secure on/off operational control.

The design is hierarchical with each mbed platform and shield communicating data from the sensor node to a web server that maintains a centralized log and dispatches notifications as necessary. The simplicity of this design enables rapid integration into any star-topology IoT network to provide security with the low overhead and cost provided by the ECDSA-P256 asymmetric-key and SHA-256 symmetric-key algorithms.

More information about the MAXREFDES155# is available on the Maxim Integrated website.

Committer:
IanBenzMaxim
Date:
Tue Dec 03 12:56:25 2019 -0600
Revision:
18:c2631e985780
Parent:
16:a004191a79ab
Updated MaximInterface to version 2.1.

Who changed what in which revision?

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