21 #ifndef RAPIDJSON_RAPIDJSON_H_
22 #define RAPIDJSON_RAPIDJSON_H_
41 #ifndef RAPIDJSON_NO_INT64DEFINE
44 #include "msinttypes/stdint.h"
45 #include "msinttypes/inttypes.h"
52 #endif // RAPIDJSON_NO_INT64TYPEDEF
57 #ifndef RAPIDJSON_FORCEINLINE
59 #define RAPIDJSON_FORCEINLINE __forceinline
60 #elif defined(__GNUC__) && __GNUC__ >= 4
61 #define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
63 #define RAPIDJSON_FORCEINLINE
65 #endif // RAPIDJSON_FORCEINLINE
69 #define RAPIDJSON_LITTLEENDIAN 0
70 #define RAPIDJSON_BIGENDIAN 1
81 #ifndef RAPIDJSON_ENDIAN
83 # ifdef __BYTE_ORDER__
84 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
85 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
86 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
87 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
89 # error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
90 # endif // __BYTE_ORDER__
92 # elif defined(__GLIBC__)
94 # if (__BYTE_ORDER == __LITTLE_ENDIAN)
95 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
96 # elif (__BYTE_ORDER == __BIG_ENDIAN)
97 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
99 # error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
102 # elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
103 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
104 # elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
105 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
107 # elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
108 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
109 # 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__)
110 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
112 # error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
114 #endif // RAPIDJSON_ENDIAN
124 #ifndef RAPIDJSON_ALIGN
125 #define RAPIDJSON_ALIGN(x) ((x + 3u) & ~3u)
137 #ifndef RAPIDJSON_UINT64_C2
138 #define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
150 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42)
151 #define RAPIDJSON_SIMD
157 #ifndef RAPIDJSON_NO_SIZETYPEDEFINE
158 namespace rapidjson {
173 #ifndef RAPIDJSON_ASSERT
175 #define RAPIDJSON_ASSERT(x) assert(x)
176 #endif // RAPIDJSON_ASSERT
182 #ifndef RAPIDJSON_STATIC_ASSERT
184 namespace rapidjson {
186 template <
bool x>
struct STATIC_ASSERTION_FAILURE;
187 template <>
struct STATIC_ASSERTION_FAILURE<true> {
enum { value = 1 }; };
188 template<
int x>
struct StaticAssertTest {};
191 #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
192 #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
193 #define RAPIDJSON_DO_JOIN2(X, Y) X##Y
195 #if defined(__GNUC__)
196 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
198 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
207 #define RAPIDJSON_STATIC_ASSERT(x) typedef ::rapidjson::StaticAssertTest<\
208 sizeof(::rapidjson::STATIC_ASSERTION_FAILURE<bool(x) >)>\
209 RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
217 #define RAPIDJSON_MULTILINEMACRO_BEGIN do {
218 #define RAPIDJSON_MULTILINEMACRO_END \
222 #define RAPIDJSON_VERSION_CODE(x,y,z) \
223 (((x)*100000) + ((y)*100) + (z))
226 #define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
227 #define RAPIDJSON_DO_STRINGIFY(x) #x
232 #if defined(__clang__) || (defined(__GNUC__) && RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= RAPIDJSON_VERSION_CODE(4,2,0))
234 #define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
235 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
236 #define RAPIDJSON_DIAG_OFF(x) \
237 RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
240 #if defined(__clang__) || (defined(__GNUC__) && RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= RAPIDJSON_VERSION_CODE(4,6,0))
241 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
242 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
243 #else // GCC >= 4.2, < 4.6
244 #define RAPIDJSON_DIAG_PUSH
245 #define RAPIDJSON_DIAG_POP
248 #elif defined(_MSC_VER)
251 #define RAPIDJSON_PRAGMA(x) __pragma(x)
252 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
254 #define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
255 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
256 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
260 #define RAPIDJSON_DIAG_OFF(x)
261 #define RAPIDJSON_DIAG_PUSH
262 #define RAPIDJSON_DIAG_POP
264 #endif // RAPIDJSON_DIAG_*
271 #include "allocators.h"
272 #include "encodings.h"
275 namespace rapidjson {
314 size_t PutEnd(Ch* begin);
325 template<
typename Stream>
332 enum { copyOptimization = 0 };
336 template<
typename Stream,
typename Ch>
338 for (
size_t i = 0; i < n; i++)
348 template <
typename Encoding>
350 typedef typename Encoding::Ch Ch;
354 Ch Peek()
const {
return *
src_; }
355 Ch Take() {
return *
src_++; }
356 size_t Tell()
const {
return static_cast<size_t>(
src_ -
head_); }
367 template <
typename Encoding>
369 enum { copyOptimization = 1 };
382 template <
typename Encoding>
384 typedef typename Encoding::Ch Ch;
389 Ch Peek() {
return *src_; }
390 Ch Take() {
return *src_++; }
391 size_t Tell() {
return static_cast<size_t>(src_ - head_); }
396 Ch* PutBegin() {
return dst_ = src_; }
397 size_t PutEnd(Ch* begin) {
return static_cast<size_t>(dst_ - begin); }
400 Ch* Push(
size_t count) { Ch* begin = dst_; dst_ += count;
return begin; }
401 void Pop(
size_t count) { dst_ -= count; }
408 template <
typename Encoding>
410 enum { copyOptimization = 1 };
432 #endif // RAPIDJSON_RAPIDJSON_H_
true
Definition: rapidjson.h:423
Read-only string stream.
Definition: rapidjson.h:349
unsigned SizeType
Use 32-bit array/string indices even for 64-bit platform, instead of using size_t.
Definition: rapidjson.h:162
false
Definition: rapidjson.h:422
const Ch * head_
Original head of the string.
Definition: rapidjson.h:364
const Ch * src_
Current read position.
Definition: rapidjson.h:363
GenericInsituStringStream< UTF8<> > InsituStringStream
Insitu string stream with UTF8 encoding.
Definition: rapidjson.h:414
Concept for encoding of Unicode characters.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:175
Type
Type of JSON value.
Definition: rapidjson.h:420
object
Definition: rapidjson.h:424
GenericStringStream< UTF8<> > StringStream
String stream with UTF8 encoding.
Definition: rapidjson.h:373
array
Definition: rapidjson.h:425
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
Definition: filewritestream.h:91
null
Definition: rapidjson.h:421
Concept for reading and writing characters.
string
Definition: rapidjson.h:426
number
Definition: rapidjson.h:427
Provides additional information for stream.
Definition: rapidjson.h:326
A read-write string stream.
Definition: rapidjson.h:383