Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
rapidjson.h
Aller à la documentation de ce fichier.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2// Tencent is pleased to support the open source community by making RapidJSON available.
3//
4// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
5//
6// Licensed under the MIT License (the "License"); you may not use this file except
7// in compliance with the License. You may obtain a copy of the License at
8//
9// http://opensource.org/licenses/MIT
10//
11// Unless required by applicable law or agreed to in writing, software distributed
12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14// specific language governing permissions and limitations under the License.
15
16#ifndef RAPIDJSON_RAPIDJSON_H_
17#define RAPIDJSON_RAPIDJSON_H_
18
40#include <cstdlib> // malloc(), realloc(), free(), size_t
41#include <cstring> // memset(), memcpy(), memmove(), memcmp()
42
44// RAPIDJSON_VERSION_STRING
45//
46// ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt.
47//
48
50// token stringification
51#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
52#define RAPIDJSON_DO_STRINGIFY(x) #x
53
54// token concatenation
55#define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
56#define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
57#define RAPIDJSON_DO_JOIN2(X, Y) X##Y
59
76#define RAPIDJSON_MAJOR_VERSION 1
77#define RAPIDJSON_MINOR_VERSION 1
78#define RAPIDJSON_PATCH_VERSION 0
79#define RAPIDJSON_VERSION_STRING \
80 RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)
81
83// RAPIDJSON_NAMESPACE_(BEGIN|END)
118#ifndef RAPIDJSON_NAMESPACE
119#define RAPIDJSON_NAMESPACE rapidjson
120#endif
121#ifndef RAPIDJSON_NAMESPACE_BEGIN
122#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
123#endif
124#ifndef RAPIDJSON_NAMESPACE_END
125#define RAPIDJSON_NAMESPACE_END }
126#endif
127
129// RAPIDJSON_HAS_STDSTRING
130
131#ifndef RAPIDJSON_HAS_STDSTRING
132#ifdef RAPIDJSON_DOXYGEN_RUNNING
133#define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
134#else
135#define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
136#endif
147#endif // !defined(RAPIDJSON_HAS_STDSTRING)
148
149#if RAPIDJSON_HAS_STDSTRING
150#include <string>
151#endif // RAPIDJSON_HAS_STDSTRING
152
154// RAPIDJSON_NO_INT64DEFINE
155
166#ifndef RAPIDJSON_NO_INT64DEFINE
168#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013
169#include "msinttypes/stdint.h"
170#include "msinttypes/inttypes.h"
171#else
172// Other compilers should have this.
173#include <stdint.h>
174#include <inttypes.h>
175#endif
177#ifdef RAPIDJSON_DOXYGEN_RUNNING
178#define RAPIDJSON_NO_INT64DEFINE
179#endif
180#endif // RAPIDJSON_NO_INT64TYPEDEF
181
183// RAPIDJSON_FORCEINLINE
184
185#ifndef RAPIDJSON_FORCEINLINE
187#if defined(_MSC_VER) && defined(NDEBUG)
188#define RAPIDJSON_FORCEINLINE __forceinline
189#elif defined(__GNUC__) && __GNUC__ >= 4 && defined(NDEBUG)
190#define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
191#else
192#define RAPIDJSON_FORCEINLINE
193#endif
195#endif // RAPIDJSON_FORCEINLINE
196
198// RAPIDJSON_ENDIAN
199#define RAPIDJSON_LITTLEENDIAN 0
200#define RAPIDJSON_BIGENDIAN 1
201
203
215#ifndef RAPIDJSON_ENDIAN
216// Detect with GCC 4.6's macro
217# ifdef __BYTE_ORDER__
218# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
219# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
220# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
221# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
222# else
223# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
224# endif // __BYTE_ORDER__
225// Detect with GLIBC's endian.h
226# elif defined(__GLIBC__)
227# include <endian.h>
228# if (__BYTE_ORDER == __LITTLE_ENDIAN)
229# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
230# elif (__BYTE_ORDER == __BIG_ENDIAN)
231# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
232# else
233# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
234# endif // __GLIBC__
235// Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
236# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
237# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
238# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
239# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
240// Detect with architecture macros
241# elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
242# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
243# elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__bfin__)
244# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
245# elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
246# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
247# elif defined(RAPIDJSON_DOXYGEN_RUNNING)
248# define RAPIDJSON_ENDIAN
249# else
250# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
251# endif
252#endif // RAPIDJSON_ENDIAN
253
255// RAPIDJSON_64BIT
256
258#ifndef RAPIDJSON_64BIT
259#if defined(__LP64__) || (defined(__x86_64__) && defined(__ILP32__)) || defined(_WIN64) || defined(__EMSCRIPTEN__)
260#define RAPIDJSON_64BIT 1
261#else
262#define RAPIDJSON_64BIT 0
263#endif
264#endif // RAPIDJSON_64BIT
265
267// RAPIDJSON_ALIGN
268
270
276#ifndef RAPIDJSON_ALIGN
277#define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
278#endif
279
281// RAPIDJSON_UINT64_C2
282
284
289#ifndef RAPIDJSON_UINT64_C2
290#define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
291#endif
292
294// RAPIDJSON_48BITPOINTER_OPTIMIZATION
295
297
304#ifndef RAPIDJSON_48BITPOINTER_OPTIMIZATION
305#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
306#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 1
307#else
308#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0
309#endif
310#endif // RAPIDJSON_48BITPOINTER_OPTIMIZATION
311
312#if RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1
313#if RAPIDJSON_64BIT != 1
314#error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
315#endif
316#define RAPIDJSON_SETPOINTER(type, p, x) (p = reinterpret_cast<type *>((reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | reinterpret_cast<uintptr_t>(reinterpret_cast<const void*>(x))))
317#define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
318#else
319#define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
320#define RAPIDJSON_GETPOINTER(type, p) (p)
321#endif
322
324// RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_NEON/RAPIDJSON_SIMD
325
352#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
353 || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
354#define RAPIDJSON_SIMD
355#endif
356
358// RAPIDJSON_NO_SIZETYPEDEFINE
359
360#ifndef RAPIDJSON_NO_SIZETYPEDEFINE
376#ifdef RAPIDJSON_DOXYGEN_RUNNING
377#define RAPIDJSON_NO_SIZETYPEDEFINE
378#endif
381
385typedef unsigned SizeType;
387#endif
388
389// always import std::size_t to rapidjson namespace
391using std::size_t;
393
395// RAPIDJSON_ASSERT
396
398
405#ifndef RAPIDJSON_ASSERT
406#include <cassert>
407#define RAPIDJSON_ASSERT(x) assert(x)
408#endif // RAPIDJSON_ASSERT
409
411// RAPIDJSON_STATIC_ASSERT
412
413// Prefer C++11 static_assert, if available
414#ifndef RAPIDJSON_STATIC_ASSERT
415#if __cplusplus >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
416#define RAPIDJSON_STATIC_ASSERT(x) \
417 static_assert(x, RAPIDJSON_STRINGIFY(x))
418#endif // C++11
419#endif // RAPIDJSON_STATIC_ASSERT
420
421// Adopt C++03 implementation from boost
422#ifndef RAPIDJSON_STATIC_ASSERT
423#ifndef __clang__
425#endif
427template <bool x> struct STATIC_ASSERTION_FAILURE;
428template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
429template <size_t x> struct StaticAssertTest {};
431
432#if defined(__GNUC__) || defined(__clang__)
433#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
434#else
435#define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
436#endif
437#ifndef __clang__
439#endif
440
446#define RAPIDJSON_STATIC_ASSERT(x) \
447 typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
448 sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
449 RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
450#endif // RAPIDJSON_STATIC_ASSERT
451
453// RAPIDJSON_LIKELY, RAPIDJSON_UNLIKELY
454
456
460#ifndef RAPIDJSON_LIKELY
461#if defined(__GNUC__) || defined(__clang__)
462#define RAPIDJSON_LIKELY(x) __builtin_expect(!!(x), 1)
463#else
464#define RAPIDJSON_LIKELY(x) (x)
465#endif
466#endif
467
469
473#ifndef RAPIDJSON_UNLIKELY
474#if defined(__GNUC__) || defined(__clang__)
475#define RAPIDJSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
476#else
477#define RAPIDJSON_UNLIKELY(x) (x)
478#endif
479#endif
480
482// Helpers
483
485
486#define RAPIDJSON_MULTILINEMACRO_BEGIN do {
487#define RAPIDJSON_MULTILINEMACRO_END \
488} while((void)0, 0)
489
490// adopted from Boost
491#define RAPIDJSON_VERSION_CODE(x,y,z) \
492 (((x)*100000) + ((y)*100) + (z))
493
494#if defined(__has_builtin)
495#define RAPIDJSON_HAS_BUILTIN(x) __has_builtin(x)
496#else
497#define RAPIDJSON_HAS_BUILTIN(x) 0
498#endif
499
501// RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
502
503#if defined(__GNUC__)
504#define RAPIDJSON_GNUC \
505 RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
506#endif
507
508#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
509
510#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
511#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
512#define RAPIDJSON_DIAG_OFF(x) \
513 RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
514
515// push/pop support in Clang and GCC>=4.6
516#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
517#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
518#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
519#else // GCC >= 4.2, < 4.6
520#define RAPIDJSON_DIAG_PUSH /* ignored */
521#define RAPIDJSON_DIAG_POP /* ignored */
522#endif
523
524#elif defined(_MSC_VER)
525
526// pragma (MSVC specific)
527#define RAPIDJSON_PRAGMA(x) __pragma(x)
528#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
529
530#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
531#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
532#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
533
534#else
535
536#define RAPIDJSON_DIAG_OFF(x) /* ignored */
537#define RAPIDJSON_DIAG_PUSH /* ignored */
538#define RAPIDJSON_DIAG_POP /* ignored */
539
540#endif // RAPIDJSON_DIAG_*
541
543// C++11 features
544
545#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
546#if defined(__clang__)
547#if __has_feature(cxx_rvalue_references) && \
548 (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
549#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
550#else
551#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
552#endif
553#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
554 (defined(_MSC_VER) && _MSC_VER >= 1600) || \
555 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
556
557#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
558#else
559#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
560#endif
561#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
562
563#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
564#if defined(__clang__)
565#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
566#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
567 (defined(_MSC_VER) && _MSC_VER >= 1900) || \
568 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
569#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
570#else
571#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
572#endif
573#endif
574#if RAPIDJSON_HAS_CXX11_NOEXCEPT
575#define RAPIDJSON_NOEXCEPT noexcept
576#else
577#define RAPIDJSON_NOEXCEPT /* noexcept */
578#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
579
580// no automatic detection, yet
581#ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
582#if (defined(_MSC_VER) && _MSC_VER >= 1700)
583#define RAPIDJSON_HAS_CXX11_TYPETRAITS 1
584#else
585#define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
586#endif
587#endif
588
589#ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
590#if defined(__clang__)
591#define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
592#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
593 (defined(_MSC_VER) && _MSC_VER >= 1700) || \
594 (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
595#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
596#else
597#define RAPIDJSON_HAS_CXX11_RANGE_FOR 0
598#endif
599#endif // RAPIDJSON_HAS_CXX11_RANGE_FOR
600
602// C++17 features
603
604#if defined(__has_cpp_attribute)
605# if __has_cpp_attribute(fallthrough)
606# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
607# else
608# define RAPIDJSON_DELIBERATE_FALLTHROUGH
609# endif
610#else
611# define RAPIDJSON_DELIBERATE_FALLTHROUGH
612#endif
613
615
617
628// RAPIDJSON_NOEXCEPT_ASSERT
629
630#ifndef RAPIDJSON_NOEXCEPT_ASSERT
631#ifdef RAPIDJSON_ASSERT_THROWS
632#if RAPIDJSON_HAS_CXX11_NOEXCEPT
633#define RAPIDJSON_NOEXCEPT_ASSERT(x)
634#else
635#include <cassert>
636#define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x)
637#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
638#else
639#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
640#endif // RAPIDJSON_ASSERT_THROWS
641#endif // RAPIDJSON_NOEXCEPT_ASSERT
642
644// new/delete
645
646#ifndef RAPIDJSON_NEW
648#define RAPIDJSON_NEW(TypeName) new TypeName
649#endif
650#ifndef RAPIDJSON_DELETE
652#define RAPIDJSON_DELETE(x) delete x
653#endif
654
656// Type
657
663
674
676
677#endif // RAPIDJSON_RAPIDJSON_H_
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition rapidjson.h:122
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition rapidjson.h:125
Type
Type of JSON value.
Definition rapidjson.h:665
@ kFalseType
false
Definition rapidjson.h:667
@ kObjectType
object
Definition rapidjson.h:669
@ kTrueType
true
Definition rapidjson.h:668
@ kStringType
string
Definition rapidjson.h:671
@ kNullType
null
Definition rapidjson.h:666
@ kArrayType
array
Definition rapidjson.h:670
@ kNumberType
number
Definition rapidjson.h:672
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition rapidjson.h:385