Electroneum
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 __clang__
30 RAPIDJSON_DIAG_OFF(padded)
31 RAPIDJSON_DIAG_OFF(switch-enum)
32 RAPIDJSON_DIAG_OFF(c++98-compat)
33 #elif defined(_MSC_VER)
34 RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
35 RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
36 #endif
37 
38 #ifdef __GNUC__
39 RAPIDJSON_DIAG_OFF(effc++)
40 #if __GNUC__ >= 6
41 RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_NOEXCEPT functions
42 #endif
43 #endif // __GNUC__
44 
45 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
46 #include <iterator> // std::random_access_iterator_tag
47 #endif
48 
49 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
50 #include <utility> // std::move
51 #endif
52 
54 
55 // Forward declaration.
56 template <typename Encoding, typename Allocator>
57 class GenericValue;
58 
59 template <typename Encoding, typename Allocator, typename StackAllocator>
60 class GenericDocument;
61 
63 
68 template <typename Encoding, typename Allocator>
69 struct GenericMember {
72 };
73 
75 // GenericMemberIterator
76 
77 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
78 
80 
98 template <bool Const, typename Encoding, typename Allocator>
100 
101  friend class GenericValue<Encoding,Allocator>;
102  template <bool, typename, typename> friend class GenericMemberIterator;
103 
105  typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
106 
107 public:
114 
117  typedef ValueType value_type;
118  typedef ValueType * pointer;
119  typedef ValueType & reference;
120  typedef std::ptrdiff_t difference_type;
121  typedef std::random_access_iterator_tag iterator_category;
123 
125  typedef pointer Pointer;
130 
132 
135  GenericMemberIterator() : ptr_() {}
136 
138 
153  GenericMemberIterator(const NonConstIterator & it) : ptr_(it.ptr_) {}
154  Iterator& operator=(const NonConstIterator & it) { ptr_ = it.ptr_; return *this; }
155 
157 
158  Iterator& operator++(){ ++ptr_; return *this; }
159  Iterator& operator--(){ --ptr_; return *this; }
160  Iterator operator++(int){ Iterator old(*this); ++ptr_; return old; }
161  Iterator operator--(int){ Iterator old(*this); --ptr_; return old; }
163 
165 
166  Iterator operator+(DifferenceType n) const { return Iterator(ptr_+n); }
167  Iterator operator-(DifferenceType n) const { return Iterator(ptr_-n); }
168 
169  Iterator& operator+=(DifferenceType n) { ptr_+=n; return *this; }
170  Iterator& operator-=(DifferenceType n) { ptr_-=n; return *this; }
172 
174 
175  bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
176  bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
177  bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
178  bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
179  bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; }
180  bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; }
182 
184 
185  Reference operator*() const { return *ptr_; }
186  Pointer operator->() const { return ptr_; }
187  Reference operator[](DifferenceType n) const { return ptr_[n]; }
189 
191  DifferenceType operator-(ConstIterator that) const { return ptr_-that.ptr_; }
192 
193 private:
195  explicit GenericMemberIterator(Pointer p) : ptr_(p) {}
196 
197  Pointer ptr_;
198 };
199 
200 #else // RAPIDJSON_NOMEMBERITERATORCLASS
201 
202 // class-based member iterator implementation disabled, use plain pointers
203 
204 template <bool Const, typename Encoding, typename Allocator>
205 struct GenericMemberIterator;
206 
208 template <typename Encoding, typename Allocator>
212 };
214 template <typename Encoding, typename Allocator>
218 };
219 
220 #endif // RAPIDJSON_NOMEMBERITERATORCLASS
221 
223 // GenericStringRef
224 
226 
252 template<typename CharType>
254  typedef CharType Ch;
255 
257 #ifndef __clang__ // -Wdocumentation
280 #endif
281  template<SizeType N>
282  GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
283  : s(str), length(N-1) {}
284 
286 #ifndef __clang__ // -Wdocumentation
305 #endif
306  explicit GenericStringRef(const CharType* str)
307  : s(str), length(NotNullStrLen(str)) {}
308 
310 #ifndef __clang__ // -Wdocumentation
317 #endif
318  GenericStringRef(const CharType* str, SizeType len)
319  : s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) { RAPIDJSON_ASSERT(str != 0 || len == 0u); }
320 
321  GenericStringRef(const GenericStringRef& rhs) : s(rhs.s), length(rhs.length) {}
322 
324  operator const Ch *() const { return s; }
325 
326  const Ch* const s;
327  const SizeType length;
328 
329 private:
330  SizeType NotNullStrLen(const CharType* str) {
331  RAPIDJSON_ASSERT(str != 0);
332  return internal::StrLen(str);
333  }
334 
336  static const Ch emptyString[];
337 
339  template<SizeType N>
340  GenericStringRef(CharType (&str)[N]) /* = delete */;
342  GenericStringRef& operator=(const GenericStringRef& rhs) /* = delete */;
343 };
344 
345 template<typename CharType>
346 const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
347 
349 
360 template<typename CharType>
361 inline GenericStringRef<CharType> StringRef(const CharType* str) {
362  return GenericStringRef<CharType>(str);
363 }
364 
366 
380 template<typename CharType>
381 inline GenericStringRef<CharType> StringRef(const CharType* str, size_t length) {
382  return GenericStringRef<CharType>(str, SizeType(length));
383 }
384 
385 #if RAPIDJSON_HAS_STDSTRING
387 
398 template<typename CharType>
399 inline GenericStringRef<CharType> StringRef(const std::basic_string<CharType>& str) {
400  return GenericStringRef<CharType>(str.data(), SizeType(str.size()));
401 }
402 #endif
403 
405 // GenericValue type traits
406 namespace internal {
407 
408 template <typename T, typename Encoding = void, typename Allocator = void>
409 struct IsGenericValueImpl : FalseType {};
410 
411 // select candidates according to nested encoding and allocator types
412 template <typename T> struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
413  : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
414 
415 // helper to match arbitrary GenericValue instantiations, including derived classes
416 template <typename T> struct IsGenericValue : IsGenericValueImpl<T>::Type {};
417 
418 } // namespace internal
419 
421 // TypeHelper
422 
423 namespace internal {
424 
425 template <typename ValueType, typename T>
426 struct TypeHelper {};
427 
428 template<typename ValueType>
429 struct TypeHelper<ValueType, bool> {
430  static bool Is(const ValueType& v) { return v.IsBool(); }
431  static bool Get(const ValueType& v) { return v.GetBool(); }
432  static ValueType& Set(ValueType& v, bool data) { return v.SetBool(data); }
433  static ValueType& Set(ValueType& v, bool data, typename ValueType::AllocatorType&) { return v.SetBool(data); }
434 };
435 
436 template<typename ValueType>
437 struct TypeHelper<ValueType, int> {
438  static bool Is(const ValueType& v) { return v.IsInt(); }
439  static int Get(const ValueType& v) { return v.GetInt(); }
440  static ValueType& Set(ValueType& v, int data) { return v.SetInt(data); }
441  static ValueType& Set(ValueType& v, int data, typename ValueType::AllocatorType&) { return v.SetInt(data); }
442 };
443 
444 template<typename ValueType>
445 struct TypeHelper<ValueType, unsigned> {
446  static bool Is(const ValueType& v) { return v.IsUint(); }
447  static unsigned Get(const ValueType& v) { return v.GetUint(); }
448  static ValueType& Set(ValueType& v, unsigned data) { return v.SetUint(data); }
449  static ValueType& Set(ValueType& v, unsigned data, typename ValueType::AllocatorType&) { return v.SetUint(data); }
450 };
451 
452 #ifdef _MSC_VER
453 RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int));
454 template<typename ValueType>
455 struct TypeHelper<ValueType, long> {
456  static bool Is(const ValueType& v) { return v.IsInt(); }
457  static long Get(const ValueType& v) { return v.GetInt(); }
458  static ValueType& Set(ValueType& v, long data) { return v.SetInt(data); }
459  static ValueType& Set(ValueType& v, long data, typename ValueType::AllocatorType&) { return v.SetInt(data); }
460 };
461 
462 RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned));
463 template<typename ValueType>
464 struct TypeHelper<ValueType, unsigned long> {
465  static bool Is(const ValueType& v) { return v.IsUint(); }
466  static unsigned long Get(const ValueType& v) { return v.GetUint(); }
467  static ValueType& Set(ValueType& v, unsigned long data) { return v.SetUint(data); }
468  static ValueType& Set(ValueType& v, unsigned long data, typename ValueType::AllocatorType&) { return v.SetUint(data); }
469 };
470 #endif
471 
472 template<typename ValueType>
473 struct TypeHelper<ValueType, int64_t> {
474  static bool Is(const ValueType& v) { return v.IsInt64(); }
475  static int64_t Get(const ValueType& v) { return v.GetInt64(); }
476  static ValueType& Set(ValueType& v, int64_t data) { return v.SetInt64(data); }
477  static ValueType& Set(ValueType& v, int64_t data, typename ValueType::AllocatorType&) { return v.SetInt64(data); }
478 };
479 
480 template<typename ValueType>
481 struct TypeHelper<ValueType, uint64_t> {
482  static bool Is(const ValueType& v) { return v.IsUint64(); }
483  static uint64_t Get(const ValueType& v) { return v.GetUint64(); }
484  static ValueType& Set(ValueType& v, uint64_t data) { return v.SetUint64(data); }
485  static ValueType& Set(ValueType& v, uint64_t data, typename ValueType::AllocatorType&) { return v.SetUint64(data); }
486 };
487 
488 template<typename ValueType>
489 struct TypeHelper<ValueType, double> {
490  static bool Is(const ValueType& v) { return v.IsDouble(); }
491  static double Get(const ValueType& v) { return v.GetDouble(); }
492  static ValueType& Set(ValueType& v, double data) { return v.SetDouble(data); }
493  static ValueType& Set(ValueType& v, double data, typename ValueType::AllocatorType&) { return v.SetDouble(data); }
494 };
495 
496 template<typename ValueType>
497 struct TypeHelper<ValueType, float> {
498  static bool Is(const ValueType& v) { return v.IsFloat(); }
499  static float Get(const ValueType& v) { return v.GetFloat(); }
500  static ValueType& Set(ValueType& v, float data) { return v.SetFloat(data); }
501  static ValueType& Set(ValueType& v, float data, typename ValueType::AllocatorType&) { return v.SetFloat(data); }
502 };
503 
504 template<typename ValueType>
505 struct TypeHelper<ValueType, const typename ValueType::Ch*> {
506  typedef const typename ValueType::Ch* StringType;
507  static bool Is(const ValueType& v) { return v.IsString(); }
508  static StringType Get(const ValueType& v) { return v.GetString(); }
509  static ValueType& Set(ValueType& v, const StringType data) { return v.SetString(typename ValueType::StringRefType(data)); }
510  static ValueType& Set(ValueType& v, const StringType data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
511 };
512 
513 #if RAPIDJSON_HAS_STDSTRING
514 template<typename ValueType>
515 struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
516  typedef std::basic_string<typename ValueType::Ch> StringType;
517  static bool Is(const ValueType& v) { return v.IsString(); }
518  static StringType Get(const ValueType& v) { return StringType(v.GetString(), v.GetStringLength()); }
519  static ValueType& Set(ValueType& v, const StringType& data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
520 };
521 #endif
522 
523 template<typename ValueType>
524 struct TypeHelper<ValueType, typename ValueType::Array> {
525  typedef typename ValueType::Array ArrayType;
526  static bool Is(const ValueType& v) { return v.IsArray(); }
527  static ArrayType Get(ValueType& v) { return v.GetArray(); }
528  static ValueType& Set(ValueType& v, ArrayType data) { return v = data; }
529  static ValueType& Set(ValueType& v, ArrayType data, typename ValueType::AllocatorType&) { return v = data; }
530 };
531 
532 template<typename ValueType>
533 struct TypeHelper<ValueType, typename ValueType::ConstArray> {
534  typedef typename ValueType::ConstArray ArrayType;
535  static bool Is(const ValueType& v) { return v.IsArray(); }
536  static ArrayType Get(const ValueType& v) { return v.GetArray(); }
537 };
538 
539 template<typename ValueType>
540 struct TypeHelper<ValueType, typename ValueType::Object> {
541  typedef typename ValueType::Object ObjectType;
542  static bool Is(const ValueType& v) { return v.IsObject(); }
543  static ObjectType Get(ValueType& v) { return v.GetObject(); }
544  static ValueType& Set(ValueType& v, ObjectType data) { return v = data; }
545  static ValueType& Set(ValueType& v, ObjectType data, typename ValueType::AllocatorType&) { return v = data; }
546 };
547 
548 template<typename ValueType>
549 struct TypeHelper<ValueType, typename ValueType::ConstObject> {
550  typedef typename ValueType::ConstObject ObjectType;
551  static bool Is(const ValueType& v) { return v.IsObject(); }
552  static ObjectType Get(const ValueType& v) { return v.GetObject(); }
553 };
554 
555 } // namespace internal
556 
557 // Forward declarations
558 template <bool, typename> class GenericArray;
559 template <bool, typename> class GenericObject;
560 
562 // GenericValue
563 
565 
574 template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
576 public:
581  typedef typename Encoding::Ch Ch;
592 
594 
595 
597  GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
598 
599 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
601  GenericValue(GenericValue&& rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) {
602  rhs.data_.f.flags = kNullFlag; // give up contents
603  }
604 #endif
605 
606 private:
608  GenericValue(const GenericValue& rhs);
609 
610 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
612  template <typename StackAllocator>
614 
616  template <typename StackAllocator>
618 #endif
619 
620 public:
621 
623 
627  explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() {
628  static const uint16_t defaultFlags[7] = {
631  };
632  RAPIDJSON_ASSERT(type >= kNullType && type <= kNumberType);
633  data_.f.flags = defaultFlags[type];
634 
635  // Use ShortString to store empty string.
636  if (type == kStringType)
637  data_.ss.SetLength(0);
638  }
639 
641 
648  template <typename SourceAllocator>
649  GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
650  switch (rhs.GetType()) {
651  case kObjectType: {
652  SizeType count = rhs.data_.o.size;
653  Member* lm = reinterpret_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
655  for (SizeType i = 0; i < count; i++) {
656  new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
657  new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings);
658  }
661  SetMembersPointer(lm);
662  }
663  break;
664  case kArrayType: {
665  SizeType count = rhs.data_.a.size;
666  GenericValue* le = reinterpret_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
668  for (SizeType i = 0; i < count; i++)
669  new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
672  SetElementsPointer(le);
673  }
674  break;
675  case kStringType:
676  if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
677  data_.f.flags = rhs.data_.f.flags;
678  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
679  }
680  else
681  SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
682  break;
683  default:
684  data_.f.flags = rhs.data_.f.flags;
685  data_ = *reinterpret_cast<const Data*>(&rhs.data_);
686  break;
687  }
688  }
689 
691 
696 #ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
697  template <typename T>
698  explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT // See #472
699 #else
700  explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT
701 #endif
702  : data_() {
703  // safe-guard against failing SFINAE
705  data_.f.flags = b ? kTrueFlag : kFalseFlag;
706  }
707 
709  explicit GenericValue(int i) RAPIDJSON_NOEXCEPT : data_() {
710  data_.n.i64 = i;
712  }
713 
715  explicit GenericValue(unsigned u) RAPIDJSON_NOEXCEPT : data_() {
716  data_.n.u64 = u;
717  data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
718  }
719 
721  explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_() {
722  data_.n.i64 = i64;
724  if (i64 >= 0) {
726  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
727  data_.f.flags |= kUintFlag;
728  if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
729  data_.f.flags |= kIntFlag;
730  }
731  else if (i64 >= static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
732  data_.f.flags |= kIntFlag;
733  }
734 
736  explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_() {
737  data_.n.u64 = u64;
739  if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
740  data_.f.flags |= kInt64Flag;
741  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
742  data_.f.flags |= kUintFlag;
743  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
744  data_.f.flags |= kIntFlag;
745  }
746 
748  explicit GenericValue(double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
749 
751  explicit GenericValue(float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = static_cast<double>(f); data_.f.flags = kNumberDoubleFlag; }
752 
754  GenericValue(const Ch* s, SizeType length) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(StringRef(s, length)); }
755 
757  explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(s); }
758 
760  GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_() { SetStringRaw(StringRef(s, length), allocator); }
761 
763  GenericValue(const Ch*s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
764 
765 #if RAPIDJSON_HAS_STDSTRING
767 
769  GenericValue(const std::basic_string<Ch>& s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
770 #endif
771 
773 
778  GenericValue(Array a) RAPIDJSON_NOEXCEPT : data_(a.value_.data_) {
779  a.value_.data_ = Data();
780  a.value_.data_.f.flags = kArrayFlag;
781  }
782 
784 
789  GenericValue(Object o) RAPIDJSON_NOEXCEPT : data_(o.value_.data_) {
790  o.value_.data_ = Data();
791  o.value_.data_.f.flags = kObjectFlag;
792  }
793 
795 
798  if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
799  switch(data_.f.flags) {
800  case kArrayFlag:
801  {
803  for (GenericValue* v = e; v != e + data_.a.size; ++v)
804  v->~GenericValue();
805  Allocator::Free(e);
806  }
807  break;
808 
809  case kObjectFlag:
810  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
811  m->~Member();
812  Allocator::Free(GetMembersPointer());
813  break;
814 
815  case kCopyStringFlag:
816  Allocator::Free(const_cast<Ch*>(GetStringPointer()));
817  break;
818 
819  default:
820  break; // Do nothing for other types.
821  }
822  }
823  }
824 
826 
828 
829 
831 
833  GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
834  RAPIDJSON_ASSERT(this != &rhs);
835  this->~GenericValue();
836  RawAssign(rhs);
837  return *this;
838  }
839 
840 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
842  GenericValue& operator=(GenericValue&& rhs) RAPIDJSON_NOEXCEPT {
843  return *this = rhs.Move();
844  }
845 #endif
846 
848 
852  GenericValue& operator=(StringRefType str) RAPIDJSON_NOEXCEPT {
853  GenericValue s(str);
854  return *this = s;
855  }
856 
858 
869  template <typename T>
870  RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (GenericValue&))
871  operator=(T value) {
872  GenericValue v(value);
873  return *this = v;
874  }
875 
877 
883  template <typename SourceAllocator>
884  GenericValue& CopyFrom(const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
885  RAPIDJSON_ASSERT(static_cast<void*>(this) != static_cast<void const*>(&rhs));
886  this->~GenericValue();
887  new (this) GenericValue(rhs, allocator, copyConstStrings);
888  return *this;
889  }
890 
892 
896  GenericValue& Swap(GenericValue& other) RAPIDJSON_NOEXCEPT {
897  GenericValue temp;
898  temp.RawAssign(*this);
899  RawAssign(other);
900  other.RawAssign(temp);
901  return *this;
902  }
903 
905 
916  friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
917 
919 
920  GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; }
922 
924 
925 
930  template <typename SourceAllocator>
931  bool operator==(const GenericValue<Encoding, SourceAllocator>& rhs) const {
933  if (GetType() != rhs.GetType())
934  return false;
935 
936  switch (GetType()) {
937  case kObjectType: // Warning: O(n^2) inner-loop
938  if (data_.o.size != rhs.data_.o.size)
939  return false;
940  for (ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
941  typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name);
942  if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
943  return false;
944  }
945  return true;
946 
947  case kArrayType:
948  if (data_.a.size != rhs.data_.a.size)
949  return false;
950  for (SizeType i = 0; i < data_.a.size; i++)
951  if ((*this)[i] != rhs[i])
952  return false;
953  return true;
954 
955  case kStringType:
956  return StringEqual(rhs);
957 
958  case kNumberType:
959  if (IsDouble() || rhs.IsDouble()) {
960  double a = GetDouble(); // May convert from integer to double.
961  double b = rhs.GetDouble(); // Ditto
962  return a >= b && a <= b; // Prevent -Wfloat-equal
963  }
964  else
965  return data_.n.u64 == rhs.data_.n.u64;
966 
967  default:
968  return true;
969  }
970  }
971 
973  bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); }
974 
975 #if RAPIDJSON_HAS_STDSTRING
977 
979  bool operator==(const std::basic_string<Ch>& rhs) const { return *this == GenericValue(StringRef(rhs)); }
980 #endif
981 
983 
985  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); }
986 
988 
990  template <typename SourceAllocator>
991  bool operator!=(const GenericValue<Encoding, SourceAllocator>& rhs) const { return !(*this == rhs); }
992 
994  bool operator!=(const Ch* rhs) const { return !(*this == rhs); }
995 
997 
999  template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& rhs) const { return !(*this == rhs); }
1000 
1002 
1004  template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator==(const T& lhs, const GenericValue& rhs) { return rhs == lhs; }
1005 
1007 
1009  template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); }
1011 
1013 
1014 
1015  Type GetType() const { return static_cast<Type>(data_.f.flags & kTypeMask); }
1016  bool IsNull() const { return data_.f.flags == kNullFlag; }
1017  bool IsFalse() const { return data_.f.flags == kFalseFlag; }
1018  bool IsTrue() const { return data_.f.flags == kTrueFlag; }
1019  bool IsBool() const { return (data_.f.flags & kBoolFlag) != 0; }
1020  bool IsObject() const { return data_.f.flags == kObjectFlag; }
1021  bool IsArray() const { return data_.f.flags == kArrayFlag; }
1022  bool IsNumber() const { return (data_.f.flags & kNumberFlag) != 0; }
1023  bool IsInt() const { return (data_.f.flags & kIntFlag) != 0; }
1024  bool IsUint() const { return (data_.f.flags & kUintFlag) != 0; }
1025  bool IsInt64() const { return (data_.f.flags & kInt64Flag) != 0; }
1026  bool IsUint64() const { return (data_.f.flags & kUint64Flag) != 0; }
1027  bool IsDouble() const { return (data_.f.flags & kDoubleFlag) != 0; }
1028  bool IsString() const { return (data_.f.flags & kStringFlag) != 0; }
1029 
1030  // Checks whether a number can be losslessly converted to a double.
1031  bool IsLosslessDouble() const {
1032  if (!IsNumber()) return false;
1033  if (IsUint64()) {
1034  uint64_t u = GetUint64();
1035  volatile double d = static_cast<double>(u);
1036  return (d >= 0.0)
1037  && (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
1038  && (u == static_cast<uint64_t>(d));
1039  }
1040  if (IsInt64()) {
1041  int64_t i = GetInt64();
1042  volatile double d = static_cast<double>(i);
1043  return (d >= static_cast<double>((std::numeric_limits<int64_t>::min)()))
1044  && (d < static_cast<double>((std::numeric_limits<int64_t>::max)()))
1045  && (i == static_cast<int64_t>(d));
1046  }
1047  return true; // double, int, uint are always lossless
1048  }
1049 
1050  // Checks whether a number is a float (possible lossy).
1051  bool IsFloat() const {
1052  if ((data_.f.flags & kDoubleFlag) == 0)
1053  return false;
1054  double d = GetDouble();
1055  return d >= -3.4028234e38 && d <= 3.4028234e38;
1056  }
1057  // Checks whether a number can be losslessly converted to a float.
1058  bool IsLosslessFloat() const {
1059  if (!IsNumber()) return false;
1060  double a = GetDouble();
1061  if (a < static_cast<double>(-(std::numeric_limits<float>::max)())
1062  || a > static_cast<double>((std::numeric_limits<float>::max)()))
1063  return false;
1064  double b = static_cast<double>(static_cast<float>(a));
1065  return a >= b && a <= b; // Prevent -Wfloat-equal
1066  }
1067 
1069 
1071 
1072 
1073  GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; }
1074 
1076 
1078 
1079 
1080  bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return data_.f.flags == kTrueFlag; }
1082 
1083  GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
1084 
1086 
1088 
1089 
1091 
1092  GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
1093 
1095  SizeType MemberCount() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size; }
1096 
1098  SizeType MemberCapacity() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.capacity; }
1099 
1101  bool ObjectEmpty() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size == 0; }
1102 
1104 
1112  template <typename T>
1113  RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(GenericValue&)) operator[](T* name) {
1115  return (*this)[n];
1116  }
1117  template <typename T>
1118  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]; }
1119 
1121 
1129  template <typename SourceAllocator>
1131  MemberIterator member = FindMember(name);
1132  if (member != MemberEnd())
1133  return member->value;
1134  else {
1135  RAPIDJSON_ASSERT(false); // see above note
1136 
1137  // This will generate -Wexit-time-destructors in clang
1138  // static GenericValue NullValue;
1139  // return NullValue;
1140 
1141  // Use static buffer and placement-new to prevent destruction
1142  static char buffer[sizeof(GenericValue)];
1143  return *new (buffer) GenericValue();
1144  }
1145  }
1146  template <typename SourceAllocator>
1147  const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
1148 
1149 #if RAPIDJSON_HAS_STDSTRING
1151  GenericValue& operator[](const std::basic_string<Ch>& name) { return (*this)[GenericValue(StringRef(name))]; }
1152  const GenericValue& operator[](const std::basic_string<Ch>& name) const { return (*this)[GenericValue(StringRef(name))]; }
1153 #endif
1154 
1156 
1157  ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer()); }
1159 
1160  ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer() + data_.o.size); }
1162 
1163  MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer()); }
1165 
1166  MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer() + data_.o.size); }
1167 
1169 
1174  GenericValue& MemberReserve(SizeType newCapacity, Allocator &allocator) {
1175  RAPIDJSON_ASSERT(IsObject());
1176  if (newCapacity > data_.o.capacity) {
1177  SetMembersPointer(reinterpret_cast<Member*>(allocator.Realloc(GetMembersPointer(), data_.o.capacity * sizeof(Member), newCapacity * sizeof(Member))));
1178  data_.o.capacity = newCapacity;
1179  }
1180  return *this;
1181  }
1182 
1184 
1191  bool HasMember(const Ch* name) const { return FindMember(name) != MemberEnd(); }
1192 
1193 #if RAPIDJSON_HAS_STDSTRING
1195 
1202  bool HasMember(const std::basic_string<Ch>& name) const { return FindMember(name) != MemberEnd(); }
1203 #endif
1204 
1206 
1214  template <typename SourceAllocator>
1215  bool HasMember(const GenericValue<Encoding, SourceAllocator>& name) const { return FindMember(name) != MemberEnd(); }
1216 
1218 
1229  MemberIterator FindMember(const Ch* name) {
1231  return FindMember(n);
1232  }
1233 
1234  ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
1235 
1237 
1249  template <typename SourceAllocator>
1251  RAPIDJSON_ASSERT(IsObject());
1252  RAPIDJSON_ASSERT(name.IsString());
1253  MemberIterator member = MemberBegin();
1254  for ( ; member != MemberEnd(); ++member)
1255  if (name.StringEqual(member->name))
1256  break;
1257  return member;
1258  }
1259  template <typename SourceAllocator> ConstMemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
1260 
1261 #if RAPIDJSON_HAS_STDSTRING
1263 
1269  MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(GenericValue(StringRef(name))); }
1270  ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(GenericValue(StringRef(name))); }
1271 #endif
1272 
1274 
1283  GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) {
1284  RAPIDJSON_ASSERT(IsObject());
1285  RAPIDJSON_ASSERT(name.IsString());
1286 
1287  ObjectData& o = data_.o;
1288  if (o.size >= o.capacity)
1289  MemberReserve(o.capacity == 0 ? kDefaultObjectCapacity : (o.capacity + (o.capacity + 1) / 2), allocator);
1290  Member* members = GetMembersPointer();
1291  members[o.size].name.RawAssign(name);
1292  members[o.size].value.RawAssign(value);
1293  o.size++;
1294  return *this;
1295  }
1296 
1298 
1306  GenericValue& AddMember(GenericValue& name, StringRefType value, Allocator& allocator) {
1307  GenericValue v(value);
1308  return AddMember(name, v, allocator);
1309  }
1310 
1311 #if RAPIDJSON_HAS_STDSTRING
1313 
1321  GenericValue& AddMember(GenericValue& name, std::basic_string<Ch>& value, Allocator& allocator) {
1322  GenericValue v(value, allocator);
1323  return AddMember(name, v, allocator);
1324  }
1325 #endif
1326 
1328 
1344  template <typename T>
1345  RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1346  AddMember(GenericValue& name, T value, Allocator& allocator) {
1347  GenericValue v(value);
1348  return AddMember(name, v, allocator);
1349  }
1350 
1351 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1352  GenericValue& AddMember(GenericValue&& name, GenericValue&& value, Allocator& allocator) {
1353  return AddMember(name, value, allocator);
1354  }
1355  GenericValue& AddMember(GenericValue&& name, GenericValue& value, Allocator& allocator) {
1356  return AddMember(name, value, allocator);
1357  }
1358  GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) {
1359  return AddMember(name, value, allocator);
1360  }
1361  GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) {
1362  GenericValue n(name);
1363  return AddMember(n, value, allocator);
1364  }
1365 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1366 
1367 
1369 
1378  GenericValue& AddMember(StringRefType name, GenericValue& value, Allocator& allocator) {
1379  GenericValue n(name);
1380  return AddMember(n, value, allocator);
1381  }
1382 
1384 
1392  GenericValue& AddMember(StringRefType name, StringRefType value, Allocator& allocator) {
1393  GenericValue v(value);
1394  return AddMember(name, v, allocator);
1395  }
1396 
1398 
1414  template <typename T>
1415  RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1416  AddMember(StringRefType name, T value, Allocator& allocator) {
1417  GenericValue n(name);
1418  return AddMember(n, value, allocator);
1419  }
1420 
1422 
1425  void RemoveAllMembers() {
1426  RAPIDJSON_ASSERT(IsObject());
1427  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
1428  m->~Member();
1429  data_.o.size = 0;
1430  }
1431 
1433 
1440  bool RemoveMember(const Ch* name) {
1442  return RemoveMember(n);
1443  }
1444 
1445 #if RAPIDJSON_HAS_STDSTRING
1446  bool RemoveMember(const std::basic_string<Ch>& name) { return RemoveMember(GenericValue(StringRef(name))); }
1447 #endif
1448 
1449  template <typename SourceAllocator>
1450  bool RemoveMember(const GenericValue<Encoding, SourceAllocator>& name) {
1451  MemberIterator m = FindMember(name);
1452  if (m != MemberEnd()) {
1453  RemoveMember(m);
1454  return true;
1455  }
1456  else
1457  return false;
1458  }
1459 
1461 
1468  MemberIterator RemoveMember(MemberIterator m) {
1469  RAPIDJSON_ASSERT(IsObject());
1472  RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd());
1473 
1474  MemberIterator last(GetMembersPointer() + (data_.o.size - 1));
1475  if (data_.o.size > 1 && m != last)
1476  *m = *last; // Move the last one to this place
1477  else
1478  m->~Member(); // Only one left, just destroy
1479  --data_.o.size;
1480  return m;
1481  }
1482 
1484 
1492  MemberIterator EraseMember(ConstMemberIterator pos) {
1493  return EraseMember(pos, pos +1);
1494  }
1495 
1497 
1505  MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) {
1506  RAPIDJSON_ASSERT(IsObject());
1509  RAPIDJSON_ASSERT(first >= MemberBegin());
1510  RAPIDJSON_ASSERT(first <= last);
1511  RAPIDJSON_ASSERT(last <= MemberEnd());
1512 
1513  MemberIterator pos = MemberBegin() + (first - MemberBegin());
1514  for (MemberIterator itr = pos; itr != last; ++itr)
1515  itr->~Member();
1516  std::memmove(&*pos, &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
1517  data_.o.size -= static_cast<SizeType>(last - first);
1518  return pos;
1519  }
1520 
1522 
1526  bool EraseMember(const Ch* name) {
1528  return EraseMember(n);
1529  }
1530 
1531 #if RAPIDJSON_HAS_STDSTRING
1532  bool EraseMember(const std::basic_string<Ch>& name) { return EraseMember(GenericValue(StringRef(name))); }
1533 #endif
1534 
1535  template <typename SourceAllocator>
1536  bool EraseMember(const GenericValue<Encoding, SourceAllocator>& name) {
1537  MemberIterator m = FindMember(name);
1538  if (m != MemberEnd()) {
1539  EraseMember(m);
1540  return true;
1541  }
1542  else
1543  return false;
1544  }
1545 
1546  Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
1547  ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
1548 
1550 
1552 
1553 
1555 
1556  GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
1557 
1559  SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
1560 
1562  SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; }
1563 
1565  bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
1566 
1568 
1571  void Clear() {
1572  RAPIDJSON_ASSERT(IsArray());
1574  for (GenericValue* v = e; v != e + data_.a.size; ++v)
1575  v->~GenericValue();
1576  data_.a.size = 0;
1577  }
1578 
1580 
1584  GenericValue& operator[](SizeType index) {
1585  RAPIDJSON_ASSERT(IsArray());
1586  RAPIDJSON_ASSERT(index < data_.a.size);
1587  return GetElementsPointer()[index];
1588  }
1589  const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
1590 
1592 
1593  ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer(); }
1595 
1596  ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer() + data_.a.size; }
1598 
1599  ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
1601 
1602  ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
1603 
1605 
1610  GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
1611  RAPIDJSON_ASSERT(IsArray());
1612  if (newCapacity > data_.a.capacity) {
1613  SetElementsPointer(reinterpret_cast<GenericValue*>(allocator.Realloc(GetElementsPointer(), data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue))));
1614  data_.a.capacity = newCapacity;
1615  }
1616  return *this;
1617  }
1618 
1620 
1629  GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
1630  RAPIDJSON_ASSERT(IsArray());
1631  if (data_.a.size >= data_.a.capacity)
1632  Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1634  return *this;
1635  }
1636 
1637 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1638  GenericValue& PushBack(GenericValue&& value, Allocator& allocator) {
1639  return PushBack(value, allocator);
1640  }
1641 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1642 
1644 
1652  GenericValue& PushBack(StringRefType value, Allocator& allocator) {
1653  return (*this).template PushBack<StringRefType>(value, allocator);
1654  }
1655 
1657 
1673  template <typename T>
1674  RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1675  PushBack(T value, Allocator& allocator) {
1676  GenericValue v(value);
1677  return PushBack(v, allocator);
1678  }
1679 
1681 
1684  GenericValue& PopBack() {
1685  RAPIDJSON_ASSERT(IsArray());
1686  RAPIDJSON_ASSERT(!Empty());
1688  return *this;
1689  }
1690 
1692 
1698  ValueIterator Erase(ConstValueIterator pos) {
1699  return Erase(pos, pos + 1);
1700  }
1701 
1703 
1711  RAPIDJSON_ASSERT(IsArray());
1714  RAPIDJSON_ASSERT(first >= Begin());
1715  RAPIDJSON_ASSERT(first <= last);
1716  RAPIDJSON_ASSERT(last <= End());
1717  ValueIterator pos = Begin() + (first - Begin());
1718  for (ValueIterator itr = pos; itr != last; ++itr)
1719  itr->~GenericValue();
1720  std::memmove(pos, last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
1721  data_.a.size -= static_cast<SizeType>(last - first);
1722  return pos;
1723  }
1724 
1725  Array GetArray() { RAPIDJSON_ASSERT(IsArray()); return Array(*this); }
1726  ConstArray GetArray() const { RAPIDJSON_ASSERT(IsArray()); return ConstArray(*this); }
1727 
1729 
1731 
1732 
1733  int GetInt() const { RAPIDJSON_ASSERT(data_.f.flags & kIntFlag); return data_.n.i.i; }
1734  unsigned GetUint() const { RAPIDJSON_ASSERT(data_.f.flags & kUintFlag); return data_.n.u.u; }
1735  int64_t GetInt64() const { RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag); return data_.n.i64; }
1736  uint64_t GetUint64() const { RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag); return data_.n.u64; }
1737 
1739 
1741  double GetDouble() const {
1742  RAPIDJSON_ASSERT(IsNumber());
1743  if ((data_.f.flags & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
1744  if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double
1745  if ((data_.f.flags & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
1746  if ((data_.f.flags & kInt64Flag) != 0) return static_cast<double>(data_.n.i64); // int64_t -> double (may lose precision)
1747  RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0); return static_cast<double>(data_.n.u64); // uint64_t -> double (may lose precision)
1748  }
1749 
1751 
1753  float GetFloat() const {
1754  return static_cast<float>(GetDouble());
1755  }
1756 
1757  GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
1758  GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
1759  GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
1760  GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
1761  GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
1762  GenericValue& SetFloat(float f) { this->~GenericValue(); new (this) GenericValue(static_cast<double>(f)); return *this; }
1763 
1765 
1767 
1768 
1769  const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1770 
1772 
1774  SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength()) : data_.s.length); }
1775 
1777 
1784  GenericValue& SetString(const Ch* s, SizeType length) { return SetString(StringRef(s, length)); }
1785 
1787 
1791  GenericValue& SetString(StringRefType s) { this->~GenericValue(); SetStringRaw(s); return *this; }
1792 
1794 
1801  GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { return SetString(StringRef(s, length), allocator); }
1802 
1804 
1809  GenericValue& SetString(const Ch* s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
1810 
1812 
1817  GenericValue& SetString(StringRefType s, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, allocator); return *this; }
1818 
1819 #if RAPIDJSON_HAS_STDSTRING
1821 
1827  GenericValue& SetString(const std::basic_string<Ch>& s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
1828 #endif
1829 
1831 
1833 
1834 
1836 
1839  template <typename T>
1840  bool Is() const { return internal::TypeHelper<ValueType, T>::Is(*this); }
1841 
1842  template <typename T>
1843  T Get() const { return internal::TypeHelper<ValueType, T>::Get(*this); }
1844 
1845  template <typename T>
1846  T Get() { return internal::TypeHelper<ValueType, T>::Get(*this); }
1847 
1848  template<typename T>
1849  ValueType& Set(const T& data) { return internal::TypeHelper<ValueType, T>::Set(*this, data); }
1850 
1851  template<typename T>
1852  ValueType& Set(const T& data, AllocatorType& allocator) { return internal::TypeHelper<ValueType, T>::Set(*this, data, allocator); }
1853 
1855 
1857 
1863  template <typename Handler>
1864  bool Accept(Handler& handler) const {
1865  switch(GetType()) {
1866  case kNullType: return handler.Null();
1867  case kFalseType: return handler.Bool(false);
1868  case kTrueType: return handler.Bool(true);
1869 
1870  case kObjectType:
1871  if (RAPIDJSON_UNLIKELY(!handler.StartObject()))
1872  return false;
1873  for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
1874  RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of name by MemberIterator.
1875  if (RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1876  return false;
1877  if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler)))
1878  return false;
1879  }
1880  return handler.EndObject(data_.o.size);
1881 
1882  case kArrayType:
1883  if (RAPIDJSON_UNLIKELY(!handler.StartArray()))
1884  return false;
1885  for (const GenericValue* v = Begin(); v != End(); ++v)
1886  if (RAPIDJSON_UNLIKELY(!v->Accept(handler)))
1887  return false;
1888  return handler.EndArray(data_.a.size);
1889 
1890  case kStringType:
1891  return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1892 
1893  default:
1894  RAPIDJSON_ASSERT(GetType() == kNumberType);
1895  if (IsDouble()) return handler.Double(data_.n.d);
1896  else if (IsInt()) return handler.Int(data_.n.i.i);
1897  else if (IsUint()) return handler.Uint(data_.n.u.u);
1898  else if (IsInt64()) return handler.Int64(data_.n.i64);
1899  else return handler.Uint64(data_.n.u64);
1900  }
1901  }
1902 
1903 private:
1904  template <typename, typename> friend class GenericValue;
1905  template <typename, typename, typename> friend class GenericDocument;
1906 
1907  enum {
1908  kBoolFlag = 0x0008,
1909  kNumberFlag = 0x0010,
1910  kIntFlag = 0x0020,
1911  kUintFlag = 0x0040,
1912  kInt64Flag = 0x0080,
1913  kUint64Flag = 0x0100,
1914  kDoubleFlag = 0x0200,
1915  kStringFlag = 0x0400,
1916  kCopyFlag = 0x0800,
1917  kInlineStrFlag = 0x1000,
1918 
1919  // Initial flags of different types.
1934 
1935  kTypeMask = 0x07
1936  };
1937 
1938  static const SizeType kDefaultArrayCapacity = 16;
1940 
1941  struct Flag {
1942 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1943  char payload[sizeof(SizeType) * 2 + 6]; // 2 x SizeType + lower 48-bit pointer
1944 #elif RAPIDJSON_64BIT
1945  char payload[sizeof(SizeType) * 2 + sizeof(void*) + 6]; // 6 padding bytes
1946 #else
1947  char payload[sizeof(SizeType) * 2 + sizeof(void*) + 2]; // 2 padding bytes
1948 #endif
1950  };
1951 
1952  struct String {
1955  const Ch* str;
1956  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1957 
1958  // implementation detail: ShortString can represent zero-terminated strings up to MaxSize chars
1959  // (excluding the terminating zero) and store a value to determine the length of the contained
1960  // string in the last character str[LenPos] by storing "MaxSize - length" there. If the string
1961  // to store has the maximal length of MaxSize then str[LenPos] will be 0 and therefore act as
1962  // the string terminator as well. For getting the string length back from that value just use
1963  // "MaxSize - str[LenPos]".
1964  // This allows to store 13-chars strings in 32-bit mode, 21-chars strings in 64-bit mode,
1965  // 13-chars strings for RAPIDJSON_48BITPOINTER_OPTIMIZATION=1 inline (for `UTF8`-encoded strings).
1966  struct ShortString {
1967  enum { MaxChars = sizeof(static_cast<Flag*>(0)->payload) / sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1969 
1970  inline static bool Usable(SizeType len) { return (MaxSize >= len); }
1971  inline void SetLength(SizeType len) { str[LenPos] = static_cast<Ch>(MaxSize - len); }
1972  inline SizeType GetLength() const { return static_cast<SizeType>(MaxSize - str[LenPos]); }
1973  }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1974 
1975  // By using proper binary layout, retrieval of different integer types do not need conversions.
1976  union Number {
1977 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1978  struct I {
1979  int i;
1980  char padding[4];
1981  }i;
1982  struct U {
1983  unsigned u;
1984  char padding2[4];
1985  }u;
1986 #else
1987  struct I {
1988  char padding[4];
1989  int i;
1990  }i;
1991  struct U {
1992  char padding2[4];
1993  unsigned u;
1994  }u;
1995 #endif
1998  double d;
1999  }; // 8 bytes
2000 
2001  struct ObjectData {
2005  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2006 
2007  struct ArrayData {
2011  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2012 
2013  union Data {
2020  }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION
2021 
2022  RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
2023  RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
2024  RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer() const { return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
2025  RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
2026  RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
2027  RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
2028 
2029  // Initialize this value as array with initial data, without calling destructor.
2030  void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
2031  data_.f.flags = kArrayFlag;
2032  if (count) {
2033  GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
2034  SetElementsPointer(e);
2035 RAPIDJSON_DIAG_PUSH
2036 #if defined(__GNUC__) && __GNUC__ >= 8
2037 RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
2038 #endif
2039  std::memcpy(e, values, count * sizeof(GenericValue));
2040 RAPIDJSON_DIAG_POP
2041  }
2042  else
2043  SetElementsPointer(0);
2045  }
2046 
2048  void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
2050  if (count) {
2051  Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
2052  SetMembersPointer(m);
2053 RAPIDJSON_DIAG_PUSH
2054 #if defined(__GNUC__) && __GNUC__ >= 8
2055 RAPIDJSON_DIAG_OFF(class-memaccess) // ignore complains from gcc that no trivial copy constructor exists.
2056 #endif
2057  std::memcpy(m, members, count * sizeof(Member));
2058 RAPIDJSON_DIAG_POP
2059  }
2060  else
2061  SetMembersPointer(0);
2063  }
2064 
2066  void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2068  SetStringPointer(s);
2069  data_.s.length = s.length;
2070  }
2071 
2073  void SetStringRaw(StringRefType s, Allocator& allocator) {
2074  Ch* str = 0;
2075  if (ShortString::Usable(s.length)) {
2077  data_.ss.SetLength(s.length);
2078  str = data_.ss.str;
2079  } else {
2081  data_.s.length = s.length;
2082  str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2083  SetStringPointer(str);
2084  }
2085  std::memcpy(str, s, s.length * sizeof(Ch));
2086  str[s.length] = '\0';
2087  }
2088 
2090  void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2091  data_ = rhs.data_;
2092  // data_.f.flags = rhs.data_.f.flags;
2093  rhs.data_.f.flags = kNullFlag;
2094  }
2095 
2096  template <typename SourceAllocator>
2098  RAPIDJSON_ASSERT(IsString());
2099  RAPIDJSON_ASSERT(rhs.IsString());
2100 
2101  const SizeType len1 = GetStringLength();
2102  const SizeType len2 = rhs.GetStringLength();
2103  if(len1 != len2) { return false; }
2104 
2105  const Ch* const str1 = GetString();
2106  const Ch* const str2 = rhs.GetString();
2107  if(str1 == str2) { return true; } // fast path for constant string
2108 
2109  return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
2110  }
2111 
2113 };
2114 
2117 
2119 // GenericDocument
2120 
2122 
2129 template <typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
2130 class GenericDocument : public GenericValue<Encoding, Allocator> {
2131 public:
2132  typedef typename Encoding::Ch Ch;
2135 
2137 
2143  explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2144  GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2145  {
2146  if (!allocator_)
2147  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2148  }
2149 
2151 
2156  GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2157  allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2158  {
2159  if (!allocator_)
2160  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2161  }
2162 
2163 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2165  GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2166  : ValueType(std::forward<ValueType>(rhs)), // explicit cast to avoid prohibited move from Document
2167  allocator_(rhs.allocator_),
2168  ownAllocator_(rhs.ownAllocator_),
2169  stack_(std::move(rhs.stack_)),
2170  parseResult_(rhs.parseResult_)
2171  {
2172  rhs.allocator_ = 0;
2173  rhs.ownAllocator_ = 0;
2174  rhs.parseResult_ = ParseResult();
2175  }
2176 #endif
2177 
2179  Destroy();
2180  }
2181 
2182 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2184  GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2185  {
2186  // The cast to ValueType is necessary here, because otherwise it would
2187  // attempt to call GenericValue's templated assignment operator.
2188  ValueType::operator=(std::forward<ValueType>(rhs));
2189 
2190  // Calling the destructor here would prematurely call stack_'s destructor
2191  Destroy();
2192 
2193  allocator_ = rhs.allocator_;
2194  ownAllocator_ = rhs.ownAllocator_;
2195  stack_ = std::move(rhs.stack_);
2196  parseResult_ = rhs.parseResult_;
2197 
2198  rhs.allocator_ = 0;
2199  rhs.ownAllocator_ = 0;
2200  rhs.parseResult_ = ParseResult();
2201 
2202  return *this;
2203  }
2204 #endif
2205 
2207 
2212  GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT {
2213  ValueType::Swap(rhs);
2214  stack_.Swap(rhs.stack_);
2215  internal::Swap(allocator_, rhs.allocator_);
2216  internal::Swap(ownAllocator_, rhs.ownAllocator_);
2217  internal::Swap(parseResult_, rhs.parseResult_);
2218  return *this;
2219  }
2220 
2221  // Allow Swap with ValueType.
2222  // Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
2223  using ValueType::Swap;
2224 
2226 
2237  friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
2238 
2240 
2244  template <typename Generator>
2245  GenericDocument& Populate(Generator& g) {
2246  ClearStackOnExit scope(*this);
2247  if (g(*this)) {
2248  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2249  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2250  }
2251  return *this;
2252  }
2253 
2256 
2258 
2264  template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
2265  GenericDocument& ParseStream(InputStream& is) {
2267  stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2268  ClearStackOnExit scope(*this);
2269  parseResult_ = reader.template Parse<parseFlags>(is, *this);
2270  if (parseResult_) {
2271  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2272  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2273  }
2274  return *this;
2275  }
2276 
2278 
2283  template <unsigned parseFlags, typename InputStream>
2284  GenericDocument& ParseStream(InputStream& is) {
2285  return ParseStream<parseFlags, Encoding, InputStream>(is);
2286  }
2287 
2289 
2293  template <typename InputStream>
2294  GenericDocument& ParseStream(InputStream& is) {
2295  return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2296  }
2298 
2301 
2303 
2307  template <unsigned parseFlags>
2310  return ParseStream<parseFlags | kParseInsituFlag>(s);
2311  }
2312 
2314 
2318  return ParseInsitu<kParseDefaultFlags>(str);
2319  }
2321 
2324 
2326 
2330  template <unsigned parseFlags, typename SourceEncoding>
2331  GenericDocument& Parse(const typename SourceEncoding::Ch* str) {
2332  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2334  return ParseStream<parseFlags, SourceEncoding>(s);
2335  }
2336 
2338 
2341  template <unsigned parseFlags>
2342  GenericDocument& Parse(const Ch* str) {
2343  return Parse<parseFlags, Encoding>(str);
2344  }
2345 
2347 
2349  GenericDocument& Parse(const Ch* str) {
2350  return Parse<kParseDefaultFlags>(str);
2351  }
2352 
2353  template <unsigned parseFlags, typename SourceEncoding>
2354  GenericDocument& Parse(const typename SourceEncoding::Ch* str, size_t length) {
2355  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2356  MemoryStream ms(reinterpret_cast<const char*>(str), length * sizeof(typename SourceEncoding::Ch));
2358  ParseStream<parseFlags, SourceEncoding>(is);
2359  return *this;
2360  }
2361 
2362  template <unsigned parseFlags>
2363  GenericDocument& Parse(const Ch* str, size_t length) {
2364  return Parse<parseFlags, Encoding>(str, length);
2365  }
2366 
2367  GenericDocument& Parse(const Ch* str, size_t length) {
2368  return Parse<kParseDefaultFlags>(str, length);
2369  }
2370 
2371 #if RAPIDJSON_HAS_STDSTRING
2372  template <unsigned parseFlags, typename SourceEncoding>
2373  GenericDocument& Parse(const std::basic_string<typename SourceEncoding::Ch>& str) {
2374  // c_str() is constant complexity according to standard. Should be faster than Parse(const char*, size_t)
2375  return Parse<parseFlags, SourceEncoding>(str.c_str());
2376  }
2377 
2378  template <unsigned parseFlags>
2379  GenericDocument& Parse(const std::basic_string<Ch>& str) {
2380  return Parse<parseFlags, Encoding>(str.c_str());
2381  }
2382 
2383  GenericDocument& Parse(const std::basic_string<Ch>& str) {
2384  return Parse<kParseDefaultFlags>(str);
2385  }
2386 #endif // RAPIDJSON_HAS_STDSTRING
2387 
2389 
2392 
2394  bool HasParseError() const { return parseResult_.IsError(); }
2395 
2397  ParseErrorCode GetParseError() const { return parseResult_.Code(); }
2398 
2400  size_t GetErrorOffset() const { return parseResult_.Offset(); }
2401 
2403 #ifndef __clang // -Wdocumentation
2413 #endif
2414  operator ParseResult() const { return parseResult_; }
2416 
2419  RAPIDJSON_ASSERT(allocator_);
2420  return *allocator_;
2421  }
2422 
2424  size_t GetStackCapacity() const { return stack_.GetCapacity(); }
2425 
2426 private:
2427  // clear stack on any exit from ParseStream, e.g. due to exception
2428  struct ClearStackOnExit {
2429  explicit ClearStackOnExit(GenericDocument& d) : d_(d) {}
2430  ~ClearStackOnExit() { d_.ClearStack(); }
2431  private:
2432  ClearStackOnExit(const ClearStackOnExit&);
2433  ClearStackOnExit& operator=(const ClearStackOnExit&);
2434  GenericDocument& d_;
2435  };
2436 
2437  // callers of the following private Handler functions
2438  // template <typename,typename,typename> friend class GenericReader; // for parsing
2439  template <typename, typename> friend class GenericValue; // for deep copying
2440 
2441 public:
2442  // Implementation of Handler
2443  bool Null() { new (stack_.template Push<ValueType>()) ValueType(); return true; }
2444  bool Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
2445  bool Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2446  bool Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2447  bool Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2448  bool Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2449  bool Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); return true; }
2450 
2451  bool RawNumber(const Ch* str, SizeType length, bool copy) {
2452  if (copy)
2453  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2454  else
2455  new (stack_.template Push<ValueType>()) ValueType(str, length);
2456  return true;
2457  }
2458 
2459  bool String(const Ch* str, SizeType length, bool copy) {
2460  if (copy)
2461  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2462  else
2463  new (stack_.template Push<ValueType>()) ValueType(str, length);
2464  return true;
2465  }
2466 
2467  bool StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); return true; }
2468 
2469  bool Key(const Ch* str, SizeType length, bool copy) { return String(str, length, copy); }
2470 
2471  bool EndObject(SizeType memberCount) {
2472  typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2473  stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2474  return true;
2475  }
2476 
2477  bool StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); return true; }
2478 
2479  bool EndArray(SizeType elementCount) {
2480  ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2481  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2482  return true;
2483  }
2484 
2485 private:
2490 
2491  void ClearStack() {
2492  if (Allocator::kNeedFree)
2493  while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
2494  (stack_.template Pop<ValueType>(1))->~ValueType();
2495  else
2496  stack_.Clear();
2497  stack_.ShrinkToFit();
2498  }
2499 
2500  void Destroy() {
2501  RAPIDJSON_DELETE(ownAllocator_);
2502  }
2503 
2504  static const size_t kDefaultStackCapacity = 1024;
2505  Allocator* allocator_;
2506  Allocator* ownAllocator_;
2508  ParseResult parseResult_;
2509 };
2510 
2513 
2515 
2519 template <bool Const, typename ValueT>
2521 public:
2524  typedef ValueT PlainType;
2526  typedef ValueType* ValueIterator; // This may be const or non-const iterator
2527  typedef const ValueT* ConstValueIterator;
2528  typedef typename ValueType::AllocatorType AllocatorType;
2529  typedef typename ValueType::StringRefType StringRefType;
2530 
2531  template <typename, typename>
2532  friend class GenericValue;
2533 
2534  GenericArray(const GenericArray& rhs) : value_(rhs.value_) {}
2535  GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; }
2537 
2538  SizeType Size() const { return value_.Size(); }
2539  SizeType Capacity() const { return value_.Capacity(); }
2540  bool Empty() const { return value_.Empty(); }
2541  void Clear() const { value_.Clear(); }
2542  ValueType& operator[](SizeType index) const { return value_[index]; }
2543  ValueIterator Begin() const { return value_.Begin(); }
2544  ValueIterator End() const { return value_.End(); }
2545  GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const { value_.Reserve(newCapacity, allocator); return *this; }
2546  GenericArray PushBack(ValueType& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2547 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2548  GenericArray PushBack(ValueType&& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2549 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2550  GenericArray PushBack(StringRefType value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2551  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; }
2552  GenericArray PopBack() const { value_.PopBack(); return *this; }
2553  ValueIterator Erase(ConstValueIterator pos) const { return value_.Erase(pos); }
2554  ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const { return value_.Erase(first, last); }
2555 
2556 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2557  ValueIterator begin() const { return value_.Begin(); }
2558  ValueIterator end() const { return value_.End(); }
2559 #endif
2560 
2561 private:
2562  GenericArray();
2563  GenericArray(ValueType& value) : value_(value) {}
2564  ValueType& value_;
2565 };
2566 
2568 
2572 template <bool Const, typename ValueT>
2574 public:
2577  typedef ValueT PlainType;
2581  typedef typename ValueType::AllocatorType AllocatorType;
2582  typedef typename ValueType::StringRefType StringRefType;
2583  typedef typename ValueType::EncodingType EncodingType;
2584  typedef typename ValueType::Ch Ch;
2585 
2586  template <typename, typename>
2587  friend class GenericValue;
2588 
2589  GenericObject(const GenericObject& rhs) : value_(rhs.value_) {}
2590  GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; }
2592 
2593  SizeType MemberCount() const { return value_.MemberCount(); }
2594  SizeType MemberCapacity() const { return value_.MemberCapacity(); }
2595  bool ObjectEmpty() const { return value_.ObjectEmpty(); }
2596  template <typename T> ValueType& operator[](T* name) const { return value_[name]; }
2597  template <typename SourceAllocator> ValueType& operator[](const GenericValue<EncodingType, SourceAllocator>& name) const { return value_[name]; }
2598 #if RAPIDJSON_HAS_STDSTRING
2599  ValueType& operator[](const std::basic_string<Ch>& name) const { return value_[name]; }
2600 #endif
2601  MemberIterator MemberBegin() const { return value_.MemberBegin(); }
2602  MemberIterator MemberEnd() const { return value_.MemberEnd(); }
2603  GenericObject MemberReserve(SizeType newCapacity, AllocatorType &allocator) const { value_.MemberReserve(newCapacity, allocator); return *this; }
2604  bool HasMember(const Ch* name) const { return value_.HasMember(name); }
2605 #if RAPIDJSON_HAS_STDSTRING
2606  bool HasMember(const std::basic_string<Ch>& name) const { return value_.HasMember(name); }
2607 #endif
2608  template <typename SourceAllocator> bool HasMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.HasMember(name); }
2609  MemberIterator FindMember(const Ch* name) const { return value_.FindMember(name); }
2610  template <typename SourceAllocator> MemberIterator FindMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.FindMember(name); }
2611 #if RAPIDJSON_HAS_STDSTRING
2612  MemberIterator FindMember(const std::basic_string<Ch>& name) const { return value_.FindMember(name); }
2613 #endif
2614  GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2615  GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2616 #if RAPIDJSON_HAS_STDSTRING
2617  GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2618 #endif
2619  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; }
2620 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2621  GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2622  GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2623  GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2624  GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2625 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2626  GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2627  GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2628  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; }
2629  void RemoveAllMembers() { value_.RemoveAllMembers(); }
2630  bool RemoveMember(const Ch* name) const { return value_.RemoveMember(name); }
2631 #if RAPIDJSON_HAS_STDSTRING
2632  bool RemoveMember(const std::basic_string<Ch>& name) const { return value_.RemoveMember(name); }
2633 #endif
2634  template <typename SourceAllocator> bool RemoveMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.RemoveMember(name); }
2635  MemberIterator RemoveMember(MemberIterator m) const { return value_.RemoveMember(m); }
2636  MemberIterator EraseMember(ConstMemberIterator pos) const { return value_.EraseMember(pos); }
2637  MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const { return value_.EraseMember(first, last); }
2638  bool EraseMember(const Ch* name) const { return value_.EraseMember(name); }
2639 #if RAPIDJSON_HAS_STDSTRING
2640  bool EraseMember(const std::basic_string<Ch>& name) const { return EraseMember(ValueType(StringRef(name))); }
2641 #endif
2642  template <typename SourceAllocator> bool EraseMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.EraseMember(name); }
2643 
2644 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2645  MemberIterator begin() const { return value_.MemberBegin(); }
2646  MemberIterator end() const { return value_.MemberEnd(); }
2647 #endif
2648 
2649 private:
2650  GenericObject();
2651  GenericObject(ValueType& value) : value_(value) {}
2652  ValueType& value_;
2653 };
2654 
2656 RAPIDJSON_DIAG_POP
2657 
2658 #endif // RAPIDJSON_DOCUMENT_H_
return true
connection< TProtocol > & operator=(const connection< TProtocol > &obj)
Input byte stream wrapper with a statically bound encoding.
Definition: encodedstream.h:39
Helper class for accessing Value of array type.
Definition: document.h:2520
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(const GenericArray &)) PushBack(T value
const ValueT * ConstValueIterator
Definition: document.h:2527
GenericArray PushBack(ValueType &value, AllocatorType &allocator) const
Definition: document.h:2546
ValueIterator End() const
Definition: document.h:2544
ValueIterator Begin() const
Definition: document.h:2543
void Clear() const
Definition: document.h:2541
SizeType Size() const
Definition: document.h:2538
GenericArray< false, ValueT > Array
Definition: document.h:2523
GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const
Definition: document.h:2545
GenericArray< true, ValueT > ConstArray
Definition: document.h:2522
ValueType::StringRefType StringRefType
Definition: document.h:2529
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:2525
ValueType & operator[](SizeType index) const
Definition: document.h:2542
GenericArray(const GenericArray &rhs)
Definition: document.h:2534
SizeType Capacity() const
Definition: document.h:2539
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const
Definition: document.h:2554
GenericArray & operator=(const GenericArray &rhs)
Definition: document.h:2535
GenericArray PushBack(StringRefType value, AllocatorType &allocator) const
Definition: document.h:2550
ValueT PlainType
Definition: document.h:2524
ValueIterator Erase(ConstValueIterator pos) const
Definition: document.h:2553
bool Empty() const
Definition: document.h:2540
ValueType::AllocatorType AllocatorType
Definition: document.h:2528
ValueType * ValueIterator
Definition: document.h:2526
GenericArray PopBack() const
Definition: document.h:2552
A document for parsing JSON text as DOM.
Definition: document.h:2130
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2237
bool EndArray(SizeType elementCount)
Definition: document.h:2479
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:2308
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:2134
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition: document.h:2245
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2143
bool EndObject(SizeType memberCount)
Definition: document.h:2471
GenericDocument & Parse(const typename SourceEncoding::Ch *str, size_t length)
Definition: document.h:2354
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:2349
bool Bool(bool b)
Definition: document.h:2444
bool Uint64(uint64_t i)
Definition: document.h:2448
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: document.h:2394
bool Uint(unsigned i)
Definition: document.h:2446
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:2342
bool Key(const Ch *str, SizeType length, bool copy)
Definition: document.h:2469
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2212
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2156
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:2284
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:2132
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:2317
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
bool Int(int i)
Definition: document.h:2445
bool Int64(int64_t i)
Definition: document.h:2447
bool Double(double d)
Definition: document.h:2449
GenericDocument & Parse(const Ch *str, size_t length)
Definition: document.h:2363
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:2397
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:2424
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2418
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2331
GenericDocument & Parse(const Ch *str, size_t length)
Definition: document.h:2367
bool StartObject()
Definition: document.h:2467
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:2294
bool String(const Ch *str, SizeType length, bool copy)
Definition: document.h:2459
bool StartArray()
Definition: document.h:2477
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:2400
bool RawNumber(const Ch *str, SizeType length, bool copy)
Definition: document.h:2451
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:2265
(Constant) member iterator for a JSON object value
Definition: document.h:99
ValueType & reference
Definition: document.h:119
bool operator==(ConstIterator that) const
Definition: document.h:175
Iterator & operator+=(DifferenceType n)
Definition: document.h:169
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:153
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:135
bool operator!=(ConstIterator that) const
Definition: document.h:176
Iterator operator-(DifferenceType n) const
Definition: document.h:167
std::random_access_iterator_tag iterator_category
Definition: document.h:121
Reference operator[](DifferenceType n) const
Definition: document.h:187
Iterator operator--(int)
Definition: document.h:161
Iterator operator+(DifferenceType n) const
Definition: document.h:166
Iterator & operator=(const NonConstIterator &it)
Definition: document.h:154
Reference operator*() const
Definition: document.h:185
bool operator<=(ConstIterator that) const
Definition: document.h:177
Iterator & operator--()
Definition: document.h:159
ValueType value_type
Definition: document.h:117
ValueType * pointer
Definition: document.h:118
Iterator & operator-=(DifferenceType n)
Definition: document.h:170
bool operator>=(ConstIterator that) const
Definition: document.h:178
reference Reference
Reference to (const) GenericMember.
Definition: document.h:127
Iterator operator++(int)
Definition: document.h:160
friend class GenericMemberIterator
Definition: document.h:102
difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:129
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:113
Pointer operator->() const
Definition: document.h:186
pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:125
bool operator<(ConstIterator that) const
Definition: document.h:179
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:109
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:191
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:111
bool operator>(ConstIterator that) const
Definition: document.h:180
std::ptrdiff_t difference_type
Definition: document.h:120
Iterator & operator++()
Definition: document.h:158
Helper class for accessing Value of object type.
Definition: document.h:2573
MemberIterator RemoveMember(MemberIterator m) const
Definition: document.h:2635
ValueType::AllocatorType AllocatorType
Definition: document.h:2581
GenericObject AddMember(StringRefType name, ValueType &value, AllocatorType &allocator) const
Definition: document.h:2626
SizeType MemberCapacity() const
Definition: document.h:2594
bool HasMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2608
GenericObject(const GenericObject &rhs)
Definition: document.h:2589
void RemoveAllMembers()
Definition: document.h:2629
MemberIterator FindMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2610
SizeType MemberCount() const
Definition: document.h:2593
ValueType & operator[](const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2597
GenericMemberIterator< Const, typename ValueT::EncodingType, typename ValueT::AllocatorType > MemberIterator
Definition: document.h:2579
MemberIterator EraseMember(ConstMemberIterator pos) const
Definition: document.h:2636
ValueType & operator[](T *name) const
Definition: document.h:2596
GenericObject AddMember(ValueType &name, ValueType &value, AllocatorType &allocator) const
Definition: document.h:2614
GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType &allocator) const
Definition: document.h:2627
ValueT PlainType
Definition: document.h:2577
bool EraseMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2642
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const
Definition: document.h:2637
MemberIterator MemberEnd() const
Definition: document.h:2602
bool RemoveMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:2634
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:2578
ValueType::EncodingType EncodingType
Definition: document.h:2583
MemberIterator FindMember(const Ch *name) const
Definition: document.h:2609
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) AddMember(ValueType &name
bool HasMember(const Ch *name) const
Definition: document.h:2604
ValueType::StringRefType StringRefType
Definition: document.h:2582
bool ObjectEmpty() const
Definition: document.h:2595
ValueType::Ch Ch
Definition: document.h:2584
GenericObject AddMember(ValueType &name, StringRefType value, AllocatorType &allocator) const
Definition: document.h:2615
GenericObject< false, ValueT > Object
Definition: document.h:2576
bool RemoveMember(const Ch *name) const
Definition: document.h:2630
GenericObject< true, ValueT > ConstObject
Definition: document.h:2575
bool EraseMember(const Ch *name) const
Definition: document.h:2638
GenericMemberIterator< true, typename ValueT::EncodingType, typename ValueT::AllocatorType > ConstMemberIterator
Definition: document.h:2580
MemberIterator MemberBegin() const
Definition: document.h:2601
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(GenericObject)) AddMember(StringRefType name
GenericObject MemberReserve(SizeType newCapacity, AllocatorType &allocator) const
Definition: document.h:2603
GenericObject & operator=(const GenericObject &rhs)
Definition: document.h:2590
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: pointer.h:79
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:537
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:575
RAPIDJSON_FORCEINLINE Member * GetMembersPointer() const
Definition: document.h:2026
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition: document.h:2027
RAPIDJSON_FORCEINLINE const Ch * GetStringPointer() const
Definition: document.h:2022
GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:698
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2066
GenericArray< false, ValueType > Array
Definition: document.h:588
static const SizeType kDefaultArrayCapacity
Definition: document.h:1938
~GenericValue()
Destructor.
Definition: document.h:797
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:748
void SetObjectRaw(Member *members, SizeType count, Allocator &allocator)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:2048
static const SizeType kDefaultObjectCapacity
Definition: document.h:1939
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:579
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:582
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:583
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:852
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:587
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:586
RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer< T >),(GenericValue &)) operator
Assignment with primitive types.
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:754
GenericObject< true, ValueType > ConstObject
Definition: document.h:591
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition: document.h:649
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:580
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:578
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:627
@ kNumberDoubleFlag
Definition: document.h:1927
@ kConstStringFlag
Definition: document.h:1929
@ kNumberUint64Flag
Definition: document.h:1926
@ kShortStringFlag
Definition: document.h:1931
@ kNumberInt64Flag
Definition: document.h:1925
GenericArray< true, ValueType > ConstArray
Definition: document.h:589
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator)
Definition: document.h:2030
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:833
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition: document.h:778
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:721
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:715
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:763
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition: document.h:789
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:760
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:2023
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:584
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:709
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:597
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:757
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition: document.h:2090
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition: document.h:751
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:736
void SetStringRaw(StringRefType s, Allocator &allocator)
Initialize this value as copy string with initial data, without calling destructor.
Definition: document.h:2073
bool StringEqual(const GenericValue< Encoding, SourceAllocator > &rhs) const
Definition: document.h:2097
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition: document.h:2025
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:581
RAPIDJSON_FORCEINLINE GenericValue * GetElementsPointer() const
Definition: document.h:2024
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:585
GenericObject< false, ValueType > Object
Definition: document.h:590
void Clear()
Definition: stack.h:98
void ShrinkToFit()
Definition: stack.h:100
void Swap(Stack &rhs) RAPIDJSON_NOEXCEPT
Definition: stack.h:89
bool HasAllocator() const
Definition: stack.h:167
size_t GetCapacity() const
Definition: stack.h:178
Allocator & GetAllocator()
Definition: stack.h:171
size_t GetSize() const
Definition: stack.h:177
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2116
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:361
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2512
void * memcpy(void *a, const void *b, size_t c)
void * memmove(void *a, const void *b, size_t c)
const uint32_t T[512]
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:468
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:481
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
ParseErrorCode
Error code of parsing.
Definition: error.h:64
bool operator==(const some_test_data &a, const some_test_data &b)
bool operator!=(const some_test_subdata &a, const some_test_subdata &b)
const char * name
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
mdb_size_t count(MDB_cursor *cur)
void copy(key &AA, const key &A)
Definition: rctOps.h:79
const T & move(const T &t)
Definition: gtest-port.h:1317
GTEST_API_ bool IsTrue(bool condition)
PolymorphicMatcher< internal::IsNullMatcher > IsNull()
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:323
Type
Type of JSON value.
Definition: rapidjson.h:620
@ kFalseType
false
Definition: rapidjson.h:622
@ kObjectType
object
Definition: rapidjson.h:624
@ kTrueType
true
Definition: rapidjson.h:623
@ kStringType
string
Definition: rapidjson.h:626
@ kNullType
null
Definition: rapidjson.h:621
@ kArrayType
array
Definition: rapidjson.h:625
@ kNumberType
number
Definition: rapidjson.h:627
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:607
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:294
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:324
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:603
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:450
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:147
int bool
Definition: stdbool.h:36
#define false
Definition: stdbool.h:38
unsigned short uint16_t
Definition: stdint.h:125
signed __int64 int64_t
Definition: stdint.h:135
unsigned __int64 uint64_t
Definition: stdint.h:136
A read-write string stream.
Definition: stream.h:188
Name-value pair in a JSON object value.
Definition: document.h:69
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:70
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:71
Reference to a constant string (not taking a copy)
Definition: document.h:253
CharType Ch
character type of the string
Definition: document.h:254
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition: document.h:327
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string.
Definition: document.h:381
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:318
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:306
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:361
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:282
GenericStringRef(const GenericStringRef &rhs)
Definition: document.h:321
const Ch *const s
plain CharType pointer
Definition: document.h:326
Read-only string stream.
Definition: stream.h:154
GenericValue * elements
Definition: document.h:2010
char payload[sizeof(SizeType) *2+sizeof(void *)+2]
Definition: document.h:1947
SizeType GetLength() const
Definition: document.h:1972
static bool Usable(SizeType len)
Definition: document.h:1970
void SetLength(SizeType len)
Definition: document.h:1971
SizeType hashcode
reserved
Definition: document.h:1954
Represents an in-memory input byte stream.
Definition: memorystream.h:40
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
bool IsError() const
Whether the result is an error.
Definition: error.h:123
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118
static ValueType & Set(ValueType &v, bool data, typename ValueType::AllocatorType &)
Definition: document.h:433
static ValueType & Set(ValueType &v, bool data)
Definition: document.h:432
static bool Is(const ValueType &v)
Definition: document.h:430
static bool Get(const ValueType &v)
Definition: document.h:431
static ValueType & Set(ValueType &v, const StringType data, typename ValueType::AllocatorType &a)
Definition: document.h:510
static ValueType & Set(ValueType &v, const StringType data)
Definition: document.h:509
static ValueType & Set(ValueType &v, double data)
Definition: document.h:492
static ValueType & Set(ValueType &v, double data, typename ValueType::AllocatorType &)
Definition: document.h:493
static bool Is(const ValueType &v)
Definition: document.h:490
static double Get(const ValueType &v)
Definition: document.h:491
static bool Is(const ValueType &v)
Definition: document.h:498
static ValueType & Set(ValueType &v, float data)
Definition: document.h:500
static ValueType & Set(ValueType &v, float data, typename ValueType::AllocatorType &)
Definition: document.h:501
static float Get(const ValueType &v)
Definition: document.h:499
static ValueType & Set(ValueType &v, int64_t data)
Definition: document.h:476
static bool Is(const ValueType &v)
Definition: document.h:474
static ValueType & Set(ValueType &v, int64_t data, typename ValueType::AllocatorType &)
Definition: document.h:477
static int64_t Get(const ValueType &v)
Definition: document.h:475
static ValueType & Set(ValueType &v, int data, typename ValueType::AllocatorType &)
Definition: document.h:441
static int Get(const ValueType &v)
Definition: document.h:439
static bool Is(const ValueType &v)
Definition: document.h:438
static ValueType & Set(ValueType &v, int data)
Definition: document.h:440
static ValueType & Set(ValueType &v, ArrayType data)
Definition: document.h:528
static ValueType & Set(ValueType &v, ArrayType data, typename ValueType::AllocatorType &)
Definition: document.h:529
static ValueType & Set(ValueType &v, ObjectType data, typename ValueType::AllocatorType &)
Definition: document.h:545
static ValueType & Set(ValueType &v, ObjectType data)
Definition: document.h:544
static uint64_t Get(const ValueType &v)
Definition: document.h:483
static ValueType & Set(ValueType &v, uint64_t data)
Definition: document.h:484
static ValueType & Set(ValueType &v, uint64_t data, typename ValueType::AllocatorType &)
Definition: document.h:485
static bool Is(const ValueType &v)
Definition: document.h:482
static ValueType & Set(ValueType &v, unsigned data)
Definition: document.h:448
static unsigned Get(const ValueType &v)
Definition: document.h:447
static ValueType & Set(ValueType &v, unsigned data, typename ValueType::AllocatorType &)
Definition: document.h:449
static bool Is(const ValueType &v)
Definition: document.h:446
ShortString ss
Definition: document.h:2015
ObjectData o
Definition: document.h:2017
struct GenericValue::Number::I i
struct GenericValue::Number::U u