rapidjson.h
Go to the documentation of this file.
1 // Copyright (C) 2011 Milo Yip
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef RAPIDJSON_RAPIDJSON_H_
22 #define RAPIDJSON_RAPIDJSON_H_
23 
24 // Copyright (c) 2011 Milo Yip (miloyip@gmail.com)
25 // Version 0.1
26 
27 /*!\file rapidjson.h
28  \brief common definitions and configuration
29 
30  \see RAPIDJSON_CONFIG
31  */
32 
33 /*! \defgroup RAPIDJSON_CONFIG RapidJSON configuration
34  \brief Configuration macros for library features
35 
36  Some RapidJSON features are configurable to adapt the library to a wide
37  variety of platforms, environments and usage scenarios. Most of the
38  features can be configured in terms of overriden or predefined
39  preprocessor macros at compile-time.
40 
41  Some additional customization is available in the \ref RAPIDJSON_ERRORS APIs.
42 
43  \note These macros should be given on the compiler command-line
44  (where applicable) to avoid inconsistent values when compiling
45  different translation units of a single application.
46  */
47 
48 #include <cstdlib> // malloc(), realloc(), free(), size_t
49 #include <cstring> // memset(), memcpy(), memmove(), memcmp()
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 // RAPIDJSON_NO_INT64DEFINE
53 
54 /*! \def RAPIDJSON_NO_INT64DEFINE
55  \ingroup RAPIDJSON_CONFIG
56  \brief Use external 64-bit integer types.
57 
58  RapidJSON requires the 64-bit integer types \c int64_t and \c uint64_t types
59  to be available at global scope.
60 
61  If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to
62  prevent RapidJSON from defining its own types.
63 */
64 #ifndef RAPIDJSON_NO_INT64DEFINE
65 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
66 #ifdef _MSC_VER
67 #include "msinttypes/stdint.h"
68 #include "msinttypes/inttypes.h"
69 #else
70 // Other compilers should have this.
71 #include <stdint.h>
72 #include <inttypes.h>
73 #endif
74 //!@endcond
75 #ifdef RAPIDJSON_DOXYGEN_RUNNING
76 #define RAPIDJSON_NO_INT64DEFINE
77 #endif
78 #endif // RAPIDJSON_NO_INT64TYPEDEF
79 
80 ///////////////////////////////////////////////////////////////////////////////
81 // RAPIDJSON_FORCEINLINE
82 
83 #ifndef RAPIDJSON_FORCEINLINE
84 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
85 #ifdef _MSC_VER
86 #define RAPIDJSON_FORCEINLINE __forceinline
87 #elif defined(__GNUC__) && __GNUC__ >= 4
88 #define RAPIDJSON_FORCEINLINE __attribute__((always_inline))
89 #else
90 #define RAPIDJSON_FORCEINLINE
91 #endif
92 //!@endcond
93 #endif // RAPIDJSON_FORCEINLINE
94 
95 ///////////////////////////////////////////////////////////////////////////////
96 // RAPIDJSON_ENDIAN
97 #define RAPIDJSON_LITTLEENDIAN 0 //!< Little endian machine
98 #define RAPIDJSON_BIGENDIAN 1 //!< Big endian machine
99 
100 //! Endianness of the machine.
101 /*!
102  \def RAPIDJSON_ENDIAN
103  \ingroup RAPIDJSON_CONFIG
104 
105  GCC 4.6 provided macro for detecting endianness of the target machine. But other
106  compilers may not have this. User can define RAPIDJSON_ENDIAN to either
107  \ref RAPIDJSON_LITTLEENDIAN or \ref RAPIDJSON_BIGENDIAN.
108 
109  Default detection implemented with reference to
110  \li https://gcc.gnu.org/onlinedocs/gcc-4.6.0/cpp/Common-Predefined-Macros.html
111  \li http://www.boost.org/doc/libs/1_42_0/boost/detail/endian.hpp
112 */
113 #ifndef RAPIDJSON_ENDIAN
114 // Detect with GCC 4.6's macro
115 # ifdef __BYTE_ORDER__
116 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
117 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
118 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
119 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
120 # else
121 # error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
122 # endif // __BYTE_ORDER__
123 // Detect with GLIBC's endian.h
124 # elif defined(__GLIBC__)
125 # include <endian.h>
126 # if (__BYTE_ORDER == __LITTLE_ENDIAN)
127 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
128 # elif (__BYTE_ORDER == __BIG_ENDIAN)
129 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
130 # else
131 # error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
132 # endif // __GLIBC__
133 // Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
134 # elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
135 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
136 # elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
137 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
138 // Detect with architecture macros
139 # elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
140 # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
141 # 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__)
142 # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
143 # elif defined(RAPIDJSON_DOXYGEN_RUNNING)
144 # define RAPIDJSON_ENDIAN
145 # else
146 # error Unknown machine endianess detected. User needs to define RAPIDJSON_ENDIAN.
147 # endif
148 #endif // RAPIDJSON_ENDIAN
149 
150 ///////////////////////////////////////////////////////////////////////////////
151 // RAPIDJSON_64BIT
152 
153 //! Whether using 64-bit architecture
154 #ifndef RAPIDJSON_64BIT
155 #if defined(__LP64__) || defined(_WIN64)
156 #define RAPIDJSON_64BIT 1
157 #else
158 #define RAPIDJSON_64BIT 0
159 #endif
160 #endif // RAPIDJSON_64BIT
161 
162 ///////////////////////////////////////////////////////////////////////////////
163 // RAPIDJSON_ALIGN
164 
165 //! Data alignment of the machine.
166 /*! \ingroup RAPIDJSON_CONFIG
167  \param x pointer to align
168 
169  Some machines require strict data alignment. Currently the default uses 4 bytes
170  alignment. User can customize by defining the RAPIDJSON_ALIGN function macro.,
171 */
172 #ifndef RAPIDJSON_ALIGN
173 #define RAPIDJSON_ALIGN(x) ((x + 3u) & ~3u)
174 #endif
175 
176 ///////////////////////////////////////////////////////////////////////////////
177 // RAPIDJSON_UINT64_C2
178 
179 //! Construct a 64-bit literal by a pair of 32-bit integer.
180 /*!
181  64-bit literal with or without ULL suffix is prone to compiler warnings.
182  UINT64_C() is C macro which cause compilation problems.
183  Use this macro to define 64-bit constants by a pair of 32-bit integer.
184 */
185 #ifndef RAPIDJSON_UINT64_C2
186 #define RAPIDJSON_UINT64_C2(high32, low32) ((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))
187 #endif
188 
189 ///////////////////////////////////////////////////////////////////////////////
190 // RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_SIMD
191 
192 /*! \def RAPIDJSON_SIMD
193  \ingroup RAPIDJSON_CONFIG
194  \brief Enable SSE2/SSE4.2 optimization.
195 
196  RapidJSON supports optimized implementations for some parsing operations
197  based on the SSE2 or SSE4.2 SIMD extensions on modern Intel-compatible
198  processors.
199 
200  To enable these optimizations, two different symbols can be defined;
201  \code
202  // Enable SSE2 optimization.
203  #define RAPIDJSON_SSE2
204 
205  // Enable SSE4.2 optimization.
206  #define RAPIDJSON_SSE42
207  \endcode
208 
209  \c RAPIDJSON_SSE42 takes precedence, if both are defined.
210 
211  If any of these symbols is defined, RapidJSON defines the macro
212  \c RAPIDJSON_SIMD to indicate the availability of the optimized code.
213 */
214 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
215  || defined(RAPIDJSON_DOXYGEN_RUNNING)
216 #define RAPIDJSON_SIMD
217 #endif
218 
219 ///////////////////////////////////////////////////////////////////////////////
220 // RAPIDJSON_NO_SIZETYPEDEFINE
221 
222 #ifndef RAPIDJSON_NO_SIZETYPEDEFINE
223 /*! \def RAPIDJSON_NO_SIZETYPEDEFINE
224  \ingroup RAPIDJSON_CONFIG
225  \brief User-provided \c SizeType definition.
226 
227  In order to avoid using 32-bit size types for indexing strings and arrays,
228  define this preprocessor symbol and provide the type rapidjson::SizeType
229  before including RapidJSON:
230  \code
231  #define RAPIDJSON_NO_SIZETYPEDEFINE
232  namespace rapidjson { typedef ::std::size_t SizeType; }
233  #include "rapidjson/..."
234  \endcode
235 
236  \see rapidjson::SizeType
237 */
238 #ifdef RAPIDJSON_DOXYGEN_RUNNING
239 #define RAPIDJSON_NO_SIZETYPEDEFINE
240 #endif
241 namespace rapidjson {
242 //! Size type (for string lengths, array sizes, etc.)
243 /*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms,
244  instead of using \c size_t. Users may override the SizeType by defining
245  \ref RAPIDJSON_NO_SIZETYPEDEFINE.
246 */
247 typedef unsigned SizeType;
248 } // namespace rapidjson
249 #endif
250 
251 // always import std::size_t to rapidjson namespace
252 namespace rapidjson {
253 using std::size_t;
254 } // namespace rapidjson
255 
256 ///////////////////////////////////////////////////////////////////////////////
257 // RAPIDJSON_ASSERT
258 
259 //! Assertion.
260 /*! \ingroup RAPIDJSON_CONFIG
261  By default, rapidjson uses C \c assert() for internal assertions.
262  User can override it by defining RAPIDJSON_ASSERT(x) macro.
263 
264  \note Parsing errors are handled and can be customized by the
265  \ref RAPIDJSON_ERRORS APIs.
266 */
267 #ifndef RAPIDJSON_ASSERT
268 #include <cassert>
269 #define RAPIDJSON_ASSERT(x) assert(x)
270 #endif // RAPIDJSON_ASSERT
271 
272 ///////////////////////////////////////////////////////////////////////////////
273 // RAPIDJSON_STATIC_ASSERT
274 
275 // Adopt from boost
276 #ifndef RAPIDJSON_STATIC_ASSERT
277 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
278 namespace rapidjson {
279 
280 template <bool x> struct STATIC_ASSERTION_FAILURE;
281 template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
282 template<int x> struct StaticAssertTest {};
283 } // namespace rapidjson
284 
285 #define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
286 #define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
287 #define RAPIDJSON_DO_JOIN2(X, Y) X##Y
288 
289 #if defined(__GNUC__)
290 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
291 #else
292 #define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
293 #endif
294 //!@endcond
295 
296 /*! \def RAPIDJSON_STATIC_ASSERT
297  \brief (Internal) macro to check for conditions at compile-time
298  \param x compile-time condition
299  \hideinitializer
300  */
301 #define RAPIDJSON_STATIC_ASSERT(x) typedef ::rapidjson::StaticAssertTest<\
302  sizeof(::rapidjson::STATIC_ASSERTION_FAILURE<bool(x) >)>\
303  RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
304 #endif
305 
306 ///////////////////////////////////////////////////////////////////////////////
307 // Helpers
308 
309 //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
310 
311 #define RAPIDJSON_MULTILINEMACRO_BEGIN do {
312 #define RAPIDJSON_MULTILINEMACRO_END \
313 } while((void)0, 0)
314 
315 // adopted from Boost
316 #define RAPIDJSON_VERSION_CODE(x,y,z) \
317  (((x)*100000) + ((y)*100) + (z))
318 
319 // token stringification
320 #define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x)
321 #define RAPIDJSON_DO_STRINGIFY(x) #x
322 
323 ///////////////////////////////////////////////////////////////////////////////
324 // RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
325 
326 #if defined(__GNUC__)
327 #define RAPIDJSON_GNUC \
328  RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
329 #endif
330 
331 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
332 
333 #define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
334 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
335 #define RAPIDJSON_DIAG_OFF(x) \
336  RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
337 
338 // push/pop support in Clang and GCC>=4.6
339 #if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
340 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
341 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
342 #else // GCC >= 4.2, < 4.6
343 #define RAPIDJSON_DIAG_PUSH /* ignored */
344 #define RAPIDJSON_DIAG_POP /* ignored */
345 #endif
346 
347 #elif defined(_MSC_VER)
348 
349 // pragma (MSVC specific)
350 #define RAPIDJSON_PRAGMA(x) __pragma(x)
351 #define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
352 
353 #define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
354 #define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
355 #define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
356 
357 #else
358 
359 #define RAPIDJSON_DIAG_OFF(x) /* ignored */
360 #define RAPIDJSON_DIAG_PUSH /* ignored */
361 #define RAPIDJSON_DIAG_POP /* ignored */
362 
363 #endif // RAPIDJSON_DIAG_*
364 
365 ///////////////////////////////////////////////////////////////////////////////
366 // C++11 features
367 
368 #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
369 #if defined(__clang__)
370 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS __has_feature(cxx_rvalue_references)
371 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
372  (defined(_MSC_VER) && _MSC_VER >= 1600)
373 
374 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
375 #else
376 #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
377 #endif
378 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
379 
380 #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
381 #if defined(__clang__)
382 #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
383 #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
384 // (defined(_MSC_VER) && _MSC_VER >= ????) // not yet supported
385 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
386 #else
387 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
388 #endif
389 #endif
390 #if RAPIDJSON_HAS_CXX11_NOEXCEPT
391 #define RAPIDJSON_NOEXCEPT noexcept
392 #else
393 #define RAPIDJSON_NOEXCEPT /* noexcept */
394 #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
395 
396 // no automatic detection, yet
397 #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
398 #define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
399 #endif
400 
401 //!@endcond
402 
403 ///////////////////////////////////////////////////////////////////////////////
404 // new/delete
405 
406 #ifndef RAPIDJSON_NEW
407 ///! customization point for global \c new
408 #define RAPIDJSON_NEW(x) new x
409 #endif
410 #ifndef RAPIDJSON_DELETE
411 ///! customization point for global \c delete
412 #define RAPIDJSON_DELETE(x) delete x
413 #endif
414 
415 ///////////////////////////////////////////////////////////////////////////////
416 // Allocators and Encodings
417 
418 #include "allocators.h"
419 #include "encodings.h"
420 
421 //! main RapidJSON namespace
422 namespace rapidjson {
423 
424 ///////////////////////////////////////////////////////////////////////////////
425 // Stream
426 
427 /*! \class rapidjson::Stream
428  \brief Concept for reading and writing characters.
429 
430  For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd().
431 
432  For write-only stream, only need to implement Put() and Flush().
433 
434 \code
435 concept Stream {
436  typename Ch; //!< Character type of the stream.
437 
438  //! Read the current character from stream without moving the read cursor.
439  Ch Peek() const;
440 
441  //! Read the current character from stream and moving the read cursor to next character.
442  Ch Take();
443 
444  //! Get the current read cursor.
445  //! \return Number of characters read from start.
446  size_t Tell();
447 
448  //! Begin writing operation at the current read pointer.
449  //! \return The begin writer pointer.
450  Ch* PutBegin();
451 
452  //! Write a character.
453  void Put(Ch c);
454 
455  //! Flush the buffer.
456  void Flush();
457 
458  //! End the writing operation.
459  //! \param begin The begin write pointer returned by PutBegin().
460  //! \return Number of characters written.
461  size_t PutEnd(Ch* begin);
462 }
463 \endcode
464 */
465 
466 //! Provides additional information for stream.
467 /*!
468  By using traits pattern, this type provides a default configuration for stream.
469  For custom stream, this type can be specialized for other configuration.
470  See TEST(Reader, CustomStringStream) in readertest.cpp for example.
471 */
472 template<typename Stream>
473 struct StreamTraits {
474  //! Whether to make local copy of stream for optimization during parsing.
475  /*!
476  By default, for safety, streams do not use local copy optimization.
477  Stream that can be copied fast should specialize this, like StreamTraits<StringStream>.
478  */
479  enum { copyOptimization = 0 };
480 };
481 
482 //! Put N copies of a character to a stream.
483 template<typename Stream, typename Ch>
484 inline void PutN(Stream& stream, Ch c, size_t n) {
485  for (size_t i = 0; i < n; i++)
486  stream.Put(c);
487 }
488 
489 ///////////////////////////////////////////////////////////////////////////////
490 // StringStream
491 
492 //! Read-only string stream.
493 /*! \note implements Stream concept
494 */
495 template <typename Encoding>
497  typedef typename Encoding::Ch Ch;
498 
499  GenericStringStream(const Ch *src) : src_(src), head_(src) {}
500 
501  Ch Peek() const { return *src_; }
502  Ch Take() { return *src_++; }
503  size_t Tell() const { return static_cast<size_t>(src_ - head_); }
504 
505  Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
506  void Put(Ch) { RAPIDJSON_ASSERT(false); }
507  void Flush() { RAPIDJSON_ASSERT(false); }
508  size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
509 
510  const Ch* src_; //!< Current read position.
511  const Ch* head_; //!< Original head of the string.
512 };
513 
514 template <typename Encoding>
516  enum { copyOptimization = 1 };
517 };
518 
519 //! String stream with UTF8 encoding.
521 
522 ///////////////////////////////////////////////////////////////////////////////
523 // InsituStringStream
524 
525 //! A read-write string stream.
526 /*! This string stream is particularly designed for in-situ parsing.
527  \note implements Stream concept
528 */
529 template <typename Encoding>
531  typedef typename Encoding::Ch Ch;
532 
533  GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {}
534 
535  // Read
536  Ch Peek() { return *src_; }
537  Ch Take() { return *src_++; }
538  size_t Tell() { return static_cast<size_t>(src_ - head_); }
539 
540  // Write
541  void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; }
542 
543  Ch* PutBegin() { return dst_ = src_; }
544  size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
545  void Flush() {}
546 
547  Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; }
548  void Pop(size_t count) { dst_ -= count; }
549 
550  Ch* src_;
551  Ch* dst_;
552  Ch* head_;
553 };
554 
555 template <typename Encoding>
557  enum { copyOptimization = 1 };
558 };
559 
560 //! Insitu string stream with UTF8 encoding.
562 
563 ///////////////////////////////////////////////////////////////////////////////
564 // Type
565 
566 //! Type of JSON value
567 enum Type {
568  kNullType = 0, //!< null
569  kFalseType = 1, //!< false
570  kTrueType = 2, //!< true
571  kObjectType = 3, //!< object
572  kArrayType = 4, //!< array
573  kStringType = 5, //!< string
574  kNumberType = 6 //!< number
575 };
576 
577 } // namespace rapidjson
578 
579 #endif // RAPIDJSON_RAPIDJSON_H_
true
Definition: rapidjson.h:570
Read-only string stream.
Definition: rapidjson.h:496
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:247
false
Definition: rapidjson.h:569
const Ch * head_
Original head of the string.
Definition: rapidjson.h:511
const Ch * src_
Current read position.
Definition: rapidjson.h:510
GenericInsituStringStream< UTF8<> > InsituStringStream
Insitu string stream with UTF8 encoding.
Definition: rapidjson.h:561
Concept for encoding of Unicode characters.
Type
Type of JSON value.
Definition: rapidjson.h:567
object
Definition: rapidjson.h:571
GenericStringStream< UTF8<> > StringStream
String stream with UTF8 encoding.
Definition: rapidjson.h:520
array
Definition: rapidjson.h:572
main RapidJSON namespace
Definition: rapidjson.h:241
null
Definition: rapidjson.h:568
Concept for reading and writing characters.
string
Definition: rapidjson.h:573
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:269
number
Definition: rapidjson.h:574
Provides additional information for stream.
Definition: rapidjson.h:473
A read-write string stream.
Definition: rapidjson.h:530
void PutN(Stream &stream, Ch c, size_t n)
Put N copies of a character to a stream.
Definition: rapidjson.h:484