document.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON available.
2 //
3 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 //
5 // Licensed under the MIT License (the "License"); you may not use this file except
6 // in compliance with the License. You may obtain a copy of the License at
7 //
8 // http://opensource.org/licenses/MIT
9 //
10 // Unless required by applicable law or agreed to in writing, software distributed
11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 // specific language governing permissions and limitations under the License.
14 
15 #ifndef RAPIDJSON_DOCUMENT_H_
16 #define RAPIDJSON_DOCUMENT_H_
17 
20 #include "reader.h"
21 #include "internal/meta.h"
22 #include "internal/strfunc.h"
23 #include "memorystream.h"
24 #include "encodedstream.h"
25 #include <new> // placement new
26 #include <limits>
27 
28 RAPIDJSON_DIAG_PUSH
29 #ifdef _MSC_VER
30 RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
31 RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
32 #ifdef _MINWINDEF_ // see: http://stackoverflow.com/questions/22744262/cant-call-stdmax-because-minwindef-h-defines-max
33 #ifndef NOMINMAX
34 #pragma push_macro("min")
35 #pragma push_macro("max")
36 #undef min
37 #undef max
38 #endif
39 #endif
40 #endif
41 
42 #ifdef __clang__
43 RAPIDJSON_DIAG_OFF(padded)
44 RAPIDJSON_DIAG_OFF(switch-enum)
45 RAPIDJSON_DIAG_OFF(c++98-compat)
46 #endif
47 
48 #ifdef __GNUC__
49 RAPIDJSON_DIAG_OFF(effc++)
50 #if __GNUC__ >= 6
51 RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_NOEXCEPT functions
52 #endif
53 #endif // __GNUC__
54 
55 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
56 #include <iterator> // std::iterator, std::random_access_iterator_tag
57 #endif
58 
59 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
60 #include <utility> // std::move
61 #endif
62 
64 
65 // Forward declaration.
66 template <typename Encoding, typename Allocator>
68 
69 template <typename Encoding, typename Allocator, typename StackAllocator>
71 
73 
78 template <typename Encoding, typename Allocator>
79 struct GenericMember {
82 };
83 
85 // GenericMemberIterator
86 
87 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
88 
90 
108 template <bool Const, typename Encoding, typename Allocator>
110  : public std::iterator<std::random_access_iterator_tag
111  , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
112 
113  friend class GenericValue<Encoding,Allocator>;
114  template <bool, typename, typename> friend class GenericMemberIterator;
115 
118  typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
119 
120 public:
127 
129  typedef typename BaseType::pointer Pointer;
131  typedef typename BaseType::reference Reference;
133  typedef typename BaseType::difference_type DifferenceType;
134 
136 
140 
142 
157  GenericMemberIterator(const NonConstIterator & it) : ptr_(it.ptr_) {}
158  Iterator& operator=(const NonConstIterator & it) { ptr_ = it.ptr_; return *this; }
159 
161 
162  Iterator& operator++(){ ++ptr_; return *this; }
163  Iterator& operator--(){ --ptr_; return *this; }
164  Iterator operator++(int){ Iterator old(*this); ++ptr_; return old; }
165  Iterator operator--(int){ Iterator old(*this); --ptr_; return old; }
167 
169 
170  Iterator operator+(DifferenceType n) const { return Iterator(ptr_+n); }
171  Iterator operator-(DifferenceType n) const { return Iterator(ptr_-n); }
172 
173  Iterator& operator+=(DifferenceType n) { ptr_+=n; return *this; }
174  Iterator& operator-=(DifferenceType n) { ptr_-=n; return *this; }
176 
178 
179  bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
180  bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
181  bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
182  bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
183  bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; }
184  bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; }
186 
188 
189  Reference operator*() const { return *ptr_; }
190  Pointer operator->() const { return ptr_; }
191  Reference operator[](DifferenceType n) const { return ptr_[n]; }
193 
195  DifferenceType operator-(ConstIterator that) const { return ptr_-that.ptr_; }
196 
197 private:
199  explicit GenericMemberIterator(Pointer p) : ptr_(p) {}
200 
201  Pointer ptr_;
202 };
203 
204 #else // RAPIDJSON_NOMEMBERITERATORCLASS
205 
206 // class-based member iterator implementation disabled, use plain pointers
207 
208 template <bool Const, typename Encoding, typename Allocator>
209 struct GenericMemberIterator;
210 
212 template <typename Encoding, typename Allocator>
213 struct GenericMemberIterator<false,Encoding,Allocator> {
216 };
218 template <typename Encoding, typename Allocator>
219 struct GenericMemberIterator<true,Encoding,Allocator> {
222 };
223 
224 #endif // RAPIDJSON_NOMEMBERITERATORCLASS
225 
227 // GenericStringRef
228 
230 
256 template<typename CharType>
258  typedef CharType Ch;
259 
261 #ifndef __clang__ // -Wdocumentation
262 
284 #endif
285  template<SizeType N>
286  GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
287  : s(str), length(N-1) {}
288 
290 #ifndef __clang__ // -Wdocumentation
291 
309 #endif
310  explicit GenericStringRef(const CharType* str)
311  : s(str), length(NotNullStrLen(str)) {}
312 
314 #ifndef __clang__ // -Wdocumentation
315 
321 #endif
322  GenericStringRef(const CharType* str, SizeType len)
323  : s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) { RAPIDJSON_ASSERT(str != 0 || len == 0u); }
324 
325  GenericStringRef(const GenericStringRef& rhs) : s(rhs.s), length(rhs.length) {}
326 
328  operator const Ch *() const { return s; }
329 
330  const Ch* const s;
331  const SizeType length;
332 
333 private:
334  SizeType NotNullStrLen(const CharType* str) {
335  RAPIDJSON_ASSERT(str != 0);
336  return internal::StrLen(str);
337  }
338 
340  static const Ch emptyString[];
341 
343  template<SizeType N>
344  GenericStringRef(CharType (&str)[N]) /* = delete */;
346  GenericStringRef& operator=(const GenericStringRef& rhs) /* = delete */;
347 };
348 
349 template<typename CharType>
350 const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
351 
353 
364 template<typename CharType>
365 inline GenericStringRef<CharType> StringRef(const CharType* str) {
366  return GenericStringRef<CharType>(str);
367 }
368 
370 
384 template<typename CharType>
385 inline GenericStringRef<CharType> StringRef(const CharType* str, size_t length) {
386  return GenericStringRef<CharType>(str, SizeType(length));
387 }
388 
389 #if RAPIDJSON_HAS_STDSTRING
390 
402 template<typename CharType>
403 inline GenericStringRef<CharType> StringRef(const std::basic_string<CharType>& str) {
404  return GenericStringRef<CharType>(str.data(), SizeType(str.size()));
405 }
406 #endif
407 
409 // GenericValue type traits
410 namespace internal {
411 
412 template <typename T, typename Encoding = void, typename Allocator = void>
413 struct IsGenericValueImpl : FalseType {};
414 
415 // select candidates according to nested encoding and allocator types
416 template <typename T> struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
417  : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
418 
419 // helper to match arbitrary GenericValue instantiations, including derived classes
420 template <typename T> struct IsGenericValue : IsGenericValueImpl<T>::Type {};
421 
422 } // namespace internal
423 
425 // TypeHelper
426 
427 namespace internal {
428 
429 template <typename ValueType, typename T>
430 struct TypeHelper {};
431 
432 template<typename ValueType>
433 struct TypeHelper<ValueType, bool> {
434  static bool Is(const ValueType& v) { return v.IsBool(); }
435  static bool Get(const ValueType& v) { return v.GetBool(); }
436  static ValueType& Set(ValueType& v, bool data) { return v.SetBool(data); }
437  static ValueType& Set(ValueType& v, bool data, typename ValueType::AllocatorType&) { return v.SetBool(data); }
438 };
439 
440 template<typename ValueType>
441 struct TypeHelper<ValueType, int> {
442  static bool Is(const ValueType& v) { return v.IsInt(); }
443  static int Get(const ValueType& v) { return v.GetInt(); }
444  static ValueType& Set(ValueType& v, int data) { return v.SetInt(data); }
445  static ValueType& Set(ValueType& v, int data, typename ValueType::AllocatorType&) { return v.SetInt(data); }
446 };
447 
448 template<typename ValueType>
449 struct TypeHelper<ValueType, unsigned> {
450  static bool Is(const ValueType& v) { return v.IsUint(); }
451  static unsigned Get(const ValueType& v) { return v.GetUint(); }
452  static ValueType& Set(ValueType& v, unsigned data) { return v.SetUint(data); }
453  static ValueType& Set(ValueType& v, unsigned data, typename ValueType::AllocatorType&) { return v.SetUint(data); }
454 };
455 
456 template<typename ValueType>
457 struct TypeHelper<ValueType, int64_t> {
458  static bool Is(const ValueType& v) { return v.IsInt64(); }
459  static int64_t Get(const ValueType& v) { return v.GetInt64(); }
460  static ValueType& Set(ValueType& v, int64_t data) { return v.SetInt64(data); }
461  static ValueType& Set(ValueType& v, int64_t data, typename ValueType::AllocatorType&) { return v.SetInt64(data); }
462 };
463 
464 template<typename ValueType>
465 struct TypeHelper<ValueType, uint64_t> {
466  static bool Is(const ValueType& v) { return v.IsUint64(); }
467  static uint64_t Get(const ValueType& v) { return v.GetUint64(); }
468  static ValueType& Set(ValueType& v, uint64_t data) { return v.SetUint64(data); }
469  static ValueType& Set(ValueType& v, uint64_t data, typename ValueType::AllocatorType&) { return v.SetUint64(data); }
470 };
471 
472 template<typename ValueType>
473 struct TypeHelper<ValueType, double> {
474  static bool Is(const ValueType& v) { return v.IsDouble(); }
475  static double Get(const ValueType& v) { return v.GetDouble(); }
476  static ValueType& Set(ValueType& v, double data) { return v.SetDouble(data); }
477  static ValueType& Set(ValueType& v, double data, typename ValueType::AllocatorType&) { return v.SetDouble(data); }
478 };
479 
480 template<typename ValueType>
481 struct TypeHelper<ValueType, float> {
482  static bool Is(const ValueType& v) { return v.IsFloat(); }
483  static float Get(const ValueType& v) { return v.GetFloat(); }
484  static ValueType& Set(ValueType& v, float data) { return v.SetFloat(data); }
485  static ValueType& Set(ValueType& v, float data, typename ValueType::AllocatorType&) { return v.SetFloat(data); }
486 };
487 
488 template<typename ValueType>
489 struct TypeHelper<ValueType, const typename ValueType::Ch*> {
490  typedef const typename ValueType::Ch* StringType;
491  static bool Is(const ValueType& v) { return v.IsString(); }
492  static StringType Get(const ValueType& v) { return v.GetString(); }
493  static ValueType& Set(ValueType& v, const StringType data) { return v.SetString(typename ValueType::StringRefType(data)); }
494  static ValueType& Set(ValueType& v, const StringType data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
495 };
496 
497 #if RAPIDJSON_HAS_STDSTRING
498 template<typename ValueType>
499 struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
500  typedef std::basic_string<typename ValueType::Ch> StringType;
501  static bool Is(const ValueType& v) { return v.IsString(); }
502  static StringType Get(const ValueType& v) { return StringType(v.GetString(), v.GetStringLength()); }
503  static ValueType& Set(ValueType& v, const StringType& data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
504 };
505 #endif
506 
507 template<typename ValueType>
508 struct TypeHelper<ValueType, typename ValueType::Array> {
509  typedef typename ValueType::Array ArrayType;
510  static bool Is(const ValueType& v) { return v.IsArray(); }
511  static ArrayType Get(ValueType& v) { return v.GetArray(); }
512  static ValueType& Set(ValueType& v, ArrayType data) { return v = data; }
513  static ValueType& Set(ValueType& v, ArrayType data, typename ValueType::AllocatorType&) { return v = data; }
514 };
515 
516 template<typename ValueType>
517 struct TypeHelper<ValueType, typename ValueType::ConstArray> {
518  typedef typename ValueType::ConstArray ArrayType;
519  static bool Is(const ValueType& v) { return v.IsArray(); }
520  static ArrayType Get(const ValueType& v) { return v.GetArray(); }
521 };
522 
523 template<typename ValueType>
524 struct TypeHelper<ValueType, typename ValueType::Object> {
525  typedef typename ValueType::Object ObjectType;
526  static bool Is(const ValueType& v) { return v.IsObject(); }
527  static ObjectType Get(ValueType& v) { return v.GetObject(); }
528  static ValueType& Set(ValueType& v, ObjectType data) { return v = data; }
529  static ValueType& Set(ValueType& v, ObjectType data, typename ValueType::AllocatorType&) { return v = data; }
530 };
531 
532 template<typename ValueType>
533 struct TypeHelper<ValueType, typename ValueType::ConstObject> {
534  typedef typename ValueType::ConstObject ObjectType;
535  static bool Is(const ValueType& v) { return v.IsObject(); }
536  static ObjectType Get(const ValueType& v) { return v.GetObject(); }
537 };
538 
539 } // namespace internal
540 
541 // Forward declarations
542 template <bool, typename> class GenericArray;
543 template <bool, typename> class GenericObject;
544 
546 // GenericValue
547 
549 
558 template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
559 class GenericValue {
560 public:
563  typedef Encoding EncodingType;
564  typedef Allocator AllocatorType;
565  typedef typename Encoding::Ch Ch;
576 
578 
579 
581  GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
582 
583 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
584  GenericValue(GenericValue&& rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) {
586  rhs.data_.f.flags = kNullFlag; // give up contents
587  }
588 #endif
589 
590 private:
592  GenericValue(const GenericValue& rhs);
593 
594 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
595  template <typename StackAllocator>
598 
600  template <typename StackAllocator>
602 #endif
603 
604 public:
605 
607 
611  explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() {
612  static const uint16_t defaultFlags[7] = {
613  kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
614  kNumberAnyFlag
615  };
616  RAPIDJSON_ASSERT(type <= kNumberType);
617  data_.f.flags = defaultFlags[type];
618 
619  // Use ShortString to store empty string.
620  if (type == kStringType)
621  data_.ss.SetLength(0);
622  }
623 
625 
632  template <typename SourceAllocator>
633  GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
634  switch (rhs.GetType()) {
635  case kObjectType: {
636  SizeType count = rhs.data_.o.size;
637  Member* lm = reinterpret_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
639  for (SizeType i = 0; i < count; i++) {
640  new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
641  new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings);
642  }
643  data_.f.flags = kObjectFlag;
644  data_.o.size = data_.o.capacity = count;
645  SetMembersPointer(lm);
646  }
647  break;
648  case kArrayType: {
649  SizeType count = rhs.data_.a.size;
650  GenericValue* le = reinterpret_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
652  for (SizeType i = 0; i < count; i++)
653  new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
654  data_.f.flags = kArrayFlag;
655  data_.a.size = data_.a.capacity = count;
656  SetElementsPointer(le);
657  }
658  break;
659  case kStringType:
660  if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
661  data_.f.flags = rhs.data_.f.flags;
662  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
663  }
664  else
665  SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
666  break;
667  default:
668  data_.f.flags = rhs.data_.f.flags;
669  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
670  break;
671  }
672  }
673 
675 
680 #ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
681  template <typename T>
682  explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT // See #472
683 #else
684  explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT
685 #endif
686  : data_() {
687  // safe-guard against failing SFINAE
689  data_.f.flags = b ? kTrueFlag : kFalseFlag;
690  }
691 
693  explicit GenericValue(int i) RAPIDJSON_NOEXCEPT : data_() {
694  data_.n.i64 = i;
695  data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
696  }
697 
699  explicit GenericValue(unsigned u) RAPIDJSON_NOEXCEPT : data_() {
700  data_.n.u64 = u;
701  data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
702  }
703 
705  explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_() {
706  data_.n.i64 = i64;
707  data_.f.flags = kNumberInt64Flag;
708  if (i64 >= 0) {
709  data_.f.flags |= kNumberUint64Flag;
710  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
711  data_.f.flags |= kUintFlag;
712  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
713  data_.f.flags |= kIntFlag;
714  }
715  else if (i64 >= static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
716  data_.f.flags |= kIntFlag;
717  }
718 
720  explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_() {
721  data_.n.u64 = u64;
722  data_.f.flags = kNumberUint64Flag;
723  if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
724  data_.f.flags |= kInt64Flag;
725  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
726  data_.f.flags |= kUintFlag;
727  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
728  data_.f.flags |= kIntFlag;
729  }
730 
732  explicit GenericValue(double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
733 
735  explicit GenericValue(float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = static_cast<double>(f); data_.f.flags = kNumberDoubleFlag; }
736 
738  GenericValue(const Ch* s, SizeType length) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(StringRef(s, length)); }
739 
741  explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(s); }
742 
744  GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_() { SetStringRaw(StringRef(s, length), allocator); }
745 
747  GenericValue(const Ch*s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
748 
749 #if RAPIDJSON_HAS_STDSTRING
750 
753  GenericValue(const std::basic_string<Ch>& s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
754 #endif
755 
757 
762  GenericValue(Array a) RAPIDJSON_NOEXCEPT : data_(a.value_.data_) {
763  a.value_.data_ = Data();
764  a.value_.data_.f.flags = kArrayFlag;
765  }
766 
768 
773  GenericValue(Object o) RAPIDJSON_NOEXCEPT : data_(o.value_.data_) {
774  o.value_.data_ = Data();
775  o.value_.data_.f.flags = kObjectFlag;
776  }
777 
779 
782  if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
783  switch(data_.f.flags) {
784  case kArrayFlag:
785  {
786  GenericValue* e = GetElementsPointer();
787  for (GenericValue* v = e; v != e + data_.a.size; ++v)
788  v->~GenericValue();
789  Allocator::Free(e);
790  }
791  break;
792 
793  case kObjectFlag:
794  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
795  m->~Member();
796  Allocator::Free(GetMembersPointer());
797  break;
798 
799  case kCopyStringFlag:
800  Allocator::Free(const_cast<Ch*>(GetStringPointer()));
801  break;
802 
803  default:
804  break; // Do nothing for other types.
805  }
806  }
807  }
808 
810 
812 
813 
815 
817  GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
818  RAPIDJSON_ASSERT(this != &rhs);
819  this->~GenericValue();
820  RawAssign(rhs);
821  return *this;
822  }
823 
824 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
825  GenericValue& operator=(GenericValue&& rhs) RAPIDJSON_NOEXCEPT {
827  return *this = rhs.Move();
828  }
829 #endif
830 
832 
836  GenericValue& operator=(StringRefType str) RAPIDJSON_NOEXCEPT {
837  GenericValue s(str);
838  return *this = s;
839  }
840 
842 
853  template <typename T>
854  RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (GenericValue&))
855  operator=(T value) {
856  GenericValue v(value);
857  return *this = v;
858  }
859 
861 
867  template <typename SourceAllocator>
868  GenericValue& CopyFrom(const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
869  RAPIDJSON_ASSERT(static_cast<void*>(this) != static_cast<void const*>(&rhs));
870  this->~GenericValue();
871  new (this) GenericValue(rhs, allocator, copyConstStrings);
872  return *this;
873  }
874 
876 
880  GenericValue& Swap(GenericValue& other) RAPIDJSON_NOEXCEPT {
881  GenericValue temp;
882  temp.RawAssign(*this);
883  RawAssign(other);
884  other.RawAssign(temp);
885  return *this;
886  }
887 
889 
900  friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
901 
903 
904  GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; }
906 
908 
909 
914  template <typename SourceAllocator>
915  bool operator==(const GenericValue<Encoding, SourceAllocator>& rhs) const {
917  if (GetType() != rhs.GetType())
918  return false;
919 
920  switch (GetType()) {
921  case kObjectType: // Warning: O(n^2) inner-loop
922  if (data_.o.size != rhs.data_.o.size)
923  return false;
924  for (ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
925  typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name);
926  if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
927  return false;
928  }
929  return true;
930 
931  case kArrayType:
932  if (data_.a.size != rhs.data_.a.size)
933  return false;
934  for (SizeType i = 0; i < data_.a.size; i++)
935  if ((*this)[i] != rhs[i])
936  return false;
937  return true;
938 
939  case kStringType:
940  return StringEqual(rhs);
941 
942  case kNumberType:
943  if (IsDouble() || rhs.IsDouble()) {
944  double a = GetDouble(); // May convert from integer to double.
945  double b = rhs.GetDouble(); // Ditto
946  return a >= b && a <= b; // Prevent -Wfloat-equal
947  }
948  else
949  return data_.n.u64 == rhs.data_.n.u64;
950 
951  default:
952  return true;
953  }
954  }
955 
957  bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); }
958 
959 #if RAPIDJSON_HAS_STDSTRING
960 
963  bool operator==(const std::basic_string<Ch>& rhs) const { return *this == GenericValue(StringRef(rhs)); }
964 #endif
965 
967 
969  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); }
970 
972 
974  template <typename SourceAllocator>
975  bool operator!=(const GenericValue<Encoding, SourceAllocator>& rhs) const { return !(*this == rhs); }
976 
978  bool operator!=(const Ch* rhs) const { return !(*this == rhs); }
979 
981 
983  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& rhs) const { return !(*this == rhs); }
984 
986 
988  template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator==(const T& lhs, const GenericValue& rhs) { return rhs == lhs; }
989 
991 
993  template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); }
995 
997 
998 
999  Type GetType() const { return static_cast<Type>(data_.f.flags & kTypeMask); }
1000  bool IsNull() const { return data_.f.flags == kNullFlag; }
1001  bool IsFalse() const { return data_.f.flags == kFalseFlag; }
1002  bool IsTrue() const { return data_.f.flags == kTrueFlag; }
1003  bool IsBool() const { return (data_.f.flags & kBoolFlag) != 0; }
1004  bool IsObject() const { return data_.f.flags == kObjectFlag; }
1005  bool IsArray() const { return data_.f.flags == kArrayFlag; }
1006  bool IsNumber() const { return (data_.f.flags & kNumberFlag) != 0; }
1007  bool IsInt() const { return (data_.f.flags & kIntFlag) != 0; }
1008  bool IsUint() const { return (data_.f.flags & kUintFlag) != 0; }
1009  bool IsInt64() const { return (data_.f.flags & kInt64Flag) != 0; }
1010  bool IsUint64() const { return (data_.f.flags & kUint64Flag) != 0; }
1011  bool IsDouble() const { return (data_.f.flags & kDoubleFlag) != 0; }
1012  bool IsString() const { return (data_.f.flags & kStringFlag) != 0; }
1013 
1014  // Checks whether a number can be losslessly converted to a double.
1015  bool IsLosslessDouble() const {
1016  if (!IsNumber()) return false;
1017  if (IsUint64()) {
1018  uint64_t u = GetUint64();
1019  volatile double d = static_cast<double>(u);
1020  return (d >= 0.0)
1021  && (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
1022  && (u == static_cast<uint64_t>(d));
1023  }
1024  if (IsInt64()) {
1025  int64_t i = GetInt64();
1026  volatile double d = static_cast<double>(i);
1027  return (d >= static_cast<double>(std::numeric_limits<int64_t>::min()))
1028  && (d < static_cast<double>(std::numeric_limits<int64_t>::max()))
1029  && (i == static_cast<int64_t>(d));
1030  }
1031  return true; // double, int, uint are always lossless
1032  }
1033 
1034  // Checks whether a number is a float (possible lossy).
1035  bool IsFloat() const {
1036  if ((data_.f.flags & kDoubleFlag) == 0)
1037  return false;
1038  double d = GetDouble();
1039  return d >= -3.4028234e38 && d <= 3.4028234e38;
1040  }
1041  // Checks whether a number can be losslessly converted to a float.
1042  bool IsLosslessFloat() const {
1043  if (!IsNumber()) return false;
1044  double a = GetDouble();
1045  if (a < static_cast<double>(-std::numeric_limits<float>::max())
1046  || a > static_cast<double>(std::numeric_limits<float>::max()))
1047  return false;
1048  double b = static_cast<double>(static_cast<float>(a));
1049  return a >= b && a <= b; // Prevent -Wfloat-equal
1050  }
1051 
1053 
1055 
1056 
1057  GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; }
1058 
1060 
1062 
1063 
1064  bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return data_.f.flags == kTrueFlag; }
1066 
1067  GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
1068 
1070 
1072 
1073 
1075 
1076  GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
1077 
1079  SizeType MemberCount() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size; }
1080 
1082  bool ObjectEmpty() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size == 0; }
1083 
1085 
1093  template <typename T>
1094  RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(GenericValue&)) operator[](T* name) {
1095  GenericValue n(StringRef(name));
1096  return (*this)[n];
1097  }
1098  template <typename T>
1099  RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(const GenericValue&)) operator[](T* name) const { return const_cast<GenericValue&>(*this)[name]; }
1100 
1102 
1110  template <typename SourceAllocator>
1111  GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) {
1112  MemberIterator member = FindMember(name);
1113  if (member != MemberEnd())
1114  return member->value;
1115  else {
1116  RAPIDJSON_ASSERT(false); // see above note
1117 
1118  // This will generate -Wexit-time-destructors in clang
1119  // static GenericValue NullValue;
1120  // return NullValue;
1121 
1122  // Use static buffer and placement-new to prevent destruction
1123  static char buffer[sizeof(GenericValue)];
1124  return *new (buffer) GenericValue();
1125  }
1126  }
1127  template <typename SourceAllocator>
1128  const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
1129 
1130 #if RAPIDJSON_HAS_STDSTRING
1131  GenericValue& operator[](const std::basic_string<Ch>& name) { return (*this)[GenericValue(StringRef(name))]; }
1133  const GenericValue& operator[](const std::basic_string<Ch>& name) const { return (*this)[GenericValue(StringRef(name))]; }
1134 #endif
1135 
1137 
1138  ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer()); }
1140 
1141  ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer() + data_.o.size); }
1143 
1144  MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer()); }
1146 
1147  MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer() + data_.o.size); }
1148 
1150 
1157  bool HasMember(const Ch* name) const { return FindMember(name) != MemberEnd(); }
1158 
1159 #if RAPIDJSON_HAS_STDSTRING
1160 
1168  bool HasMember(const std::basic_string<Ch>& name) const { return FindMember(name) != MemberEnd(); }
1169 #endif
1170 
1172 
1180  template <typename SourceAllocator>
1181  bool HasMember(const GenericValue<Encoding, SourceAllocator>& name) const { return FindMember(name) != MemberEnd(); }
1182 
1184 
1195  MemberIterator FindMember(const Ch* name) {
1196  GenericValue n(StringRef(name));
1197  return FindMember(n);
1198  }
1199 
1200  ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
1201 
1203 
1215  template <typename SourceAllocator>
1216  MemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) {
1217  RAPIDJSON_ASSERT(IsObject());
1218  RAPIDJSON_ASSERT(name.IsString());
1219  MemberIterator member = MemberBegin();
1220  for ( ; member != MemberEnd(); ++member)
1221  if (name.StringEqual(member->name))
1222  break;
1223  return member;
1224  }
1225  template <typename SourceAllocator> ConstMemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
1226 
1227 #if RAPIDJSON_HAS_STDSTRING
1228 
1235  MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(GenericValue(StringRef(name))); }
1236  ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(GenericValue(StringRef(name))); }
1237 #endif
1238 
1240 
1249  GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) {
1250  RAPIDJSON_ASSERT(IsObject());
1251  RAPIDJSON_ASSERT(name.IsString());
1252 
1253  ObjectData& o = data_.o;
1254  if (o.size >= o.capacity) {
1255  if (o.capacity == 0) {
1256  o.capacity = kDefaultObjectCapacity;
1257  SetMembersPointer(reinterpret_cast<Member*>(allocator.Malloc(o.capacity * sizeof(Member))));
1258  }
1259  else {
1260  SizeType oldCapacity = o.capacity;
1261  o.capacity += (oldCapacity + 1) / 2; // grow by factor 1.5
1262  SetMembersPointer(reinterpret_cast<Member*>(allocator.Realloc(GetMembersPointer(), oldCapacity * sizeof(Member), o.capacity * sizeof(Member))));
1263  }
1264  }
1265  Member* members = GetMembersPointer();
1266  members[o.size].name.RawAssign(name);
1267  members[o.size].value.RawAssign(value);
1268  o.size++;
1269  return *this;
1270  }
1271 
1273 
1281  GenericValue& AddMember(GenericValue& name, StringRefType value, Allocator& allocator) {
1282  GenericValue v(value);
1283  return AddMember(name, v, allocator);
1284  }
1285 
1286 #if RAPIDJSON_HAS_STDSTRING
1287 
1296  GenericValue& AddMember(GenericValue& name, std::basic_string<Ch>& value, Allocator& allocator) {
1297  GenericValue v(value, allocator);
1298  return AddMember(name, v, allocator);
1299  }
1300 #endif
1301 
1303 
1319  template <typename T>
1320  RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1321  AddMember(GenericValue& name, T value, Allocator& allocator) {
1322  GenericValue v(value);
1323  return AddMember(name, v, allocator);
1324  }
1325 
1326 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1327  GenericValue& AddMember(GenericValue&& name, GenericValue&& value, Allocator& allocator) {
1328  return AddMember(name, value, allocator);
1329  }
1330  GenericValue& AddMember(GenericValue&& name, GenericValue& value, Allocator& allocator) {
1331  return AddMember(name, value, allocator);
1332  }
1333  GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) {
1334  return AddMember(name, value, allocator);
1335  }
1336  GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) {
1337  GenericValue n(name);
1338  return AddMember(n, value, allocator);
1339  }
1340 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1341 
1342 
1344 
1353  GenericValue& AddMember(StringRefType name, GenericValue& value, Allocator& allocator) {
1354  GenericValue n(name);
1355  return AddMember(n, value, allocator);
1356  }
1357 
1359 
1367  GenericValue& AddMember(StringRefType name, StringRefType value, Allocator& allocator) {
1368  GenericValue v(value);
1369  return AddMember(name, v, allocator);
1370  }
1371 
1373 
1389  template <typename T>
1390  RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1391  AddMember(StringRefType name, T value, Allocator& allocator) {
1392  GenericValue n(name);
1393  return AddMember(n, value, allocator);
1394  }
1395 
1397 
1400  void RemoveAllMembers() {
1401  RAPIDJSON_ASSERT(IsObject());
1402  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
1403  m->~Member();
1404  data_.o.size = 0;
1405  }
1406 
1408 
1415  bool RemoveMember(const Ch* name) {
1416  GenericValue n(StringRef(name));
1417  return RemoveMember(n);
1418  }
1419 
1420 #if RAPIDJSON_HAS_STDSTRING
1421  bool RemoveMember(const std::basic_string<Ch>& name) { return RemoveMember(GenericValue(StringRef(name))); }
1422 #endif
1423 
1424  template <typename SourceAllocator>
1425  bool RemoveMember(const GenericValue<Encoding, SourceAllocator>& name) {
1426  MemberIterator m = FindMember(name);
1427  if (m != MemberEnd()) {
1428  RemoveMember(m);
1429  return true;
1430  }
1431  else
1432  return false;
1433  }
1434 
1436 
1443  MemberIterator RemoveMember(MemberIterator m) {
1444  RAPIDJSON_ASSERT(IsObject());
1445  RAPIDJSON_ASSERT(data_.o.size > 0);
1446  RAPIDJSON_ASSERT(GetMembersPointer() != 0);
1447  RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd());
1448 
1449  MemberIterator last(GetMembersPointer() + (data_.o.size - 1));
1450  if (data_.o.size > 1 && m != last)
1451  *m = *last; // Move the last one to this place
1452  else
1453  m->~Member(); // Only one left, just destroy
1454  --data_.o.size;
1455  return m;
1456  }
1457 
1459 
1467  MemberIterator EraseMember(ConstMemberIterator pos) {
1468  return EraseMember(pos, pos +1);
1469  }
1470 
1472 
1480  MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) {
1481  RAPIDJSON_ASSERT(IsObject());
1482  RAPIDJSON_ASSERT(data_.o.size > 0);
1483  RAPIDJSON_ASSERT(GetMembersPointer() != 0);
1484  RAPIDJSON_ASSERT(first >= MemberBegin());
1485  RAPIDJSON_ASSERT(first <= last);
1486  RAPIDJSON_ASSERT(last <= MemberEnd());
1487 
1488  MemberIterator pos = MemberBegin() + (first - MemberBegin());
1489  for (MemberIterator itr = pos; itr != last; ++itr)
1490  itr->~Member();
1491  std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
1492  data_.o.size -= static_cast<SizeType>(last - first);
1493  return pos;
1494  }
1495 
1497 
1501  bool EraseMember(const Ch* name) {
1502  GenericValue n(StringRef(name));
1503  return EraseMember(n);
1504  }
1505 
1506 #if RAPIDJSON_HAS_STDSTRING
1507  bool EraseMember(const std::basic_string<Ch>& name) { return EraseMember(GenericValue(StringRef(name))); }
1508 #endif
1509 
1510  template <typename SourceAllocator>
1511  bool EraseMember(const GenericValue<Encoding, SourceAllocator>& name) {
1512  MemberIterator m = FindMember(name);
1513  if (m != MemberEnd()) {
1514  EraseMember(m);
1515  return true;
1516  }
1517  else
1518  return false;
1519  }
1520 
1521  Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
1522  ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
1523 
1525 
1527 
1528 
1530 
1531  GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
1532 
1534  SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
1535 
1537  SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; }
1538 
1540  bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
1541 
1543 
1546  void Clear() {
1547  RAPIDJSON_ASSERT(IsArray());
1548  GenericValue* e = GetElementsPointer();
1549  for (GenericValue* v = e; v != e + data_.a.size; ++v)
1550  v->~GenericValue();
1551  data_.a.size = 0;
1552  }
1553 
1555 
1559  GenericValue& operator[](SizeType index) {
1560  RAPIDJSON_ASSERT(IsArray());
1561  RAPIDJSON_ASSERT(index < data_.a.size);
1562  return GetElementsPointer()[index];
1563  }
1564  const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
1565 
1567 
1568  ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer(); }
1570 
1571  ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer() + data_.a.size; }
1573 
1574  ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
1576 
1577  ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
1578 
1580 
1585  GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
1586  RAPIDJSON_ASSERT(IsArray());
1587  if (newCapacity > data_.a.capacity) {
1588  SetElementsPointer(reinterpret_cast<GenericValue*>(allocator.Realloc(GetElementsPointer(), data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue))));
1589  data_.a.capacity = newCapacity;
1590  }
1591  return *this;
1592  }
1593 
1595 
1604  GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
1605  RAPIDJSON_ASSERT(IsArray());
1606  if (data_.a.size >= data_.a.capacity)
1607  Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1608  GetElementsPointer()[data_.a.size++].RawAssign(value);
1609  return *this;
1610  }
1611 
1612 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1613  GenericValue& PushBack(GenericValue&& value, Allocator& allocator) {
1614  return PushBack(value, allocator);
1615  }
1616 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1617 
1619 
1627  GenericValue& PushBack(StringRefType value, Allocator& allocator) {
1628  return (*this).template PushBack<StringRefType>(value, allocator);
1629  }
1630 
1632 
1648  template <typename T>
1649  RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1650  PushBack(T value, Allocator& allocator) {
1651  GenericValue v(value);
1652  return PushBack(v, allocator);
1653  }
1654 
1656 
1659  GenericValue& PopBack() {
1660  RAPIDJSON_ASSERT(IsArray());
1661  RAPIDJSON_ASSERT(!Empty());
1662  GetElementsPointer()[--data_.a.size].~GenericValue();
1663  return *this;
1664  }
1665 
1667 
1673  ValueIterator Erase(ConstValueIterator pos) {
1674  return Erase(pos, pos + 1);
1675  }
1676 
1678 
1685  ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) {
1686  RAPIDJSON_ASSERT(IsArray());
1687  RAPIDJSON_ASSERT(data_.a.size > 0);
1688  RAPIDJSON_ASSERT(GetElementsPointer() != 0);
1689  RAPIDJSON_ASSERT(first >= Begin());
1690  RAPIDJSON_ASSERT(first <= last);
1691  RAPIDJSON_ASSERT(last <= End());
1692  ValueIterator pos = Begin() + (first - Begin());
1693  for (ValueIterator itr = pos; itr != last; ++itr)
1694  itr->~GenericValue();
1695  std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
1696  data_.a.size -= static_cast<SizeType>(last - first);
1697  return pos;
1698  }
1699 
1700  Array GetArray() { RAPIDJSON_ASSERT(IsArray()); return Array(*this); }
1701  ConstArray GetArray() const { RAPIDJSON_ASSERT(IsArray()); return ConstArray(*this); }
1702 
1704 
1706 
1707 
1708  int GetInt() const { RAPIDJSON_ASSERT(data_.f.flags & kIntFlag); return data_.n.i.i; }
1709  unsigned GetUint() const { RAPIDJSON_ASSERT(data_.f.flags & kUintFlag); return data_.n.u.u; }
1710  int64_t GetInt64() const { RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag); return data_.n.i64; }
1711  uint64_t GetUint64() const { RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag); return data_.n.u64; }
1712 
1714 
1716  double GetDouble() const {
1717  RAPIDJSON_ASSERT(IsNumber());
1718  if ((data_.f.flags & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
1719  if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double
1720  if ((data_.f.flags & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
1721  if ((data_.f.flags & kInt64Flag) != 0) return static_cast<double>(data_.n.i64); // int64_t -> double (may lose precision)
1722  RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0); return static_cast<double>(data_.n.u64); // uint64_t -> double (may lose precision)
1723  }
1724 
1726 
1728  float GetFloat() const {
1729  return static_cast<float>(GetDouble());
1730  }
1731 
1732  GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
1733  GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
1734  GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
1735  GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
1736  GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
1737  GenericValue& SetFloat(float f) { this->~GenericValue(); new (this) GenericValue(static_cast<double>(f)); return *this; }
1738 
1740 
1742 
1743 
1744  const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1745 
1747 
1749  SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength()) : data_.s.length); }
1750 
1752 
1759  GenericValue& SetString(const Ch* s, SizeType length) { return SetString(StringRef(s, length)); }
1760 
1762 
1766  GenericValue& SetString(StringRefType s) { this->~GenericValue(); SetStringRaw(s); return *this; }
1767 
1769 
1776  GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { return SetString(StringRef(s, length), allocator); }
1777 
1779 
1784  GenericValue& SetString(const Ch* s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
1785 
1787 
1792  GenericValue& SetString(StringRefType s, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, allocator); return *this; }
1793 
1794 #if RAPIDJSON_HAS_STDSTRING
1795 
1802  GenericValue& SetString(const std::basic_string<Ch>& s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
1803 #endif
1804 
1806 
1808 
1809 
1811 
1814  template <typename T>
1815  bool Is() const { return internal::TypeHelper<ValueType, T>::Is(*this); }
1816 
1817  template <typename T>
1818  T Get() const { return internal::TypeHelper<ValueType, T>::Get(*this); }
1819 
1820  template <typename T>
1821  T Get() { return internal::TypeHelper<ValueType, T>::Get(*this); }
1822 
1823  template<typename T>
1824  ValueType& Set(const T& data) { return internal::TypeHelper<ValueType, T>::Set(*this, data); }
1825 
1826  template<typename T>
1827  ValueType& Set(const T& data, AllocatorType& allocator) { return internal::TypeHelper<ValueType, T>::Set(*this, data, allocator); }
1828 
1830 
1832 
1838  template <typename Handler>
1839  bool Accept(Handler& handler) const {
1840  switch(GetType()) {
1841  case kNullType: return handler.Null();
1842  case kFalseType: return handler.Bool(false);
1843  case kTrueType: return handler.Bool(true);
1844 
1845  case kObjectType:
1846  if (RAPIDJSON_UNLIKELY(!handler.StartObject()))
1847  return false;
1848  for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
1849  RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of name by MemberIterator.
1850  if (RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1851  return false;
1852  if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler)))
1853  return false;
1854  }
1855  return handler.EndObject(data_.o.size);
1856 
1857  case kArrayType:
1858  if (RAPIDJSON_UNLIKELY(!handler.StartArray()))
1859  return false;
1860  for (const GenericValue* v = Begin(); v != End(); ++v)
1861  if (RAPIDJSON_UNLIKELY(!v->Accept(handler)))
1862  return false;
1863  return handler.EndArray(data_.a.size);
1864 
1865  case kStringType:
1866  return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1867 
1868  default:
1869  RAPIDJSON_ASSERT(GetType() == kNumberType);
1870  if (IsDouble()) return handler.Double(data_.n.d);
1871  else if (IsInt()) return handler.Int(data_.n.i.i);
1872  else if (IsUint()) return handler.Uint(data_.n.u.u);
1873  else if (IsInt64()) return handler.Int64(data_.n.i64);
1874  else return handler.Uint64(data_.n.u64);
1875  }
1876  }
1877 
1878 private:
1879  template <typename, typename> friend class GenericValue;
1880  template <typename, typename, typename> friend class GenericDocument;
1881 
1882  enum {
1883  kBoolFlag = 0x0008,
1884  kNumberFlag = 0x0010,
1885  kIntFlag = 0x0020,
1886  kUintFlag = 0x0040,
1887  kInt64Flag = 0x0080,
1888  kUint64Flag = 0x0100,
1889  kDoubleFlag = 0x0200,
1890  kStringFlag = 0x0400,
1891  kCopyFlag = 0x0800,
1892  kInlineStrFlag = 0x1000,
1893 
1894  // Initial flags of different types.
1909 
1910  kTypeMask = 0x07
1911  };
1912 
1913  static const SizeType kDefaultArrayCapacity = 16;
1915 
1916  struct Flag {
1917 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1918  char payload[sizeof(SizeType) * 2 + 6]; // 2 x SizeType + lower 48-bit pointer
1919 #elif RAPIDJSON_64BIT
1920  char payload[sizeof(SizeType) * 2 + sizeof(void*) + 6]; // 6 padding bytes
1921 #else
1922  char payload[sizeof(SizeType) * 2 + sizeof(void*) + 2]; // 2 padding bytes
1923 #endif
1925  };
1926 
1927  struct String {
1930  const Ch* str;
1931  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1932 
1933  // implementation detail: ShortString can represent zero-terminated strings up to MaxSize chars
1934  // (excluding the terminating zero) and store a value to determine the length of the contained
1935  // string in the last character str[LenPos] by storing "MaxSize - length" there. If the string
1936  // to store has the maximal length of MaxSize then str[LenPos] will be 0 and therefore act as
1937  // the string terminator as well. For getting the string length back from that value just use
1938  // "MaxSize - str[LenPos]".
1939  // This allows to store 13-chars strings in 32-bit mode, 21-chars strings in 64-bit mode,
1940  // 13-chars strings for RAPIDJSON_48BITPOINTER_OPTIMIZATION=1 inline (for `UTF8`-encoded strings).
1941  struct ShortString {
1942  enum { MaxChars = sizeof(static_cast<Flag*>(0)->payload) / sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1943  Ch str[MaxChars];
1944 
1945  inline static bool Usable(SizeType len) { return (MaxSize >= len); }
1946  inline void SetLength(SizeType len) { str[LenPos] = static_cast<Ch>(MaxSize - len); }
1947  inline SizeType GetLength() const { return static_cast<SizeType>(MaxSize - str[LenPos]); }
1948  }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1949 
1950  // By using proper binary layout, retrieval of different integer types do not need conversions.
1951  union Number {
1952 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1953  struct I {
1954  int i;
1955  char padding[4];
1956  }i;
1957  struct U {
1958  unsigned u;
1959  char padding2[4];
1960  }u;
1961 #else
1962  struct I {
1963  char padding[4];
1964  int i;
1965  }i;
1966  struct U {
1967  char padding2[4];
1968  unsigned u;
1969  }u;
1970 #endif
1973  double d;
1974  }; // 8 bytes
1975 
1976  struct ObjectData {
1979  Member* members;
1980  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1981 
1982  struct ArrayData {
1986  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1987 
1988  union Data {
1995  }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION
1996 
1997  RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
1998  RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
1999  RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer() const { return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
2000  RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
2001  RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
2002  RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
2003 
2004  // Initialize this value as array with initial data, without calling destructor.
2005  void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
2006  data_.f.flags = kArrayFlag;
2007  if (count) {
2008  GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
2009  SetElementsPointer(e);
2010  std::memcpy(e, values, count * sizeof(GenericValue));
2011  }
2012  else
2013  SetElementsPointer(0);
2014  data_.a.size = data_.a.capacity = count;
2015  }
2016 
2018  void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
2019  data_.f.flags = kObjectFlag;
2020  if (count) {
2021  Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
2022  SetMembersPointer(m);
2023  std::memcpy(m, members, count * sizeof(Member));
2024  }
2025  else
2026  SetMembersPointer(0);
2027  data_.o.size = data_.o.capacity = count;
2028  }
2029 
2031  void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2032  data_.f.flags = kConstStringFlag;
2033  SetStringPointer(s);
2034  data_.s.length = s.length;
2035  }
2036 
2038  void SetStringRaw(StringRefType s, Allocator& allocator) {
2039  Ch* str = 0;
2040  if (ShortString::Usable(s.length)) {
2041  data_.f.flags = kShortStringFlag;
2042  data_.ss.SetLength(s.length);
2043  str = data_.ss.str;
2044  } else {
2045  data_.f.flags = kCopyStringFlag;
2046  data_.s.length = s.length;
2047  str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2048  SetStringPointer(str);
2049  }
2050  std::memcpy(str, s, s.length * sizeof(Ch));
2051  str[s.length] = '\0';
2052  }
2053 
2055  void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2056  data_ = rhs.data_;
2057  // data_.f.flags = rhs.data_.f.flags;
2058  rhs.data_.f.flags = kNullFlag;
2059  }
2060 
2061  template <typename SourceAllocator>
2063  RAPIDJSON_ASSERT(IsString());
2064  RAPIDJSON_ASSERT(rhs.IsString());
2065 
2066  const SizeType len1 = GetStringLength();
2067  const SizeType len2 = rhs.GetStringLength();
2068  if(len1 != len2) { return false; }
2069 
2070  const Ch* const str1 = GetString();
2071  const Ch* const str2 = rhs.GetString();
2072  if(str1 == str2) { return true; } // fast path for constant string
2073 
2074  return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
2075  }
2076 
2077  Data data_;
2078 };
2079 
2082 
2084 // GenericDocument
2085 
2087 
2094 template <typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
2095 class GenericDocument : public GenericValue<Encoding, Allocator> {
2096 public:
2097  typedef typename Encoding::Ch Ch;
2099  typedef Allocator AllocatorType;
2100 
2102 
2108  explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2109  GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2110  {
2111  if (!allocator_)
2112  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2113  }
2114 
2116 
2121  GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2122  allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2123  {
2124  if (!allocator_)
2125  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2126  }
2127 
2128 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2129  GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2131  : ValueType(std::forward<ValueType>(rhs)), // explicit cast to avoid prohibited move from Document
2132  allocator_(rhs.allocator_),
2133  ownAllocator_(rhs.ownAllocator_),
2134  stack_(std::move(rhs.stack_)),
2135  parseResult_(rhs.parseResult_)
2136  {
2137  rhs.allocator_ = 0;
2138  rhs.ownAllocator_ = 0;
2139  rhs.parseResult_ = ParseResult();
2140  }
2141 #endif
2142 
2144  Destroy();
2145  }
2146 
2147 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2148  GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2150  {
2151  // The cast to ValueType is necessary here, because otherwise it would
2152  // attempt to call GenericValue's templated assignment operator.
2153  ValueType::operator=(std::forward<ValueType>(rhs));
2154 
2155  // Calling the destructor here would prematurely call stack_'s destructor
2156  Destroy();
2157 
2158  allocator_ = rhs.allocator_;
2159  ownAllocator_ = rhs.ownAllocator_;
2160  stack_ = std::move(rhs.stack_);
2161  parseResult_ = rhs.parseResult_;
2162 
2163  rhs.allocator_ = 0;
2164  rhs.ownAllocator_ = 0;
2165  rhs.parseResult_ = ParseResult();
2166 
2167  return *this;
2168  }
2169 #endif
2170 
2172 
2177  GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT {
2178  ValueType::Swap(rhs);
2179  stack_.Swap(rhs.stack_);
2180  internal::Swap(allocator_, rhs.allocator_);
2181  internal::Swap(ownAllocator_, rhs.ownAllocator_);
2182  internal::Swap(parseResult_, rhs.parseResult_);
2183  return *this;
2184  }
2185 
2186  // Allow Swap with ValueType.
2187  // Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
2188  using ValueType::Swap;
2189 
2191 
2202  friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
2203 
2205 
2209  template <typename Generator>
2210  GenericDocument& Populate(Generator& g) {
2211  ClearStackOnExit scope(*this);
2212  if (g(*this)) {
2213  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2214  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2215  }
2216  return *this;
2217  }
2218 
2221 
2223 
2229  template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
2230  GenericDocument& ParseStream(InputStream& is) {
2232  stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2233  ClearStackOnExit scope(*this);
2234  parseResult_ = reader.template Parse<parseFlags>(is, *this);
2235  if (parseResult_) {
2236  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2237  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2238  }
2239  return *this;
2240  }
2241 
2243 
2248  template <unsigned parseFlags, typename InputStream>
2249  GenericDocument& ParseStream(InputStream& is) {
2250  return ParseStream<parseFlags, Encoding, InputStream>(is);
2251  }
2252 
2254 
2258  template <typename InputStream>
2259  GenericDocument& ParseStream(InputStream& is) {
2260  return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2261  }
2263 
2266 
2268 
2272  template <unsigned parseFlags>
2275  return ParseStream<parseFlags | kParseInsituFlag>(s);
2276  }
2277 
2279 
2283  return ParseInsitu<kParseDefaultFlags>(str);
2284  }
2286 
2289 
2291 
2295  template <unsigned parseFlags, typename SourceEncoding>
2296  GenericDocument& Parse(const typename SourceEncoding::Ch* str) {
2297  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2299  return ParseStream<parseFlags, SourceEncoding>(s);
2300  }
2301 
2303 
2306  template <unsigned parseFlags>
2307  GenericDocument& Parse(const Ch* str) {
2308  return Parse<parseFlags, Encoding>(str);
2309  }
2310 
2312 
2314  GenericDocument& Parse(const Ch* str) {
2315  return Parse<kParseDefaultFlags>(str);
2316  }
2317 
2318  template <unsigned parseFlags, typename SourceEncoding>
2319  GenericDocument& Parse(const typename SourceEncoding::Ch* str, size_t length) {
2320  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2321  MemoryStream ms(reinterpret_cast<const char*>(str), length * sizeof(typename SourceEncoding::Ch));
2323  ParseStream<parseFlags, SourceEncoding>(is);
2324  return *this;
2325  }
2326 
2327  template <unsigned parseFlags>
2328  GenericDocument& Parse(const Ch* str, size_t length) {
2329  return Parse<parseFlags, Encoding>(str, length);
2330  }
2331 
2332  GenericDocument& Parse(const Ch* str, size_t length) {
2333  return Parse<kParseDefaultFlags>(str, length);
2334  }
2335 
2336 #if RAPIDJSON_HAS_STDSTRING
2337  template <unsigned parseFlags, typename SourceEncoding>
2338  GenericDocument& Parse(const std::basic_string<typename SourceEncoding::Ch>& str) {
2339  // c_str() is constant complexity according to standard. Should be faster than Parse(const char*, size_t)
2340  return Parse<parseFlags, SourceEncoding>(str.c_str());
2341  }
2342 
2343  template <unsigned parseFlags>
2344  GenericDocument& Parse(const std::basic_string<Ch>& str) {
2345  return Parse<parseFlags, Encoding>(str.c_str());
2346  }
2347 
2348  GenericDocument& Parse(const std::basic_string<Ch>& str) {
2349  return Parse<kParseDefaultFlags>(str);
2350  }
2351 #endif // RAPIDJSON_HAS_STDSTRING
2352 
2354 
2357 
2359  bool HasParseError() const { return parseResult_.IsError(); }
2360 
2362  ParseErrorCode GetParseError() const { return parseResult_.Code(); }
2363 
2365  size_t GetErrorOffset() const { return parseResult_.Offset(); }
2366 
2368 #ifndef __clang // -Wdocumentation
2369 
2378 #endif
2379  operator ParseResult() const { return parseResult_; }
2381 
2383  Allocator& GetAllocator() {
2384  RAPIDJSON_ASSERT(allocator_);
2385  return *allocator_;
2386  }
2387 
2389  size_t GetStackCapacity() const { return stack_.GetCapacity(); }
2390 
2391 private:
2392  // clear stack on any exit from ParseStream, e.g. due to exception
2394  explicit ClearStackOnExit(GenericDocument& d) : d_(d) {}
2395  ~ClearStackOnExit() { d_.ClearStack(); }
2396  private:
2398  ClearStackOnExit& operator=(const ClearStackOnExit&);
2400  };
2401 
2402  // callers of the following private Handler functions
2403  // template <typename,typename,typename> friend class GenericReader; // for parsing
2404  template <typename, typename> friend class GenericValue; // for deep copying
2405 
2406 public:
2407  // Implementation of Handler
2408  bool Null() { new (stack_.template Push<ValueType>()) ValueType(); return true; }
2409  bool Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
2410  bool Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2411  bool Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2412  bool Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2413  bool Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2414  bool Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); return true; }
2415 
2416  bool RawNumber(const Ch* str, SizeType length, bool copy) {
2417  if (copy)
2418  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2419  else
2420  new (stack_.template Push<ValueType>()) ValueType(str, length);
2421  return true;
2422  }
2423 
2424  bool String(const Ch* str, SizeType length, bool copy) {
2425  if (copy)
2426  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2427  else
2428  new (stack_.template Push<ValueType>()) ValueType(str, length);
2429  return true;
2430  }
2431 
2432  bool StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); return true; }
2433 
2434  bool Key(const Ch* str, SizeType length, bool copy) { return String(str, length, copy); }
2435 
2436  bool EndObject(SizeType memberCount) {
2437  typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2438  stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2439  return true;
2440  }
2441 
2442  bool StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); return true; }
2443 
2444  bool EndArray(SizeType elementCount) {
2445  ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2446  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2447  return true;
2448  }
2449 
2450 private:
2455 
2456  void ClearStack() {
2457  if (Allocator::kNeedFree)
2458  while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
2459  (stack_.template Pop<ValueType>(1))->~ValueType();
2460  else
2461  stack_.Clear();
2462  stack_.ShrinkToFit();
2463  }
2464 
2465  void Destroy() {
2466  RAPIDJSON_DELETE(ownAllocator_);
2467  }
2468 
2469  static const size_t kDefaultStackCapacity = 1024;
2470  Allocator* allocator_;
2471  Allocator* ownAllocator_;
2474 };
2475 
2478 
2480 
2484 template <bool Const, typename ValueT>
2485 class GenericArray {
2486 public:
2489  typedef ValueT PlainType;
2491  typedef ValueType* ValueIterator; // This may be const or non-const iterator
2492  typedef const ValueT* ConstValueIterator;
2493  typedef typename ValueType::AllocatorType AllocatorType;
2494  typedef typename ValueType::StringRefType StringRefType;
2495 
2496  template <typename, typename>
2497  friend class GenericValue;
2498 
2499  GenericArray(const GenericArray& rhs) : value_(rhs.value_) {}
2500  GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; }
2502 
2503  SizeType Size() const { return value_.Size(); }
2504  SizeType Capacity() const { return value_.Capacity(); }
2505  bool Empty() const { return value_.Empty(); }
2506  void Clear() const { value_.Clear(); }
2507  ValueType& operator[](SizeType index) const { return value_[index]; }
2508  ValueIterator Begin() const { return value_.Begin(); }
2509  ValueIterator End() const { return value_.End(); }
2510  GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const { value_.Reserve(newCapacity, allocator); return *this; }
2511  GenericArray PushBack(ValueType& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2512 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2513  GenericArray PushBack(ValueType&& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2514 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2515  GenericArray PushBack(StringRefType value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2516  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (const GenericArray&)) PushBack(T value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2517  GenericArray PopBack() const { value_.PopBack(); return *this; }
2518  ValueIterator Erase(ConstValueIterator pos) const { return value_.Erase(pos); }
2519  ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const { return value_.Erase(first, last); }
2520 
2521 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2522  ValueIterator begin() const { return value_.Begin(); }
2523  ValueIterator end() const { return value_.End(); }
2524 #endif
2525 
2526 private:
2527  GenericArray();
2528  GenericArray(ValueType& value) : value_(value) {}
2529  ValueType& value_;
2530 };
2531 
2533 
2537 template <bool Const, typename ValueT>
2538 class GenericObject {
2539 public:
2542  typedef ValueT PlainType;
2546  typedef typename ValueType::AllocatorType AllocatorType;
2547  typedef typename ValueType::StringRefType StringRefType;
2548  typedef typename ValueType::EncodingType EncodingType;
2549  typedef typename ValueType::Ch Ch;
2550 
2551  template <typename, typename>
2552  friend class GenericValue;
2553 
2554  GenericObject(const GenericObject& rhs) : value_(rhs.value_) {}
2555  GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; }
2557 
2558  SizeType MemberCount() const { return value_.MemberCount(); }
2559  bool ObjectEmpty() const { return value_.ObjectEmpty(); }
2560  template <typename T> ValueType& operator[](T* name) const { return value_[name]; }
2561  template <typename SourceAllocator> ValueType& operator[](const GenericValue<EncodingType, SourceAllocator>& name) const { return value_[name]; }
2562 #if RAPIDJSON_HAS_STDSTRING
2563  ValueType& operator[](const std::basic_string<Ch>& name) const { return value_[name]; }
2564 #endif
2565  MemberIterator MemberBegin() const { return value_.MemberBegin(); }
2566  MemberIterator MemberEnd() const { return value_.MemberEnd(); }
2567  bool HasMember(const Ch* name) const { return value_.HasMember(name); }
2568 #if RAPIDJSON_HAS_STDSTRING
2569  bool HasMember(const std::basic_string<Ch>& name) const { return value_.HasMember(name); }
2570 #endif
2571  template <typename SourceAllocator> bool HasMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.HasMember(name); }
2572  MemberIterator FindMember(const Ch* name) const { return value_.FindMember(name); }
2573  template <typename SourceAllocator> MemberIterator FindMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.FindMember(name); }
2574 #if RAPIDJSON_HAS_STDSTRING
2575  MemberIterator FindMember(const std::basic_string<Ch>& name) const { return value_.FindMember(name); }
2576 #endif
2577  GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2578  GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2579 #if RAPIDJSON_HAS_STDSTRING
2580  GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2581 #endif
2582  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&)) AddMember(ValueType& name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2583 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2584  GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2585  GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2586  GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2587  GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2588 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2589  GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2590  GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2591  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericObject)) AddMember(StringRefType name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2592  void RemoveAllMembers() { value_.RemoveAllMembers(); }
2593  bool RemoveMember(const Ch* name) const { return value_.RemoveMember(name); }
2594 #if RAPIDJSON_HAS_STDSTRING
2595  bool RemoveMember(const std::basic_string<Ch>& name) const { return value_.RemoveMember(name); }
2596 #endif
2597  template <typename SourceAllocator> bool RemoveMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.RemoveMember(name); }
2598  MemberIterator RemoveMember(MemberIterator m) const { return value_.RemoveMember(m); }
2599  MemberIterator EraseMember(ConstMemberIterator pos) const { return value_.EraseMember(pos); }
2600  MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const { return value_.EraseMember(first, last); }
2601  bool EraseMember(const Ch* name) const { return value_.EraseMember(name); }
2602 #if RAPIDJSON_HAS_STDSTRING
2603  bool EraseMember(const std::basic_string<Ch>& name) const { return EraseMember(ValueType(StringRef(name))); }
2604 #endif
2605  template <typename SourceAllocator> bool EraseMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.EraseMember(name); }
2606 
2607 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2608  MemberIterator begin() const { return value_.MemberBegin(); }
2609  MemberIterator end() const { return value_.MemberEnd(); }
2610 #endif
2611 
2612 private:
2613  GenericObject();
2614  GenericObject(ValueType& value) : value_(value) {}
2615  ValueType& value_;
2616 };
2617 
2619 #ifdef _MINWINDEF_ // see: http://stackoverflow.com/questions/22744262/cant-call-stdmax-because-minwindef-h-defines-max
2620 #ifndef NOMINMAX
2621 #pragma pop_macro("min")
2622 #pragma pop_macro("max")
2623 #endif
2624 #endif
2625 RAPIDJSON_DIAG_POP
2626 
2627 #endif // RAPIDJSON_DOCUMENT_H_
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:693
bool RemoveMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2597
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:139
void SetLength(SizeType len)
Definition: document.h:1946
ValueT PlainType
Definition: document.h:2542
d
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:744
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:80
bool Empty() const
Definition: document.h:2505
void Clear() const
Definition: document.h:2506
RAPIDJSON_FORCEINLINE const Ch * GetStringPointer() const
Definition: document.h:1997
Iterator operator--(int)
Definition: document.h:165
SizeType NotNullStrLen(const CharType *str)
Definition: document.h:334
GenericObject(ValueType &value)
Definition: document.h:2614
bool EndArray(SizeType elementCount)
Definition: document.h:2444
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:2099
SizeType GetLength() const
Definition: document.h:1947
GenericStringRef(const GenericStringRef &rhs)
Definition: document.h:325
GenericArray PushBack(StringRefType value, AllocatorType &allocator) const
Definition: document.h:2515
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2098
GenericObject AddMember(StringRefType name, ValueType &value, AllocatorType &allocator) const
Definition: document.h:2589
static ValueType & Set(ValueType &v, uint64_t data)
Definition: document.h:468
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
Represents an in-memory input byte stream.
Definition: memorystream.h:40
GenericObject AddMember(ValueType &name, ValueType &value, AllocatorType &allocator) const
Definition: document.h:2577
bool String(const Ch *str, SizeType length, bool copy)
Definition: document.h:2424
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition: document.h:773
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
ValueType::EncodingType EncodingType
Definition: document.h:2548
static bool Is(const ValueType &v)
Definition: document.h:474
BaseType::pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:129
ClearStackOnExit(GenericDocument &d)
Definition: document.h:2394
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:294
GenericArray< true, ValueT > ConstArray
Definition: document.h:2487
object
Definition: rapidjson.h:620
static bool Get(const ValueType &v)
Definition: document.h:435
Pointer ptr_
raw pointer
Definition: document.h:201
f
Helper class for accessing Value of array type.
Definition: document.h:542
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:611
bool StringEqual(const GenericValue< Encoding, SourceAllocator > &rhs) const
Definition: document.h:2062
Read-only string stream.
Definition: fwd.h:47
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2202
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition: document.h:735
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:81
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition: document.h:2210
(Constant) member iterator for a JSON object value
Definition: document.h:109
const Ch *const s
plain CharType pointer
Definition: document.h:330
array
Definition: rapidjson.h:621
static ValueType & Set(ValueType &v, ObjectType data)
Definition: document.h:528
GenericArray PopBack() const
Definition: document.h:2517
static ValueType & Set(ValueType &v, ArrayType data)
Definition: document.h:512
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:122
GenericMemberIterator(Pointer p)
Internal constructor from plain pointer.
Definition: document.h:199
ValueType & operator[](SizeType index) const
Definition: document.h:2507
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition: document.h:2000
XmlRpcServer s
GenericDocument & Parse(const Ch *str, size_t length)
Definition: document.h:2332
GenericDocument & Parse(const Ch *str, size_t length)
Definition: document.h:2328
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:2097
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:2249
ValueType::StringRefType StringRefType
Definition: document.h:2494
internal::Stack< StackAllocator > stack_
Definition: document.h:2472
MemberIterator MemberEnd() const
Definition: document.h:2566
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:67
bool Bool(bool b)
Definition: document.h:2409
std::iterator< std::random_access_iterator_tag, ValueType > BaseType
Definition: document.h:118
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:450
static bool Is(const ValueType &v)
Definition: document.h:466
ValueIterator Erase(ConstValueIterator pos) const
Definition: document.h:2518
bool operator!=(ConstIterator that) const
Definition: document.h:180
bool ObjectEmpty() const
Definition: document.h:2559
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:2362
unsigned short uint16_t
Definition: stdint.h:125
static ValueType & Set(ValueType &v, double data, typename ValueType::AllocatorType &)
Definition: document.h:477
GenericArray PushBack(ValueType &value, AllocatorType &allocator) const
Definition: document.h:2511
false
Definition: rapidjson.h:618
static bool Is(const ValueType &v)
Definition: document.h:434
static ValueType & Set(ValueType &v, bool data)
Definition: document.h:436
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:747
bool EraseMember(const Ch *name) const
Definition: document.h:2601
ValueType & operator[](T *name) const
Definition: document.h:2560
SizeType Capacity() const
Definition: document.h:2504
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:124
MemberIterator FindMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2573
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator)
Definition: document.h:2005
MemberIterator MemberBegin() const
Definition: document.h:2565
static ValueType & Set(ValueType &v, ArrayType data, typename ValueType::AllocatorType &)
Definition: document.h:513
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:570
friend class GenericDocument
Definition: document.h:1880
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:563
bool operator<(ConstIterator that) const
Definition: document.h:183
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:2259
Pointer operator->() const
Definition: document.h:190
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:117
static unsigned Get(const ValueType &v)
Definition: document.h:451
GenericArray(const GenericArray &rhs)
Definition: document.h:2499
bool StartObject()
Definition: document.h:2432
ValueType::StringRefType StringRefType
Definition: document.h:2547
bool StartArray()
Definition: document.h:2442
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:562
A document for parsing JSON text as DOM.
Definition: document.h:70
bool HasMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2571
void RemoveAllMembers()
Definition: document.h:2592
static bool Is(const ValueType &v)
Definition: document.h:442
ShortString ss
Definition: document.h:1990
A read-write string stream.
Definition: fwd.h:52
GenericArray & operator=(const GenericArray &rhs)
Definition: document.h:2500
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:705
bool operator==(ConstIterator that) const
Definition: document.h:179
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:738
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2108
static ValueType & Set(ValueType &v, double data)
Definition: document.h:476
Iterator & operator--()
Definition: document.h:163
bool HasMember(const Ch *name) const
Definition: document.h:2567
GenericMemberIterator< true, typename ValueT::EncodingType, typename ValueT::AllocatorType > ConstMemberIterator
Definition: document.h:2545
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:564
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:599
ValueT PlainType
Definition: document.h:2489
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2121
GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:682
Reference operator[](DifferenceType n) const
Definition: document.h:191
bool EndObject(SizeType memberCount)
Definition: document.h:2436
ObjectData o
Definition: document.h:1992
string
Definition: rapidjson.h:622
Allocator * ownAllocator_
Definition: document.h:2471
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: fwd.h:88
GenericArray(ValueType &value)
Definition: document.h:2528
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:565
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:310
ParseResult parseResult_
Definition: document.h:2473
static ValueType & Set(ValueType &v, ObjectType data, typename ValueType::AllocatorType &)
Definition: document.h:529
static bool Is(const ValueType &v)
Definition: document.h:458
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2081
bool Double(double d)
Definition: document.h:2414
static ValueType & Set(ValueType &v, float data, typename ValueType::AllocatorType &)
Definition: document.h:485
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:568
ParseErrorCode
Error code of parsing.
Definition: error.h:64
bool RawNumber(const Ch *str, SizeType length, bool copy)
Definition: document.h:2416
RAPIDJSON_FORCEINLINE GenericValue * GetElementsPointer() const
Definition: document.h:1999
Helper class for accessing Value of object type.
Definition: document.h:543
GenericObject< true, ValueT > ConstObject
Definition: document.h:2540
static ValueType & Set(ValueType &v, float data)
Definition: document.h:484
Iterator & operator++()
Definition: document.h:162
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:1998
bool operator<=(ConstIterator that) const
Definition: document.h:181
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:2273
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:286
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:566
bool Int(int i)
Definition: document.h:2410
GenericObject(const GenericObject &rhs)
Definition: document.h:2554
unsigned __int64 uint64_t
Definition: stdint.h:136
ValueType::AllocatorType AllocatorType
Definition: document.h:2546
bool operator>(ConstIterator that) const
Definition: document.h:184
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2383
static bool Usable(SizeType len)
Definition: document.h:1945
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2477
Iterator operator++(int)
Definition: document.h:164
Input byte stream wrapper with a statically bound encoding.
Definition: encodedstream.h:39
GenericArray< false, ValueType > Array
Definition: document.h:572
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:571
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:2543
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition: document.h:331
number
Definition: rapidjson.h:623
const ValueT * ConstValueIterator
Definition: document.h:2492
ValueIterator Begin() const
Definition: document.h:2508
Name-value pair in a JSON object value.
Definition: document.h:79
bool Int64(int64_t i)
Definition: document.h:2412
ValueType * ValueIterator
Definition: document.h:2491
SizeType hashcode
reserved
Definition: document.h:1929
Iterator & operator+=(DifferenceType n)
Definition: document.h:173
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
GenericArray< true, ValueType > ConstArray
Definition: document.h:573
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:603
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2296
ValueIterator End() const
Definition: document.h:2509
static ValueType & Set(ValueType &v, unsigned data)
Definition: document.h:452
~GenericValue()
Destructor.
Definition: document.h:781
static int Get(const ValueType &v)
Definition: document.h:443
GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType &allocator) const
Definition: document.h:2590
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:2282
GenericObject< false, ValueT > Object
Definition: document.h:2541
SizeType MemberCount() const
Definition: document.h:2558
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:323
static ValueType & Set(ValueType &v, unsigned data, typename ValueType::AllocatorType &)
Definition: document.h:453
MemberIterator FindMember(const Ch *name) const
Definition: document.h:2572
void SetObjectRaw(Member *members, SizeType count, Allocator &allocator)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:2018
CharType Ch
character type of the string
Definition: document.h:258
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:468
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:195
static bool Is(const ValueType &v)
Definition: document.h:482
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition: document.h:2002
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1121
MemberIterator RemoveMember(MemberIterator m) const
Definition: document.h:2598
RAPIDJSON_FORCEINLINE Member * GetMembersPointer() const
Definition: document.h:2001
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:365
GenericMember< Encoding, Allocator > PlainType
Definition: document.h:116
Reference operator*() const
Definition: document.h:189
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:567
#define T(x)
Iterator & operator=(const NonConstIterator &it)
Definition: document.h:158
MemberIterator EraseMember(ConstMemberIterator pos) const
Definition: document.h:2599
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const
Definition: document.h:2519
void SetStringRaw(StringRefType s, Allocator &allocator)
Initialize this value as copy string with initial data, without calling destructor.
Definition: document.h:2038
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:2365
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:2490
bool operator>=(ConstIterator that) const
Definition: document.h:182
GenericDocument & Parse(const typename SourceEncoding::Ch *str, size_t length)
Definition: document.h:2319
static int64_t Get(const ValueType &v)
Definition: document.h:459
ValueType::AllocatorType AllocatorType
Definition: document.h:2493
GenericObject< true, ValueType > ConstObject
Definition: document.h:575
signed __int64 int64_t
Definition: stdint.h:135
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2031
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:699
static ValueType & Set(ValueType &v, int64_t data)
Definition: document.h:460
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:324
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:720
Iterator operator-(DifferenceType n) const
Definition: document.h:171
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:569
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:741
static const SizeType kDefaultObjectCapacity
Definition: document.h:1914
GenericObject< false, ValueType > Object
Definition: document.h:574
bool Uint64(uint64_t i)
Definition: document.h:2413
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:2307
true
Definition: rapidjson.h:619
static const SizeType kDefaultArrayCapacity
Definition: document.h:1913
GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const
Definition: document.h:2510
ValueType::Ch Ch
Definition: document.h:2549
static float Get(const ValueType &v)
Definition: document.h:483
bool Uint(unsigned i)
Definition: document.h:2411
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
static ValueType & Set(ValueType &v, const StringType data)
Definition: document.h:493
Reference to a constant string (not taking a copy)
Definition: document.h:257
void ClearStack()
Definition: document.h:2456
BaseType::difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:133
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:126
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:157
static ValueType & Set(ValueType &v, int data)
Definition: document.h:444
bool EraseMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2605
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1121
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:581
static double Get(const ValueType &v)
Definition: document.h:475
Iterator operator+(DifferenceType n) const
Definition: document.h:170
ValueType & operator[](const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2561
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:732
SizeType Size() const
Definition: document.h:2503
Allocator * allocator_
Definition: document.h:2470
GenericArray< false, ValueT > Array
Definition: document.h:2488
bool RemoveMember(const Ch *name) const
Definition: document.h:2593
Type
Type of JSON value.
Definition: rapidjson.h:616
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:836
ValueType & value_
Definition: document.h:2615
BaseType::reference Reference
Reference to (const) GenericMember.
Definition: document.h:131
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:2314
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:322
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition: document.h:2055
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:481
GenericObject & operator=(const GenericObject &rhs)
Definition: document.h:2555
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const
Definition: document.h:2600
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2177
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T2 >, internal::IsGenericValue< T2 > >),(typename T::ValueType &)) GetValueByPointerWithDefault(T &root
static ValueType & Set(ValueType &v, uint64_t data, typename ValueType::AllocatorType &)
Definition: document.h:469
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:2389
ValueType & value_
Definition: document.h:2529
GenericObject AddMember(ValueType &name, StringRefType value, AllocatorType &allocator) const
Definition: document.h:2578
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition: document.h:633
GenericValue * elements
Definition: document.h:1985
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:817
static ValueType & Set(ValueType &v, int data, typename ValueType::AllocatorType &)
Definition: document.h:445
static ValueType & Set(ValueType &v, int64_t data, typename ValueType::AllocatorType &)
Definition: document.h:461
In-situ(destructive) parsing.
Definition: reader.h:149
static bool Is(const ValueType &v)
Definition: document.h:450
void Destroy()
Definition: document.h:2465
Iterator & operator-=(DifferenceType n)
Definition: document.h:174
static uint64_t Get(const ValueType &v)
Definition: document.h:467
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition: document.h:2359
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:2230
static ValueType & Set(ValueType &v, const StringType data, typename ValueType::AllocatorType &a)
Definition: document.h:494
null
Definition: rapidjson.h:617
GenericMemberIterator< Const, typename ValueT::EncodingType, typename ValueT::AllocatorType > MemberIterator
Definition: document.h:2544
static ValueType & Set(ValueType &v, bool data, typename ValueType::AllocatorType &)
Definition: document.h:437
bool Key(const Ch *str, SizeType length, bool copy)
Definition: document.h:2434
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition: document.h:762


choreo_rapidjson
Author(s):
autogenerated on Thu Jul 18 2019 03:59:09