document.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_DOCUMENT_H_
20 #define RAPIDJSON_DOCUMENT_H_
21 
24 #include <limits>
25 #include <new> // placement new
26 #include "encodedstream.h"
27 #include "internal/meta.h"
28 #include "internal/strfunc.h"
29 #include "memorystream.h"
30 #include "reader.h"
31 
32 RAPIDJSON_DIAG_PUSH
33 #ifdef __clang__
34 RAPIDJSON_DIAG_OFF(padded)
35 RAPIDJSON_DIAG_OFF(switch - enum)
36 RAPIDJSON_DIAG_OFF(c++ 98 - compat)
37 #elif defined(_MSC_VER)
38 RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
39 RAPIDJSON_DIAG_OFF(
40  4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
41 #endif
42 
43 #ifdef __GNUC__
44 RAPIDJSON_DIAG_OFF(effc++)
45 #endif // __GNUC__
46 
47 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
48 #include <iterator> // std::random_access_iterator_tag
49 #endif
50 
51 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
52 #include <utility> // std::move
53 #endif
54 
56 
57 // Forward declaration.
58 template <typename Encoding, typename Allocator>
60 
61 template <typename Encoding, typename Allocator, typename StackAllocator>
63 
65 
71 template <typename Encoding, typename Allocator>
73  public:
75  name;
77 
78 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
79  GenericMember(GenericMember &&rhs) RAPIDJSON_NOEXCEPT
81  : name(std::move(rhs.name)),
82  value(std::move(rhs.value)) {}
83 
85  GenericMember &operator=(GenericMember &&rhs) RAPIDJSON_NOEXCEPT {
86  return *this = static_cast<GenericMember &>(rhs);
87  }
88 #endif
89 
91 
94  GenericMember &operator=(GenericMember &rhs) RAPIDJSON_NOEXCEPT {
95  if (RAPIDJSON_LIKELY(this != &rhs)) {
96  name = rhs.name;
97  value = rhs.value;
98  }
99  return *this;
100  }
101 
102  // swap() for std::sort() and other potential use in STL.
103  friend inline void swap(GenericMember &a,
104  GenericMember &b) RAPIDJSON_NOEXCEPT {
105  a.name.Swap(b.name);
106  a.value.Swap(b.value);
107  }
108 
109  private:
111  GenericMember(const GenericMember &rhs);
112 };
113 
115 // GenericMemberIterator
116 
117 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
118 
120 
141 template <bool Const, typename Encoding, typename Allocator>
143  friend class GenericValue<Encoding, Allocator>;
144  template <bool, typename, typename>
145  friend class GenericMemberIterator;
146 
149 
150  public:
157 
160  typedef ValueType value_type;
161  typedef ValueType *pointer;
162  typedef ValueType &reference;
163  typedef std::ptrdiff_t difference_type;
164  typedef std::random_access_iterator_tag iterator_category;
166 
168  typedef pointer Pointer;
170  typedef reference Reference;
172  typedef difference_type DifferenceType;
173 
175 
180 
182 
197  GenericMemberIterator(const NonConstIterator &it) : ptr_(it.ptr_) {}
198  Iterator &operator=(const NonConstIterator &it) {
199  ptr_ = it.ptr_;
200  return *this;
201  }
202 
204 
205  Iterator &operator++() {
206  ++ptr_;
207  return *this;
208  }
209  Iterator &operator--() {
210  --ptr_;
211  return *this;
212  }
213  Iterator operator++(int) {
214  Iterator old(*this);
215  ++ptr_;
216  return old;
217  }
218  Iterator operator--(int) {
219  Iterator old(*this);
220  --ptr_;
221  return old;
222  }
224 
226 
227  Iterator operator+(DifferenceType n) const { return Iterator(ptr_ + n); }
228  Iterator operator-(DifferenceType n) const { return Iterator(ptr_ - n); }
229 
230  Iterator &operator+=(DifferenceType n) {
231  ptr_ += n;
232  return *this;
233  }
234  Iterator &operator-=(DifferenceType n) {
235  ptr_ -= n;
236  return *this;
237  }
239 
241 
242  bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
243  bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
244  bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
245  bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
246  bool operator<(ConstIterator that) const { return ptr_ < that.ptr_; }
247  bool operator>(ConstIterator that) const { return ptr_ > that.ptr_; }
249 
251 
252  Reference operator*() const { return *ptr_; }
253  Pointer operator->() const { return ptr_; }
254  Reference operator[](DifferenceType n) const { return ptr_[n]; }
256 
258  DifferenceType operator-(ConstIterator that) const {
259  return ptr_ - that.ptr_;
260  }
261 
262  private:
264  explicit GenericMemberIterator(Pointer p) : ptr_(p) {}
265 
266  Pointer ptr_;
267 };
268 
269 #else // RAPIDJSON_NOMEMBERITERATORCLASS
270 
271 // class-based member iterator implementation disabled, use plain pointers
272 
273 template <bool Const, typename Encoding, typename Allocator>
275 
277 template <typename Encoding, typename Allocator>
278 class GenericMemberIterator<false, Encoding, Allocator> {
281 };
283 template <typename Encoding, typename Allocator>
284 class GenericMemberIterator<true, Encoding, Allocator> {
287 };
288 
289 #endif // RAPIDJSON_NOMEMBERITERATORCLASS
290 
292 // GenericStringRef
293 
295 
321 template <typename CharType>
323  typedef CharType Ch;
324 
326 #ifndef __clang__ // -Wdocumentation
327 
349 #endif
350  template <SizeType N>
351  GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
352  : s(str),
353  length(N - 1) {}
354 
356 #ifndef __clang__ // -Wdocumentation
357 
375 #endif
376  explicit GenericStringRef(const CharType *str)
377  : s(str), length(NotNullStrLen(str)) {}
378 
380 #ifndef __clang__ // -Wdocumentation
381 
388 #endif
389  GenericStringRef(const CharType *str, SizeType len)
390  : s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) {
391  RAPIDJSON_ASSERT(str != 0 || len == 0u);
392  }
393 
395  : s(rhs.s), length(rhs.length) {}
396 
398  operator const Ch *() const { return s; }
399 
400  const Ch *const s;
401  const SizeType length;
402 
404  private:
405  SizeType NotNullStrLen(const CharType *str) {
406  RAPIDJSON_ASSERT(str != 0);
407  return internal::StrLen(str);
408  }
409 
411  static const Ch emptyString[];
412 
414  template <SizeType N>
415  GenericStringRef(CharType (&str)[N]) /* = delete */;
417  GenericStringRef &operator=(const GenericStringRef &rhs) /* = delete */;
418 };
419 
420 template <typename CharType>
421 const CharType GenericStringRef<CharType>::emptyString[] = {CharType()};
422 
424 
438 template <typename CharType>
439 inline GenericStringRef<CharType> StringRef(const CharType *str) {
440  return GenericStringRef<CharType>(str);
441 }
442 
444 
458 template <typename CharType>
459 inline GenericStringRef<CharType> StringRef(const CharType *str,
460  size_t length) {
461  return GenericStringRef<CharType>(str, SizeType(length));
462 }
463 
464 #if RAPIDJSON_HAS_STDSTRING
465 
477 template <typename CharType>
479  const std::basic_string<CharType> &str) {
480  return GenericStringRef<CharType>(str.data(), SizeType(str.size()));
481 }
482 #endif
483 
485 // GenericValue type traits
486 namespace internal {
487 
488 template <typename T, typename Encoding = void, typename Allocator = void>
489 struct IsGenericValueImpl : FalseType {};
490 
491 // select candidates according to nested encoding and allocator types
492 template <typename T>
493 struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type,
494  typename Void<typename T::AllocatorType>::Type>
495  : IsBaseOf<
496  GenericValue<typename T::EncodingType, typename T::AllocatorType>,
497  T>::Type {};
498 
499 // helper to match arbitrary GenericValue instantiations, including derived
500 // classes
501 template <typename T>
503 
504 } // namespace internal
505 
507 // TypeHelper
508 
509 namespace internal {
510 
511 template <typename ValueType, typename T>
512 struct TypeHelper {};
513 
514 template <typename ValueType>
515 struct TypeHelper<ValueType, bool> {
516  static bool Is(const ValueType &v) { return v.IsBool(); }
517  static bool Get(const ValueType &v) { return v.GetBool(); }
518  static ValueType &Set(ValueType &v, bool data) { return v.SetBool(data); }
519  static ValueType &Set(ValueType &v, bool data,
520  typename ValueType::AllocatorType &) {
521  return v.SetBool(data);
522  }
523 };
524 
525 template <typename ValueType>
526 struct TypeHelper<ValueType, int> {
527  static bool Is(const ValueType &v) { return v.IsInt(); }
528  static int Get(const ValueType &v) { return v.GetInt(); }
529  static ValueType &Set(ValueType &v, int data) { return v.SetInt(data); }
530  static ValueType &Set(ValueType &v, int data,
531  typename ValueType::AllocatorType &) {
532  return v.SetInt(data);
533  }
534 };
535 
536 template <typename ValueType>
537 struct TypeHelper<ValueType, unsigned> {
538  static bool Is(const ValueType &v) { return v.IsUint(); }
539  static unsigned Get(const ValueType &v) { return v.GetUint(); }
540  static ValueType &Set(ValueType &v, unsigned data) { return v.SetUint(data); }
541  static ValueType &Set(ValueType &v, unsigned data,
542  typename ValueType::AllocatorType &) {
543  return v.SetUint(data);
544  }
545 };
546 
547 #ifdef _MSC_VER
548 RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int));
549 template <typename ValueType>
550 struct TypeHelper<ValueType, long> {
551  static bool Is(const ValueType &v) { return v.IsInt(); }
552  static long Get(const ValueType &v) { return v.GetInt(); }
553  static ValueType &Set(ValueType &v, long data) { return v.SetInt(data); }
554  static ValueType &Set(ValueType &v, long data,
555  typename ValueType::AllocatorType &) {
556  return v.SetInt(data);
557  }
558 };
559 
560 RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned));
561 template <typename ValueType>
562 struct TypeHelper<ValueType, unsigned long> {
563  static bool Is(const ValueType &v) { return v.IsUint(); }
564  static unsigned long Get(const ValueType &v) { return v.GetUint(); }
565  static ValueType &Set(ValueType &v, unsigned long data) {
566  return v.SetUint(data);
567  }
568  static ValueType &Set(ValueType &v, unsigned long data,
569  typename ValueType::AllocatorType &) {
570  return v.SetUint(data);
571  }
572 };
573 #endif
574 
575 template <typename ValueType>
576 struct TypeHelper<ValueType, int64_t> {
577  static bool Is(const ValueType &v) { return v.IsInt64(); }
578  static int64_t Get(const ValueType &v) { return v.GetInt64(); }
579  static ValueType &Set(ValueType &v, int64_t data) { return v.SetInt64(data); }
580  static ValueType &Set(ValueType &v, int64_t data,
581  typename ValueType::AllocatorType &) {
582  return v.SetInt64(data);
583  }
584 };
585 
586 template <typename ValueType>
587 struct TypeHelper<ValueType, uint64_t> {
588  static bool Is(const ValueType &v) { return v.IsUint64(); }
589  static uint64_t Get(const ValueType &v) { return v.GetUint64(); }
590  static ValueType &Set(ValueType &v, uint64_t data) {
591  return v.SetUint64(data);
592  }
593  static ValueType &Set(ValueType &v, uint64_t data,
594  typename ValueType::AllocatorType &) {
595  return v.SetUint64(data);
596  }
597 };
598 
599 template <typename ValueType>
600 struct TypeHelper<ValueType, double> {
601  static bool Is(const ValueType &v) { return v.IsDouble(); }
602  static double Get(const ValueType &v) { return v.GetDouble(); }
603  static ValueType &Set(ValueType &v, double data) { return v.SetDouble(data); }
604  static ValueType &Set(ValueType &v, double data,
605  typename ValueType::AllocatorType &) {
606  return v.SetDouble(data);
607  }
608 };
609 
610 template <typename ValueType>
611 struct TypeHelper<ValueType, float> {
612  static bool Is(const ValueType &v) { return v.IsFloat(); }
613  static float Get(const ValueType &v) { return v.GetFloat(); }
614  static ValueType &Set(ValueType &v, float data) { return v.SetFloat(data); }
615  static ValueType &Set(ValueType &v, float data,
616  typename ValueType::AllocatorType &) {
617  return v.SetFloat(data);
618  }
619 };
620 
621 template <typename ValueType>
622 struct TypeHelper<ValueType, const typename ValueType::Ch *> {
623  typedef const typename ValueType::Ch *StringType;
624  static bool Is(const ValueType &v) { return v.IsString(); }
625  static StringType Get(const ValueType &v) { return v.GetString(); }
626  static ValueType &Set(ValueType &v, const StringType data) {
627  return v.SetString(typename ValueType::StringRefType(data));
628  }
629  static ValueType &Set(ValueType &v, const StringType data,
630  typename ValueType::AllocatorType &a) {
631  return v.SetString(data, a);
632  }
633 };
634 
635 #if RAPIDJSON_HAS_STDSTRING
636 template <typename ValueType>
637 struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch>> {
638  typedef std::basic_string<typename ValueType::Ch> StringType;
639  static bool Is(const ValueType &v) { return v.IsString(); }
640  static StringType Get(const ValueType &v) {
641  return StringType(v.GetString(), v.GetStringLength());
642  }
643  static ValueType &Set(ValueType &v, const StringType &data,
644  typename ValueType::AllocatorType &a) {
645  return v.SetString(data, a);
646  }
647 };
648 #endif
649 
650 template <typename ValueType>
651 struct TypeHelper<ValueType, typename ValueType::Array> {
652  typedef typename ValueType::Array ArrayType;
653  static bool Is(const ValueType &v) { return v.IsArray(); }
654  static ArrayType Get(ValueType &v) { return v.GetArray(); }
655  static ValueType &Set(ValueType &v, ArrayType data) { return v = data; }
656  static ValueType &Set(ValueType &v, ArrayType data,
657  typename ValueType::AllocatorType &) {
658  return v = data;
659  }
660 };
661 
662 template <typename ValueType>
663 struct TypeHelper<ValueType, typename ValueType::ConstArray> {
664  typedef typename ValueType::ConstArray ArrayType;
665  static bool Is(const ValueType &v) { return v.IsArray(); }
666  static ArrayType Get(const ValueType &v) { return v.GetArray(); }
667 };
668 
669 template <typename ValueType>
670 struct TypeHelper<ValueType, typename ValueType::Object> {
671  typedef typename ValueType::Object ObjectType;
672  static bool Is(const ValueType &v) { return v.IsObject(); }
673  static ObjectType Get(ValueType &v) { return v.GetObject(); }
674  static ValueType &Set(ValueType &v, ObjectType data) { return v = data; }
675  static ValueType &Set(ValueType &v, ObjectType data,
676  typename ValueType::AllocatorType &) {
677  return v = data;
678  }
679 };
680 
681 template <typename ValueType>
682 struct TypeHelper<ValueType, typename ValueType::ConstObject> {
683  typedef typename ValueType::ConstObject ObjectType;
684  static bool Is(const ValueType &v) { return v.IsObject(); }
685  static ObjectType Get(const ValueType &v) { return v.GetObject(); }
686 };
687 
688 } // namespace internal
689 
690 // Forward declarations
691 template <bool, typename>
693 template <bool, typename>
695 
697 // GenericValue
698 
700 
710 template <typename Encoding, typename Allocator = MemoryPoolAllocator<>>
711 class GenericValue {
712  public:
715  typedef Encoding EncodingType;
716  typedef Allocator AllocatorType;
717  typedef typename Encoding::Ch Ch;
718  typedef GenericStringRef<Ch>
724  typedef GenericValue
727  typedef const GenericValue
735 
737 
738 
740  GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
741 
742 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
743  GenericValue(GenericValue &&rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) {
745  rhs.data_.f.flags = kNullFlag; // give up contents
746  }
747 #endif
748 
749  private:
751  GenericValue(const GenericValue &rhs);
752 
753 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
754  template <typename StackAllocator>
757 
759  template <typename StackAllocator>
762 #endif
763 
764  public:
766 
770  explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() {
771  static const uint16_t defaultFlags[] = {
772  kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag,
773  kArrayFlag, kShortStringFlag, kNumberAnyFlag};
774  RAPIDJSON_NOEXCEPT_ASSERT(type >= kNullType && type <= kNumberType);
775  data_.f.flags = defaultFlags[type];
776 
777  // Use ShortString to store empty string.
778  if (type == kStringType) data_.ss.SetLength(0);
779  }
780 
782 
790  template <typename SourceAllocator>
792  Allocator &allocator, bool copyConstStrings = false) {
793  switch (rhs.GetType()) {
794  case kObjectType: {
795  SizeType count = rhs.data_.o.size;
796  Member *lm = reinterpret_cast<Member *>(
797  allocator.Malloc(count * sizeof(Member)));
799  rhs.GetMembersPointer();
800  for (SizeType i = 0; i < count; i++) {
801  new (&lm[i].name)
802  GenericValue(rm[i].name, allocator, copyConstStrings);
803  new (&lm[i].value)
804  GenericValue(rm[i].value, allocator, copyConstStrings);
805  }
806  data_.f.flags = kObjectFlag;
807  data_.o.size = data_.o.capacity = count;
808  SetMembersPointer(lm);
809  } break;
810  case kArrayType: {
811  SizeType count = rhs.data_.a.size;
812  GenericValue *le = reinterpret_cast<GenericValue *>(
813  allocator.Malloc(count * sizeof(GenericValue)));
815  rhs.GetElementsPointer();
816  for (SizeType i = 0; i < count; i++)
817  new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
818  data_.f.flags = kArrayFlag;
819  data_.a.size = data_.a.capacity = count;
820  SetElementsPointer(le);
821  } break;
822  case kStringType:
823  if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
824  data_.f.flags = rhs.data_.f.flags;
825  data_ = *reinterpret_cast<const Data *>(&rhs.data_);
826  } else
827  SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()),
828  allocator);
829  break;
830  default:
831  data_.f.flags = rhs.data_.f.flags;
832  data_ = *reinterpret_cast<const Data *>(&rhs.data_);
833  break;
834  }
835  }
836 
838 
844 #ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
845  template <typename T>
846  explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>)))
847  RAPIDJSON_NOEXCEPT // See #472
848 #else
849  explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT
850 #endif
851  : data_() {
852  // safe-guard against failing SFINAE
854  data_.f.flags = b ? kTrueFlag : kFalseFlag;
855  }
856 
858  explicit GenericValue(int i) RAPIDJSON_NOEXCEPT : data_() {
859  data_.n.i64 = i;
860  data_.f.flags =
861  (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
862  }
863 
865  explicit GenericValue(unsigned u) RAPIDJSON_NOEXCEPT : data_() {
866  data_.n.u64 = u;
867  data_.f.flags = (u & 0x80000000)
868  ? kNumberUintFlag
869  : (kNumberUintFlag | kIntFlag | kInt64Flag);
870  }
871 
873  explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_() {
874  data_.n.i64 = i64;
875  data_.f.flags = kNumberInt64Flag;
876  if (i64 >= 0) {
877  data_.f.flags |= kNumberUint64Flag;
878  if (!(static_cast<uint64_t>(i64) &
879  RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
880  data_.f.flags |= kUintFlag;
881  if (!(static_cast<uint64_t>(i64) &
882  RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
883  data_.f.flags |= kIntFlag;
884  } else if (i64 >= static_cast<int64_t>(
885  RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
886  data_.f.flags |= kIntFlag;
887  }
888 
890  explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_() {
891  data_.n.u64 = u64;
892  data_.f.flags = kNumberUint64Flag;
893  if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
894  data_.f.flags |= kInt64Flag;
895  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
896  data_.f.flags |= kUintFlag;
897  if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
898  data_.f.flags |= kIntFlag;
899  }
900 
902  explicit GenericValue(double d) RAPIDJSON_NOEXCEPT : data_() {
903  data_.n.d = d;
904  data_.f.flags = kNumberDoubleFlag;
905  }
906 
908  explicit GenericValue(float f) RAPIDJSON_NOEXCEPT : data_() {
909  data_.n.d = static_cast<double>(f);
910  data_.f.flags = kNumberDoubleFlag;
911  }
912 
914  GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT : data_() {
915  SetStringRaw(StringRef(s, length));
916  }
917 
919  explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_() {
920  SetStringRaw(s);
921  }
922 
924  GenericValue(const Ch *s, SizeType length, Allocator &allocator) : data_() {
925  SetStringRaw(StringRef(s, length), allocator);
926  }
927 
929  GenericValue(const Ch *s, Allocator &allocator) : data_() {
930  SetStringRaw(StringRef(s), allocator);
931  }
932 
933 #if RAPIDJSON_HAS_STDSTRING
934 
939  GenericValue(const std::basic_string<Ch> &s, Allocator &allocator) : data_() {
940  SetStringRaw(StringRef(s), allocator);
941  }
942 #endif
943 
945 
951  GenericValue(Array a) RAPIDJSON_NOEXCEPT : data_(a.value_.data_) {
952  a.value_.data_ = Data();
953  a.value_.data_.f.flags = kArrayFlag;
954  }
955 
957 
963  GenericValue(Object o) RAPIDJSON_NOEXCEPT : data_(o.value_.data_) {
964  o.value_.data_ = Data();
965  o.value_.data_.f.flags = kObjectFlag;
966  }
967 
969 
972  if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
973  switch (data_.f.flags) {
974  case kArrayFlag: {
975  GenericValue *e = GetElementsPointer();
976  for (GenericValue *v = e; v != e + data_.a.size; ++v)
977  v->~GenericValue();
978  Allocator::Free(e);
979  } break;
980 
981  case kObjectFlag:
982  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
983  m->~Member();
984  Allocator::Free(GetMembersPointer());
985  break;
986 
987  case kCopyStringFlag:
988  Allocator::Free(const_cast<Ch *>(GetStringPointer()));
989  break;
990 
991  default:
992  break; // Do nothing for other types.
993  }
994  }
995  }
996 
998 
1000 
1001 
1003 
1006  GenericValue &operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT {
1007  if (RAPIDJSON_LIKELY(this != &rhs)) {
1008  this->~GenericValue();
1009  RawAssign(rhs);
1010  }
1011  return *this;
1012  }
1013 
1014 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1015  GenericValue &operator=(GenericValue &&rhs) RAPIDJSON_NOEXCEPT {
1017  return *this = rhs.Move();
1018  }
1019 #endif
1020 
1022 
1026  GenericValue &operator=(StringRefType str) RAPIDJSON_NOEXCEPT {
1027  GenericValue s(str);
1028  return *this = s;
1029  }
1030 
1032 
1043  template <typename T>
1044  RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (GenericValue &))
1045  operator=(T value) {
1046  GenericValue v(value);
1047  return *this = v;
1048  }
1049 
1051 
1058  template <typename SourceAllocator>
1060  Allocator &allocator, bool copyConstStrings = false) {
1061  RAPIDJSON_ASSERT(static_cast<void *>(this) !=
1062  static_cast<void const *>(&rhs));
1063  this->~GenericValue();
1064  new (this) GenericValue(rhs, allocator, copyConstStrings);
1065  return *this;
1066  }
1067 
1069 
1073  GenericValue &Swap(GenericValue &other) RAPIDJSON_NOEXCEPT {
1074  GenericValue temp;
1075  temp.RawAssign(*this);
1076  RawAssign(other);
1077  other.RawAssign(temp);
1078  return *this;
1079  }
1080 
1082 
1091  friend inline void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT {
1092  a.Swap(b);
1093  }
1094 
1096 
1097  GenericValue &Move() RAPIDJSON_NOEXCEPT { return *this; }
1099 
1101 
1102 
1109  template <typename SourceAllocator>
1110  bool operator==(const GenericValue<Encoding, SourceAllocator> &rhs) const {
1112  if (GetType() != rhs.GetType()) return false;
1113 
1114  switch (GetType()) {
1115  case kObjectType: // Warning: O(n^2) inner-loop
1116  if (data_.o.size != rhs.data_.o.size) return false;
1117  for (ConstMemberIterator lhsMemberItr = MemberBegin();
1118  lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
1119  typename RhsType::ConstMemberIterator rhsMemberItr =
1120  rhs.FindMember(lhsMemberItr->name);
1121  if (rhsMemberItr == rhs.MemberEnd() ||
1122  lhsMemberItr->value != rhsMemberItr->value)
1123  return false;
1124  }
1125  return true;
1126 
1127  case kArrayType:
1128  if (data_.a.size != rhs.data_.a.size) return false;
1129  for (SizeType i = 0; i < data_.a.size; i++)
1130  if ((*this)[i] != rhs[i]) return false;
1131  return true;
1132 
1133  case kStringType:
1134  return StringEqual(rhs);
1135 
1136  case kNumberType:
1137  if (IsDouble() || rhs.IsDouble()) {
1138  double a = GetDouble(); // May convert from integer to double.
1139  double b = rhs.GetDouble(); // Ditto
1140  return a >= b && a <= b; // Prevent -Wfloat-equal
1141  } else
1142  return data_.n.u64 == rhs.data_.n.u64;
1143 
1144  default:
1145  return true;
1146  }
1147  }
1148 
1150  bool operator==(const Ch *rhs) const {
1151  return *this == GenericValue(StringRef(rhs));
1152  }
1153 
1154 #if RAPIDJSON_HAS_STDSTRING
1155 
1159  bool operator==(const std::basic_string<Ch> &rhs) const {
1160  return *this == GenericValue(StringRef(rhs));
1161  }
1162 #endif
1163 
1165 
1168  template <typename T>
1170  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
1171  (bool))
1172  operator==(const T &rhs) const {
1173  return *this == GenericValue(rhs);
1174  }
1175 
1177 
1179  template <typename SourceAllocator>
1180  bool operator!=(const GenericValue<Encoding, SourceAllocator> &rhs) const {
1181  return !(*this == rhs);
1182  }
1183 
1185  bool operator!=(const Ch *rhs) const { return !(*this == rhs); }
1186 
1188 
1190  template <typename T>
1192  operator!=(const T &rhs) const {
1193  return !(*this == rhs);
1194  }
1195 
1197 
1199  template <typename T>
1201  operator==(const T &lhs, const GenericValue &rhs) {
1202  return rhs == lhs;
1203  }
1204 
1206 
1208  template <typename T>
1210  operator!=(const T &lhs, const GenericValue &rhs) {
1211  return !(rhs == lhs);
1212  }
1214 
1216 
1217 
1218  Type GetType() const { return static_cast<Type>(data_.f.flags & kTypeMask); }
1219  bool IsNull() const { return data_.f.flags == kNullFlag; }
1220  bool IsFalse() const { return data_.f.flags == kFalseFlag; }
1221  bool IsTrue() const { return data_.f.flags == kTrueFlag; }
1222  bool IsBool() const { return (data_.f.flags & kBoolFlag) != 0; }
1223  bool IsObject() const { return data_.f.flags == kObjectFlag; }
1224  bool IsArray() const { return data_.f.flags == kArrayFlag; }
1225  bool IsNumber() const { return (data_.f.flags & kNumberFlag) != 0; }
1226  bool IsInt() const { return (data_.f.flags & kIntFlag) != 0; }
1227  bool IsUint() const { return (data_.f.flags & kUintFlag) != 0; }
1228  bool IsInt64() const { return (data_.f.flags & kInt64Flag) != 0; }
1229  bool IsUint64() const { return (data_.f.flags & kUint64Flag) != 0; }
1230  bool IsDouble() const { return (data_.f.flags & kDoubleFlag) != 0; }
1231  bool IsString() const { return (data_.f.flags & kStringFlag) != 0; }
1232 
1233  // Checks whether a number can be losslessly converted to a double.
1234  bool IsLosslessDouble() const {
1235  if (!IsNumber()) return false;
1236  if (IsUint64()) {
1237  uint64_t u = GetUint64();
1238  volatile double d = static_cast<double>(u);
1239  return (d >= 0.0) &&
1240  (d <
1241  static_cast<double>((std::numeric_limits<uint64_t>::max)())) &&
1242  (u == static_cast<uint64_t>(d));
1243  }
1244  if (IsInt64()) {
1245  int64_t i = GetInt64();
1246  volatile double d = static_cast<double>(i);
1247  return (d >=
1248  static_cast<double>((std::numeric_limits<int64_t>::min)())) &&
1249  (d < static_cast<double>((std::numeric_limits<int64_t>::max)())) &&
1250  (i == static_cast<int64_t>(d));
1251  }
1252  return true; // double, int, uint are always lossless
1253  }
1254 
1255  // Checks whether a number is a float (possible lossy).
1256  bool IsFloat() const {
1257  if ((data_.f.flags & kDoubleFlag) == 0) return false;
1258  double d = GetDouble();
1259  return d >= -3.4028234e38 && d <= 3.4028234e38;
1260  }
1261  // Checks whether a number can be losslessly converted to a float.
1262  bool IsLosslessFloat() const {
1263  if (!IsNumber()) return false;
1264  double a = GetDouble();
1265  if (a < static_cast<double>(-(std::numeric_limits<float>::max)()) ||
1266  a > static_cast<double>((std::numeric_limits<float>::max)()))
1267  return false;
1268  double b = static_cast<double>(static_cast<float>(a));
1269  return a >= b && a <= b; // Prevent -Wfloat-equal
1270  }
1271 
1273 
1275 
1276 
1277  GenericValue &SetNull() {
1278  this->~GenericValue();
1279  new (this) GenericValue();
1280  return *this;
1281  }
1282 
1284 
1286 
1287 
1288  bool GetBool() const {
1289  RAPIDJSON_ASSERT(IsBool());
1290  return data_.f.flags == kTrueFlag;
1291  }
1293 
1294  GenericValue &SetBool(bool b) {
1295  this->~GenericValue();
1296  new (this) GenericValue(b);
1297  return *this;
1298  }
1299 
1301 
1303 
1304 
1306 
1307  GenericValue &SetObject() {
1308  this->~GenericValue();
1309  new (this) GenericValue(kObjectType);
1310  return *this;
1311  }
1312 
1314  SizeType MemberCount() const {
1315  RAPIDJSON_ASSERT(IsObject());
1316  return data_.o.size;
1317  }
1318 
1320  SizeType MemberCapacity() const {
1321  RAPIDJSON_ASSERT(IsObject());
1322  return data_.o.capacity;
1323  }
1324 
1326  bool ObjectEmpty() const {
1327  RAPIDJSON_ASSERT(IsObject());
1328  return data_.o.size == 0;
1329  }
1330 
1332 
1340  template <typename T>
1342  (internal::NotExpr<
1343  internal::IsSame<typename internal::RemoveConst<T>::Type, Ch>>),
1344  (GenericValue &))
1345  operator[](T *name) {
1346  GenericValue n(StringRef(name));
1347  return (*this)[n];
1348  }
1349  template <typename T>
1351  (internal::NotExpr<
1352  internal::IsSame<typename internal::RemoveConst<T>::Type, Ch>>),
1353  (const GenericValue &))
1354  operator[](T *name) const {
1355  return const_cast<GenericValue &>(*this)[name];
1356  }
1357 
1359 
1368  template <typename SourceAllocator>
1369  GenericValue &operator[](
1371  MemberIterator member = FindMember(name);
1372  if (member != MemberEnd())
1373  return member->value;
1374  else {
1375  RAPIDJSON_ASSERT(false); // see above note
1376 
1377  // This will generate -Wexit-time-destructors in clang
1378  // static GenericValue NullValue;
1379  // return NullValue;
1380 
1381  // Use static buffer and placement-new to prevent destruction
1382  static char buffer[sizeof(GenericValue)];
1383  return *new (buffer) GenericValue();
1384  }
1385  }
1386  template <typename SourceAllocator>
1387  const GenericValue &operator[](
1388  const GenericValue<Encoding, SourceAllocator> &name) const {
1389  return const_cast<GenericValue &>(*this)[name];
1390  }
1391 
1392 #if RAPIDJSON_HAS_STDSTRING
1393  GenericValue &operator[](const std::basic_string<Ch> &name) {
1395  return (*this)[GenericValue(StringRef(name))];
1396  }
1397  const GenericValue &operator[](const std::basic_string<Ch> &name) const {
1398  return (*this)[GenericValue(StringRef(name))];
1399  }
1400 #endif
1401 
1403 
1404  ConstMemberIterator MemberBegin() const {
1405  RAPIDJSON_ASSERT(IsObject());
1406  return ConstMemberIterator(GetMembersPointer());
1407  }
1409 
1410  ConstMemberIterator MemberEnd() const {
1411  RAPIDJSON_ASSERT(IsObject());
1412  return ConstMemberIterator(GetMembersPointer() + data_.o.size);
1413  }
1415 
1416  MemberIterator MemberBegin() {
1417  RAPIDJSON_ASSERT(IsObject());
1418  return MemberIterator(GetMembersPointer());
1419  }
1421 
1422  MemberIterator MemberEnd() {
1423  RAPIDJSON_ASSERT(IsObject());
1424  return MemberIterator(GetMembersPointer() + data_.o.size);
1425  }
1426 
1428 
1433  GenericValue &MemberReserve(SizeType newCapacity, Allocator &allocator) {
1434  RAPIDJSON_ASSERT(IsObject());
1435  if (newCapacity > data_.o.capacity) {
1436  SetMembersPointer(reinterpret_cast<Member *>(allocator.Realloc(
1437  GetMembersPointer(), data_.o.capacity * sizeof(Member),
1438  newCapacity * sizeof(Member))));
1439  data_.o.capacity = newCapacity;
1440  }
1441  return *this;
1442  }
1443 
1445 
1452  bool HasMember(const Ch *name) const {
1453  return FindMember(name) != MemberEnd();
1454  }
1455 
1456 #if RAPIDJSON_HAS_STDSTRING
1457 
1465  bool HasMember(const std::basic_string<Ch> &name) const {
1466  return FindMember(name) != MemberEnd();
1467  }
1468 #endif
1469 
1471 
1479  template <typename SourceAllocator>
1480  bool HasMember(const GenericValue<Encoding, SourceAllocator> &name) const {
1481  return FindMember(name) != MemberEnd();
1482  }
1483 
1485 
1496  MemberIterator FindMember(const Ch *name) {
1497  GenericValue n(StringRef(name));
1498  return FindMember(n);
1499  }
1500 
1501  ConstMemberIterator FindMember(const Ch *name) const {
1502  return const_cast<GenericValue &>(*this).FindMember(name);
1503  }
1504 
1506 
1518  template <typename SourceAllocator>
1519  MemberIterator FindMember(
1521  RAPIDJSON_ASSERT(IsObject());
1522  RAPIDJSON_ASSERT(name.IsString());
1523  MemberIterator member = MemberBegin();
1524  for (; member != MemberEnd(); ++member)
1525  if (name.StringEqual(member->name)) break;
1526  return member;
1527  }
1528  template <typename SourceAllocator>
1529  ConstMemberIterator FindMember(
1530  const GenericValue<Encoding, SourceAllocator> &name) const {
1531  return const_cast<GenericValue &>(*this).FindMember(name);
1532  }
1533 
1534 #if RAPIDJSON_HAS_STDSTRING
1535 
1542  MemberIterator FindMember(const std::basic_string<Ch> &name) {
1543  return FindMember(GenericValue(StringRef(name)));
1544  }
1545  ConstMemberIterator FindMember(const std::basic_string<Ch> &name) const {
1546  return FindMember(GenericValue(StringRef(name)));
1547  }
1548 #endif
1549 
1551 
1560  GenericValue &AddMember(GenericValue &name, GenericValue &value,
1561  Allocator &allocator) {
1562  RAPIDJSON_ASSERT(IsObject());
1563  RAPIDJSON_ASSERT(name.IsString());
1564 
1565  ObjectData &o = data_.o;
1566  if (o.size >= o.capacity)
1567  MemberReserve(o.capacity == 0 ? kDefaultObjectCapacity
1568  : (o.capacity + (o.capacity + 1) / 2),
1569  allocator);
1570  Member *members = GetMembersPointer();
1571  members[o.size].name.RawAssign(name);
1572  members[o.size].value.RawAssign(value);
1573  o.size++;
1574  return *this;
1575  }
1576 
1578 
1587  GenericValue &AddMember(GenericValue &name, StringRefType value,
1588  Allocator &allocator) {
1589  GenericValue v(value);
1590  return AddMember(name, v, allocator);
1591  }
1592 
1593 #if RAPIDJSON_HAS_STDSTRING
1594 
1604  GenericValue &AddMember(GenericValue &name, std::basic_string<Ch> &value,
1605  Allocator &allocator) {
1606  GenericValue v(value, allocator);
1607  return AddMember(name, v, allocator);
1608  }
1609 #endif
1610 
1612 
1628  template <typename T>
1630  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
1631  (GenericValue &))
1632  AddMember(GenericValue &name, T value, Allocator &allocator) {
1633  GenericValue v(value);
1634  return AddMember(name, v, allocator);
1635  }
1636 
1637 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1638  GenericValue &AddMember(GenericValue &&name, GenericValue &&value,
1639  Allocator &allocator) {
1640  return AddMember(name, value, allocator);
1641  }
1642  GenericValue &AddMember(GenericValue &&name, GenericValue &value,
1643  Allocator &allocator) {
1644  return AddMember(name, value, allocator);
1645  }
1646  GenericValue &AddMember(GenericValue &name, GenericValue &&value,
1647  Allocator &allocator) {
1648  return AddMember(name, value, allocator);
1649  }
1650  GenericValue &AddMember(StringRefType name, GenericValue &&value,
1651  Allocator &allocator) {
1652  GenericValue n(name);
1653  return AddMember(n, value, allocator);
1654  }
1655 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1656 
1658 
1666  GenericValue &AddMember(StringRefType name, GenericValue &value,
1667  Allocator &allocator) {
1668  GenericValue n(name);
1669  return AddMember(n, value, allocator);
1670  }
1671 
1673 
1682  GenericValue &AddMember(StringRefType name, StringRefType value,
1683  Allocator &allocator) {
1684  GenericValue v(value);
1685  return AddMember(name, v, allocator);
1686  }
1687 
1689 
1705  template <typename T>
1707  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
1708  (GenericValue &))
1709  AddMember(StringRefType name, T value, Allocator &allocator) {
1710  GenericValue n(name);
1711  return AddMember(n, value, allocator);
1712  }
1713 
1715 
1718  void RemoveAllMembers() {
1719  RAPIDJSON_ASSERT(IsObject());
1720  for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m) m->~Member();
1721  data_.o.size = 0;
1722  }
1723 
1725 
1732  bool RemoveMember(const Ch *name) {
1733  GenericValue n(StringRef(name));
1734  return RemoveMember(n);
1735  }
1736 
1737 #if RAPIDJSON_HAS_STDSTRING
1738  bool RemoveMember(const std::basic_string<Ch> &name) {
1739  return RemoveMember(GenericValue(StringRef(name)));
1740  }
1741 #endif
1742 
1743  template <typename SourceAllocator>
1744  bool RemoveMember(const GenericValue<Encoding, SourceAllocator> &name) {
1745  MemberIterator m = FindMember(name);
1746  if (m != MemberEnd()) {
1747  RemoveMember(m);
1748  return true;
1749  } else
1750  return false;
1751  }
1752 
1754 
1761  MemberIterator RemoveMember(MemberIterator m) {
1762  RAPIDJSON_ASSERT(IsObject());
1763  RAPIDJSON_ASSERT(data_.o.size > 0);
1764  RAPIDJSON_ASSERT(GetMembersPointer() != 0);
1765  RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd());
1766 
1767  MemberIterator last(GetMembersPointer() + (data_.o.size - 1));
1768  if (data_.o.size > 1 && m != last)
1769  *m = *last; // Move the last one to this place
1770  else
1771  m->~Member(); // Only one left, just destroy
1772  --data_.o.size;
1773  return m;
1774  }
1775 
1777 
1786  MemberIterator EraseMember(ConstMemberIterator pos) {
1787  return EraseMember(pos, pos + 1);
1788  }
1789 
1791 
1798  MemberIterator EraseMember(ConstMemberIterator first,
1799  ConstMemberIterator last) {
1800  RAPIDJSON_ASSERT(IsObject());
1801  RAPIDJSON_ASSERT(data_.o.size > 0);
1802  RAPIDJSON_ASSERT(GetMembersPointer() != 0);
1803  RAPIDJSON_ASSERT(first >= MemberBegin());
1804  RAPIDJSON_ASSERT(first <= last);
1805  RAPIDJSON_ASSERT(last <= MemberEnd());
1806 
1807  MemberIterator pos = MemberBegin() + (first - MemberBegin());
1808  for (MemberIterator itr = pos; itr != last; ++itr) itr->~Member();
1809  std::memmove(static_cast<void *>(&*pos), &*last,
1810  static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
1811  data_.o.size -= static_cast<SizeType>(last - first);
1812  return pos;
1813  }
1814 
1816 
1820  bool EraseMember(const Ch *name) {
1821  GenericValue n(StringRef(name));
1822  return EraseMember(n);
1823  }
1824 
1825 #if RAPIDJSON_HAS_STDSTRING
1826  bool EraseMember(const std::basic_string<Ch> &name) {
1827  return EraseMember(GenericValue(StringRef(name)));
1828  }
1829 #endif
1830 
1831  template <typename SourceAllocator>
1832  bool EraseMember(const GenericValue<Encoding, SourceAllocator> &name) {
1833  MemberIterator m = FindMember(name);
1834  if (m != MemberEnd()) {
1835  EraseMember(m);
1836  return true;
1837  } else
1838  return false;
1839  }
1840 
1841  Object GetObject() {
1842  RAPIDJSON_ASSERT(IsObject());
1843  return Object(*this);
1844  }
1845  ConstObject GetObject() const {
1846  RAPIDJSON_ASSERT(IsObject());
1847  return ConstObject(*this);
1848  }
1849 
1851 
1853 
1854 
1856 
1857  GenericValue &SetArray() {
1858  this->~GenericValue();
1859  new (this) GenericValue(kArrayType);
1860  return *this;
1861  }
1862 
1864  SizeType Size() const {
1865  RAPIDJSON_ASSERT(IsArray());
1866  return data_.a.size;
1867  }
1868 
1870  SizeType Capacity() const {
1871  RAPIDJSON_ASSERT(IsArray());
1872  return data_.a.capacity;
1873  }
1874 
1876  bool Empty() const {
1877  RAPIDJSON_ASSERT(IsArray());
1878  return data_.a.size == 0;
1879  }
1880 
1882 
1885  void Clear() {
1886  RAPIDJSON_ASSERT(IsArray());
1887  GenericValue *e = GetElementsPointer();
1888  for (GenericValue *v = e; v != e + data_.a.size; ++v) v->~GenericValue();
1889  data_.a.size = 0;
1890  }
1891 
1893 
1897  GenericValue &operator[](SizeType index) {
1898  RAPIDJSON_ASSERT(IsArray());
1899  RAPIDJSON_ASSERT(index < data_.a.size);
1900  return GetElementsPointer()[index];
1901  }
1902  const GenericValue &operator[](SizeType index) const {
1903  return const_cast<GenericValue &>(*this)[index];
1904  }
1905 
1907 
1908  ValueIterator Begin() {
1909  RAPIDJSON_ASSERT(IsArray());
1910  return GetElementsPointer();
1911  }
1913 
1914  ValueIterator End() {
1915  RAPIDJSON_ASSERT(IsArray());
1916  return GetElementsPointer() + data_.a.size;
1917  }
1919 
1920  ConstValueIterator Begin() const {
1921  return const_cast<GenericValue &>(*this).Begin();
1922  }
1924 
1925  ConstValueIterator End() const {
1926  return const_cast<GenericValue &>(*this).End();
1927  }
1928 
1930 
1935  GenericValue &Reserve(SizeType newCapacity, Allocator &allocator) {
1936  RAPIDJSON_ASSERT(IsArray());
1937  if (newCapacity > data_.a.capacity) {
1938  SetElementsPointer(reinterpret_cast<GenericValue *>(allocator.Realloc(
1939  GetElementsPointer(), data_.a.capacity * sizeof(GenericValue),
1940  newCapacity * sizeof(GenericValue))));
1941  data_.a.capacity = newCapacity;
1942  }
1943  return *this;
1944  }
1945 
1947 
1956  GenericValue &PushBack(GenericValue &value, Allocator &allocator) {
1957  RAPIDJSON_ASSERT(IsArray());
1958  if (data_.a.size >= data_.a.capacity)
1959  Reserve(data_.a.capacity == 0
1960  ? kDefaultArrayCapacity
1961  : (data_.a.capacity + (data_.a.capacity + 1) / 2),
1962  allocator);
1963  GetElementsPointer()[data_.a.size++].RawAssign(value);
1964  return *this;
1965  }
1966 
1967 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1968  GenericValue &PushBack(GenericValue &&value, Allocator &allocator) {
1969  return PushBack(value, allocator);
1970  }
1971 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1972 
1974 
1982  GenericValue &PushBack(StringRefType value, Allocator &allocator) {
1983  return (*this).template PushBack<StringRefType>(value, allocator);
1984  }
1985 
1987 
2004  template <typename T>
2006  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
2007  (GenericValue &))
2008  PushBack(T value, Allocator &allocator) {
2009  GenericValue v(value);
2010  return PushBack(v, allocator);
2011  }
2012 
2014 
2017  GenericValue &PopBack() {
2018  RAPIDJSON_ASSERT(IsArray());
2019  RAPIDJSON_ASSERT(!Empty());
2020  GetElementsPointer()[--data_.a.size].~GenericValue();
2021  return *this;
2022  }
2023 
2025 
2032  ValueIterator Erase(ConstValueIterator pos) { return Erase(pos, pos + 1); }
2033 
2035 
2043  RAPIDJSON_ASSERT(IsArray());
2044  RAPIDJSON_ASSERT(data_.a.size > 0);
2045  RAPIDJSON_ASSERT(GetElementsPointer() != 0);
2046  RAPIDJSON_ASSERT(first >= Begin());
2047  RAPIDJSON_ASSERT(first <= last);
2048  RAPIDJSON_ASSERT(last <= End());
2049  ValueIterator pos = Begin() + (first - Begin());
2050  for (ValueIterator itr = pos; itr != last; ++itr) itr->~GenericValue();
2051  std::memmove(static_cast<void *>(pos), last,
2052  static_cast<size_t>(End() - last) * sizeof(GenericValue));
2053  data_.a.size -= static_cast<SizeType>(last - first);
2054  return pos;
2055  }
2056 
2057  Array GetArray() {
2058  RAPIDJSON_ASSERT(IsArray());
2059  return Array(*this);
2060  }
2061  ConstArray GetArray() const {
2062  RAPIDJSON_ASSERT(IsArray());
2063  return ConstArray(*this);
2064  }
2065 
2067 
2069 
2070 
2071  int GetInt() const {
2072  RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
2073  return data_.n.i.i;
2074  }
2075  unsigned GetUint() const {
2076  RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
2077  return data_.n.u.u;
2078  }
2079  int64_t GetInt64() const {
2080  RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
2081  return data_.n.i64;
2082  }
2083  uint64_t GetUint64() const {
2084  RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
2085  return data_.n.u64;
2086  }
2087 
2089 
2092  double GetDouble() const {
2093  RAPIDJSON_ASSERT(IsNumber());
2094  if ((data_.f.flags & kDoubleFlag) != 0)
2095  return data_.n.d; // exact type, no conversion.
2096  if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double
2097  if ((data_.f.flags & kUintFlag) != 0)
2098  return data_.n.u.u; // unsigned -> double
2099  if ((data_.f.flags & kInt64Flag) != 0)
2100  return static_cast<double>(
2101  data_.n.i64); // int64_t -> double (may lose precision)
2102  RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
2103  return static_cast<double>(
2104  data_.n.u64); // uint64_t -> double (may lose precision)
2105  }
2106 
2108 
2111  float GetFloat() const { return static_cast<float>(GetDouble()); }
2112 
2113  GenericValue &SetInt(int i) {
2114  this->~GenericValue();
2115  new (this) GenericValue(i);
2116  return *this;
2117  }
2118  GenericValue &SetUint(unsigned u) {
2119  this->~GenericValue();
2120  new (this) GenericValue(u);
2121  return *this;
2122  }
2123  GenericValue &SetInt64(int64_t i64) {
2124  this->~GenericValue();
2125  new (this) GenericValue(i64);
2126  return *this;
2127  }
2128  GenericValue &SetUint64(uint64_t u64) {
2129  this->~GenericValue();
2130  new (this) GenericValue(u64);
2131  return *this;
2132  }
2133  GenericValue &SetDouble(double d) {
2134  this->~GenericValue();
2135  new (this) GenericValue(d);
2136  return *this;
2137  }
2138  GenericValue &SetFloat(float f) {
2139  this->~GenericValue();
2140  new (this) GenericValue(static_cast<double>(f));
2141  return *this;
2142  }
2143 
2145 
2147 
2148 
2149  const Ch *GetString() const {
2150  RAPIDJSON_ASSERT(IsString());
2151  return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer();
2152  }
2153 
2155 
2158  SizeType GetStringLength() const {
2159  RAPIDJSON_ASSERT(IsString());
2160  return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength())
2161  : data_.s.length);
2162  }
2163 
2165 
2172  GenericValue &SetString(const Ch *s, SizeType length) {
2173  return SetString(StringRef(s, length));
2174  }
2175 
2177 
2182  GenericValue &SetString(StringRefType s) {
2183  this->~GenericValue();
2184  SetStringRaw(s);
2185  return *this;
2186  }
2187 
2189 
2197  GenericValue &SetString(const Ch *s, SizeType length, Allocator &allocator) {
2198  return SetString(StringRef(s, length), allocator);
2199  }
2200 
2202 
2208  GenericValue &SetString(const Ch *s, Allocator &allocator) {
2209  return SetString(StringRef(s), allocator);
2210  }
2211 
2213 
2219  GenericValue &SetString(StringRefType s, Allocator &allocator) {
2220  this->~GenericValue();
2221  SetStringRaw(s, allocator);
2222  return *this;
2223  }
2224 
2225 #if RAPIDJSON_HAS_STDSTRING
2226 
2235  GenericValue &SetString(const std::basic_string<Ch> &s,
2236  Allocator &allocator) {
2237  return SetString(StringRef(s), allocator);
2238  }
2239 #endif
2240 
2242 
2244 
2245 
2247 
2251  template <typename T>
2252  bool Is() const {
2254  }
2255 
2256  template <typename T>
2257  T Get() const {
2259  }
2260 
2261  template <typename T>
2262  T Get() {
2264  }
2265 
2266  template <typename T>
2267  ValueType &Set(const T &data) {
2268  return internal::TypeHelper<ValueType, T>::Set(*this, data);
2269  }
2270 
2271  template <typename T>
2272  ValueType &Set(const T &data, AllocatorType &allocator) {
2273  return internal::TypeHelper<ValueType, T>::Set(*this, data, allocator);
2274  }
2275 
2277 
2279 
2285  template <typename Handler>
2286  bool Accept(Handler &handler) const {
2287  switch (GetType()) {
2288  case kNullType:
2289  return handler.Null();
2290  case kFalseType:
2291  return handler.Bool(false);
2292  case kTrueType:
2293  return handler.Bool(true);
2294 
2295  case kObjectType:
2296  if (RAPIDJSON_UNLIKELY(!handler.StartObject())) return false;
2297  for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
2298  RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of
2299  // name by MemberIterator.
2300  if (RAPIDJSON_UNLIKELY(
2301  !handler.Key(m->name.GetString(), m->name.GetStringLength(),
2302  (m->name.data_.f.flags & kCopyFlag) != 0)))
2303  return false;
2304  if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler))) return false;
2305  }
2306  return handler.EndObject(data_.o.size);
2307 
2308  case kArrayType:
2309  if (RAPIDJSON_UNLIKELY(!handler.StartArray())) return false;
2310  for (const GenericValue *v = Begin(); v != End(); ++v)
2311  if (RAPIDJSON_UNLIKELY(!v->Accept(handler))) return false;
2312  return handler.EndArray(data_.a.size);
2313 
2314  case kStringType:
2315  return handler.String(GetString(), GetStringLength(),
2316  (data_.f.flags & kCopyFlag) != 0);
2317 
2318  default:
2319  RAPIDJSON_ASSERT(GetType() == kNumberType);
2320  if (IsDouble())
2321  return handler.Double(data_.n.d);
2322  else if (IsInt())
2323  return handler.Int(data_.n.i.i);
2324  else if (IsUint())
2325  return handler.Uint(data_.n.u.u);
2326  else if (IsInt64())
2327  return handler.Int64(data_.n.i64);
2328  else
2329  return handler.Uint64(data_.n.u64);
2330  }
2331  }
2332 
2333  private:
2334  template <typename, typename>
2335  friend class GenericValue;
2336  template <typename, typename, typename>
2337  friend class GenericDocument;
2338 
2339  enum {
2340  kBoolFlag = 0x0008,
2341  kNumberFlag = 0x0010,
2342  kIntFlag = 0x0020,
2343  kUintFlag = 0x0040,
2344  kInt64Flag = 0x0080,
2345  kUint64Flag = 0x0100,
2346  kDoubleFlag = 0x0200,
2347  kStringFlag = 0x0400,
2348  kCopyFlag = 0x0800,
2349  kInlineStrFlag = 0x1000,
2350 
2351  // Initial flags of different types.
2368 
2369  kTypeMask = 0x07
2370  };
2371 
2372  static const SizeType kDefaultArrayCapacity = 16;
2374 
2375  struct Flag {
2376 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION
2377  char payload[sizeof(SizeType) * 2 +
2378  6]; // 2 x SizeType + lower 48-bit pointer
2379 #elif RAPIDJSON_64BIT
2380  char payload[sizeof(SizeType) * 2 + sizeof(void *) + 6]; // 6 padding bytes
2381 #else
2382  char payload[sizeof(SizeType) * 2 + sizeof(void *) +
2383  2]; // 2 padding bytes
2384 #endif
2386  };
2387 
2388  struct String {
2391  const Ch *str;
2392  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2393 
2394  // implementation detail: ShortString can represent zero-terminated strings up
2395  // to MaxSize chars (excluding the terminating zero) and store a value to
2396  // determine the length of the contained string in the last character
2397  // str[LenPos] by storing "MaxSize - length" there. If the string to store has
2398  // the maximal length of MaxSize then str[LenPos] will be 0 and therefore act
2399  // as the string terminator as well. For getting the string length back from
2400  // that value just use "MaxSize - str[LenPos]". This allows to store 13-chars
2401  // strings in 32-bit mode, 21-chars strings in 64-bit mode, 13-chars strings
2402  // for RAPIDJSON_48BITPOINTER_OPTIMIZATION=1 inline (for `UTF8`-encoded
2403  // strings).
2404  struct ShortString {
2405  enum {
2406  MaxChars = sizeof(static_cast<Flag *>(0)->payload) / sizeof(Ch),
2407  MaxSize = MaxChars - 1,
2408  LenPos = MaxSize
2409  };
2410  Ch str[MaxChars];
2411 
2412  inline static bool Usable(SizeType len) { return (MaxSize >= len); }
2413  inline void SetLength(SizeType len) {
2414  str[LenPos] = static_cast<Ch>(MaxSize - len);
2415  }
2416  inline SizeType GetLength() const {
2417  return static_cast<SizeType>(MaxSize - str[LenPos]);
2418  }
2419  }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16
2420  // bytes in 64-bit mode
2421 
2422  // By using proper binary layout, retrieval of different integer types do not
2423  // need conversions.
2424  union Number {
2425 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
2426  struct I {
2427  int i;
2428  char padding[4];
2429  } i;
2430  struct U {
2431  unsigned u;
2432  char padding2[4];
2433  } u;
2434 #else
2435  struct I {
2436  char padding[4];
2437  int i;
2438  } i;
2439  struct U {
2440  char padding2[4];
2441  unsigned u;
2442  } u;
2443 #endif
2446  double d;
2447  }; // 8 bytes
2448 
2449  struct ObjectData {
2452  Member *members;
2453  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2454 
2455  struct ArrayData {
2459  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2460 
2461  union Data {
2468  }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit
2469  // with RAPIDJSON_48BITPOINTER_OPTIMIZATION
2470 
2471  RAPIDJSON_FORCEINLINE const Ch *GetStringPointer() const {
2472  return RAPIDJSON_GETPOINTER(Ch, data_.s.str);
2473  }
2474  RAPIDJSON_FORCEINLINE const Ch *SetStringPointer(const Ch *str) {
2475  return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str);
2476  }
2477  RAPIDJSON_FORCEINLINE GenericValue *GetElementsPointer() const {
2478  return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements);
2479  }
2480  RAPIDJSON_FORCEINLINE GenericValue *SetElementsPointer(
2481  GenericValue *elements) {
2482  return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements);
2483  }
2484  RAPIDJSON_FORCEINLINE Member *GetMembersPointer() const {
2485  return RAPIDJSON_GETPOINTER(Member, data_.o.members);
2486  }
2487  RAPIDJSON_FORCEINLINE Member *SetMembersPointer(Member *members) {
2488  return RAPIDJSON_SETPOINTER(Member, data_.o.members, members);
2489  }
2490 
2491  // Initialize this value as array with initial data, without calling
2492  // destructor.
2493  void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator) {
2494  data_.f.flags = kArrayFlag;
2495  if (count) {
2496  GenericValue *e = static_cast<GenericValue *>(
2497  allocator.Malloc(count * sizeof(GenericValue)));
2498  SetElementsPointer(e);
2499  std::memcpy(static_cast<void *>(e), values, count * sizeof(GenericValue));
2500  } else
2501  SetElementsPointer(0);
2502  data_.a.size = data_.a.capacity = count;
2503  }
2504 
2507  void SetObjectRaw(Member *members, SizeType count, Allocator &allocator) {
2508  data_.f.flags = kObjectFlag;
2509  if (count) {
2510  Member *m =
2511  static_cast<Member *>(allocator.Malloc(count * sizeof(Member)));
2512  SetMembersPointer(m);
2513  std::memcpy(static_cast<void *>(m), members, count * sizeof(Member));
2514  } else
2515  SetMembersPointer(0);
2516  data_.o.size = data_.o.capacity = count;
2517  }
2518 
2520  void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2521  data_.f.flags = kConstStringFlag;
2522  SetStringPointer(s);
2523  data_.s.length = s.length;
2524  }
2525 
2528  void SetStringRaw(StringRefType s, Allocator &allocator) {
2529  Ch *str = 0;
2530  if (ShortString::Usable(s.length)) {
2531  data_.f.flags = kShortStringFlag;
2532  data_.ss.SetLength(s.length);
2533  str = data_.ss.str;
2534  } else {
2535  data_.f.flags = kCopyStringFlag;
2536  data_.s.length = s.length;
2537  str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2538  SetStringPointer(str);
2539  }
2540  std::memcpy(str, s, s.length * sizeof(Ch));
2541  str[s.length] = '\0';
2542  }
2543 
2545  void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT {
2546  data_ = rhs.data_;
2547  // data_.f.flags = rhs.data_.f.flags;
2548  rhs.data_.f.flags = kNullFlag;
2549  }
2550 
2551  template <typename SourceAllocator>
2553  RAPIDJSON_ASSERT(IsString());
2554  RAPIDJSON_ASSERT(rhs.IsString());
2555 
2556  const SizeType len1 = GetStringLength();
2557  const SizeType len2 = rhs.GetStringLength();
2558  if (len1 != len2) {
2559  return false;
2560  }
2561 
2562  const Ch *const str1 = GetString();
2563  const Ch *const str2 = rhs.GetString();
2564  if (str1 == str2) {
2565  return true;
2566  } // fast path for constant string
2567 
2568  return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
2569  }
2570 
2571  Data data_;
2572 };
2573 
2576 
2578 // GenericDocument
2579 
2581 
2591 template <typename Encoding, typename Allocator = MemoryPoolAllocator<>,
2592  typename StackAllocator = CrtAllocator>
2593 class GenericDocument : public GenericValue<Encoding, Allocator> {
2594  public:
2595  typedef typename Encoding::Ch Ch;
2598  typedef Allocator AllocatorType;
2599 
2601 
2608  explicit GenericDocument(Type type, Allocator *allocator = 0,
2609  size_t stackCapacity = kDefaultStackCapacity,
2610  StackAllocator *stackAllocator = 0)
2611  : GenericValue<Encoding, Allocator>(type),
2612  allocator_(allocator),
2613  ownAllocator_(0),
2614  stack_(stackAllocator, stackCapacity),
2615  parseResult_() {
2616  if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2617  }
2618 
2620 
2626  GenericDocument(Allocator *allocator = 0,
2627  size_t stackCapacity = kDefaultStackCapacity,
2628  StackAllocator *stackAllocator = 0)
2629  : allocator_(allocator),
2630  ownAllocator_(0),
2631  stack_(stackAllocator, stackCapacity),
2632  parseResult_() {
2633  if (!allocator_) ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2634  }
2635 
2636 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2637  GenericDocument(GenericDocument &&rhs) RAPIDJSON_NOEXCEPT
2639  : ValueType(std::forward<ValueType>(
2640  rhs)), // explicit cast to avoid prohibited move from Document
2641  allocator_(rhs.allocator_),
2642  ownAllocator_(rhs.ownAllocator_),
2643  stack_(std::move(rhs.stack_)),
2644  parseResult_(rhs.parseResult_) {
2645  rhs.allocator_ = 0;
2646  rhs.ownAllocator_ = 0;
2647  rhs.parseResult_ = ParseResult();
2648  }
2649 #endif
2650 
2651  ~GenericDocument() { Destroy(); }
2652 
2653 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2654  GenericDocument &operator=(GenericDocument &&rhs) RAPIDJSON_NOEXCEPT {
2656  // The cast to ValueType is necessary here, because otherwise it would
2657  // attempt to call GenericValue's templated assignment operator.
2658  ValueType::operator=(std::forward<ValueType>(rhs));
2659 
2660  // Calling the destructor here would prematurely call stack_'s destructor
2661  Destroy();
2662 
2663  allocator_ = rhs.allocator_;
2664  ownAllocator_ = rhs.ownAllocator_;
2665  stack_ = std::move(rhs.stack_);
2666  parseResult_ = rhs.parseResult_;
2667 
2668  rhs.allocator_ = 0;
2669  rhs.ownAllocator_ = 0;
2670  rhs.parseResult_ = ParseResult();
2671 
2672  return *this;
2673  }
2674 #endif
2675 
2677 
2682  GenericDocument &Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT {
2683  ValueType::Swap(rhs);
2684  stack_.Swap(rhs.stack_);
2685  internal::Swap(allocator_, rhs.allocator_);
2686  internal::Swap(ownAllocator_, rhs.ownAllocator_);
2687  internal::Swap(parseResult_, rhs.parseResult_);
2688  return *this;
2689  }
2690 
2691  // Allow Swap with ValueType.
2692  // Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
2693  using ValueType::Swap;
2694 
2696 
2705  friend inline void swap(GenericDocument &a,
2706  GenericDocument &b) RAPIDJSON_NOEXCEPT {
2707  a.Swap(b);
2708  }
2709 
2711 
2715  template <typename Generator>
2716  GenericDocument &Populate(Generator &g) {
2717  ClearStackOnExit scope(*this);
2718  if (g(*this)) {
2719  RAPIDJSON_ASSERT(stack_.GetSize() ==
2720  sizeof(ValueType)); // Got one and only one root object
2721  ValueType::operator=(*stack_.template Pop<ValueType>(
2722  1)); // Move value from stack to document
2723  }
2724  return *this;
2725  }
2726 
2729 
2731 
2737  template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
2738  GenericDocument &ParseStream(InputStream &is) {
2740  stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2741  ClearStackOnExit scope(*this);
2742  parseResult_ = reader.template Parse<parseFlags>(is, *this);
2743  if (parseResult_) {
2744  RAPIDJSON_ASSERT(stack_.GetSize() ==
2745  sizeof(ValueType)); // Got one and only one root object
2746  ValueType::operator=(*stack_.template Pop<ValueType>(
2747  1)); // Move value from stack to document
2748  }
2749  return *this;
2750  }
2751 
2753 
2758  template <unsigned parseFlags, typename InputStream>
2759  GenericDocument &ParseStream(InputStream &is) {
2760  return ParseStream<parseFlags, Encoding, InputStream>(is);
2761  }
2762 
2764 
2768  template <typename InputStream>
2769  GenericDocument &ParseStream(InputStream &is) {
2770  return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2771  }
2773 
2776 
2778 
2782  template <unsigned parseFlags>
2785  return ParseStream<parseFlags | kParseInsituFlag>(s);
2786  }
2787 
2789 
2793  return ParseInsitu<kParseDefaultFlags>(str);
2794  }
2796 
2799 
2801 
2805  template <unsigned parseFlags, typename SourceEncoding>
2806  GenericDocument &Parse(const typename SourceEncoding::Ch *str) {
2807  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2809  return ParseStream<parseFlags, SourceEncoding>(s);
2810  }
2811 
2813 
2817  template <unsigned parseFlags>
2818  GenericDocument &Parse(const Ch *str) {
2819  return Parse<parseFlags, Encoding>(str);
2820  }
2821 
2823 
2825  GenericDocument &Parse(const Ch *str) {
2826  return Parse<kParseDefaultFlags>(str);
2827  }
2828 
2829  template <unsigned parseFlags, typename SourceEncoding>
2830  GenericDocument &Parse(const typename SourceEncoding::Ch *str,
2831  size_t length) {
2832  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2833  MemoryStream ms(reinterpret_cast<const char *>(str),
2834  length * sizeof(typename SourceEncoding::Ch));
2836  ParseStream<parseFlags, SourceEncoding>(is);
2837  return *this;
2838  }
2839 
2840  template <unsigned parseFlags>
2841  GenericDocument &Parse(const Ch *str, size_t length) {
2842  return Parse<parseFlags, Encoding>(str, length);
2843  }
2844 
2845  GenericDocument &Parse(const Ch *str, size_t length) {
2846  return Parse<kParseDefaultFlags>(str, length);
2847  }
2848 
2849 #if RAPIDJSON_HAS_STDSTRING
2850  template <unsigned parseFlags, typename SourceEncoding>
2851  GenericDocument &Parse(
2852  const std::basic_string<typename SourceEncoding::Ch> &str) {
2853  // c_str() is constant complexity according to standard. Should be faster
2854  // than Parse(const char*, size_t)
2855  return Parse<parseFlags, SourceEncoding>(str.c_str());
2856  }
2857 
2858  template <unsigned parseFlags>
2859  GenericDocument &Parse(const std::basic_string<Ch> &str) {
2860  return Parse<parseFlags, Encoding>(str.c_str());
2861  }
2862 
2863  GenericDocument &Parse(const std::basic_string<Ch> &str) {
2864  return Parse<kParseDefaultFlags>(str);
2865  }
2866 #endif // RAPIDJSON_HAS_STDSTRING
2867 
2869 
2872 
2874  bool HasParseError() const { return parseResult_.IsError(); }
2875 
2877  ParseErrorCode GetParseError() const { return parseResult_.Code(); }
2878 
2880  size_t GetErrorOffset() const { return parseResult_.Offset(); }
2881 
2883 #ifndef __clang // -Wdocumentation
2884 
2893 #endif
2894  operator ParseResult() const { return parseResult_; }
2896 
2898  Allocator &GetAllocator() {
2899  RAPIDJSON_ASSERT(allocator_);
2900  return *allocator_;
2901  }
2902 
2904  size_t GetStackCapacity() const { return stack_.GetCapacity(); }
2905 
2906  private:
2907  // clear stack on any exit from ParseStream, e.g. due to exception
2909  explicit ClearStackOnExit(GenericDocument &d) : d_(d) {}
2910  ~ClearStackOnExit() { d_.ClearStack(); }
2911 
2912  private:
2916  };
2917 
2918  // callers of the following private Handler functions
2919  // template <typename,typename,typename> friend class GenericReader; // for
2920  // parsing
2921  template <typename, typename>
2922  friend class GenericValue; // for deep copying
2923 
2924  public:
2925  // Implementation of Handler
2926  bool Null() {
2927  new (stack_.template Push<ValueType>()) ValueType();
2928  return true;
2929  }
2930  bool Bool(bool b) {
2931  new (stack_.template Push<ValueType>()) ValueType(b);
2932  return true;
2933  }
2934  bool Int(int i) {
2935  new (stack_.template Push<ValueType>()) ValueType(i);
2936  return true;
2937  }
2938  bool Uint(unsigned i) {
2939  new (stack_.template Push<ValueType>()) ValueType(i);
2940  return true;
2941  }
2942  bool Int64(int64_t i) {
2943  new (stack_.template Push<ValueType>()) ValueType(i);
2944  return true;
2945  }
2946  bool Uint64(uint64_t i) {
2947  new (stack_.template Push<ValueType>()) ValueType(i);
2948  return true;
2949  }
2950  bool Double(double d) {
2951  new (stack_.template Push<ValueType>()) ValueType(d);
2952  return true;
2953  }
2954 
2955  bool RawNumber(const Ch *str, SizeType length, bool copy) {
2956  if (copy)
2957  new (stack_.template Push<ValueType>())
2958  ValueType(str, length, GetAllocator());
2959  else
2960  new (stack_.template Push<ValueType>()) ValueType(str, length);
2961  return true;
2962  }
2963 
2964  bool String(const Ch *str, SizeType length, bool copy) {
2965  if (copy)
2966  new (stack_.template Push<ValueType>())
2967  ValueType(str, length, GetAllocator());
2968  else
2969  new (stack_.template Push<ValueType>()) ValueType(str, length);
2970  return true;
2971  }
2972 
2973  bool StartObject() {
2974  new (stack_.template Push<ValueType>()) ValueType(kObjectType);
2975  return true;
2976  }
2977 
2978  bool Key(const Ch *str, SizeType length, bool copy) {
2979  return String(str, length, copy);
2980  }
2981 
2982  bool EndObject(SizeType memberCount) {
2983  typename ValueType::Member *members =
2984  stack_.template Pop<typename ValueType::Member>(memberCount);
2985  stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount,
2986  GetAllocator());
2987  return true;
2988  }
2989 
2990  bool StartArray() {
2991  new (stack_.template Push<ValueType>()) ValueType(kArrayType);
2992  return true;
2993  }
2994 
2995  bool EndArray(SizeType elementCount) {
2996  ValueType *elements = stack_.template Pop<ValueType>(elementCount);
2997  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount,
2998  GetAllocator());
2999  return true;
3000  }
3001 
3002  private:
3007 
3008  void ClearStack() {
3009  if (Allocator::kNeedFree)
3010  while (stack_.GetSize() >
3011  0) // Here assumes all elements in stack array are GenericValue
3012  // (Member is actually 2 GenericValue objects)
3013  (stack_.template Pop<ValueType>(1))->~ValueType();
3014  else
3015  stack_.Clear();
3016  stack_.ShrinkToFit();
3017  }
3018 
3019  void Destroy() { RAPIDJSON_DELETE(ownAllocator_); }
3020 
3021  static const size_t kDefaultStackCapacity = 1024;
3022  Allocator *allocator_;
3023  Allocator *ownAllocator_;
3026 };
3027 
3030 
3032 
3037 template <bool Const, typename ValueT>
3038 class GenericArray {
3039  public:
3042  typedef ValueT PlainType;
3044  typedef ValueType *ValueIterator; // This may be const or non-const iterator
3045  typedef const ValueT *ConstValueIterator;
3046  typedef typename ValueType::AllocatorType AllocatorType;
3047  typedef typename ValueType::StringRefType StringRefType;
3048 
3049  template <typename, typename>
3050  friend class GenericValue;
3051 
3052  GenericArray(const GenericArray &rhs) : value_(rhs.value_) {}
3054  value_ = rhs.value_;
3055  return *this;
3056  }
3058 
3059  SizeType Size() const { return value_.Size(); }
3060  SizeType Capacity() const { return value_.Capacity(); }
3061  bool Empty() const { return value_.Empty(); }
3062  void Clear() const { value_.Clear(); }
3063  ValueType &operator[](SizeType index) const { return value_[index]; }
3064  ValueIterator Begin() const { return value_.Begin(); }
3065  ValueIterator End() const { return value_.End(); }
3066  GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const {
3067  value_.Reserve(newCapacity, allocator);
3068  return *this;
3069  }
3070  GenericArray PushBack(ValueType &value, AllocatorType &allocator) const {
3071  value_.PushBack(value, allocator);
3072  return *this;
3073  }
3074 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
3075  GenericArray PushBack(ValueType &&value, AllocatorType &allocator) const {
3076  value_.PushBack(value, allocator);
3077  return *this;
3078  }
3079 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
3080  GenericArray PushBack(StringRefType value, AllocatorType &allocator) const {
3081  value_.PushBack(value, allocator);
3082  return *this;
3083  }
3084  template <typename T>
3086  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
3087  (const GenericArray &))
3088  PushBack(T value, AllocatorType &allocator) const {
3089  value_.PushBack(value, allocator);
3090  return *this;
3091  }
3093  value_.PopBack();
3094  return *this;
3095  }
3097  return value_.Erase(pos);
3098  }
3100  return value_.Erase(first, last);
3101  }
3102 
3103 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
3104  ValueIterator begin() const { return value_.Begin(); }
3105  ValueIterator end() const { return value_.End(); }
3106 #endif
3107 
3108  private:
3109  GenericArray();
3110  GenericArray(ValueType &value) : value_(value) {}
3112 };
3113 
3115 
3120 template <bool Const, typename ValueT>
3121 class GenericObject {
3122  public:
3125  typedef ValueT PlainType;
3127  typedef GenericMemberIterator<Const, typename ValueT::EncodingType,
3128  typename ValueT::AllocatorType>
3129  MemberIterator; // This may be const or non-const iterator
3130  typedef GenericMemberIterator<true, typename ValueT::EncodingType,
3131  typename ValueT::AllocatorType>
3133  typedef typename ValueType::AllocatorType AllocatorType;
3134  typedef typename ValueType::StringRefType StringRefType;
3135  typedef typename ValueType::EncodingType EncodingType;
3136  typedef typename ValueType::Ch Ch;
3137 
3138  template <typename, typename>
3139  friend class GenericValue;
3140 
3141  GenericObject(const GenericObject &rhs) : value_(rhs.value_) {}
3143  value_ = rhs.value_;
3144  return *this;
3145  }
3147 
3148  SizeType MemberCount() const { return value_.MemberCount(); }
3149  SizeType MemberCapacity() const { return value_.MemberCapacity(); }
3150  bool ObjectEmpty() const { return value_.ObjectEmpty(); }
3151  template <typename T>
3152  ValueType &operator[](T *name) const {
3153  return value_[name];
3154  }
3155  template <typename SourceAllocator>
3156  ValueType &operator[](
3158  return value_[name];
3159  }
3160 #if RAPIDJSON_HAS_STDSTRING
3161  ValueType &operator[](const std::basic_string<Ch> &name) const {
3162  return value_[name];
3163  }
3164 #endif
3165  MemberIterator MemberBegin() const { return value_.MemberBegin(); }
3166  MemberIterator MemberEnd() const { return value_.MemberEnd(); }
3168  AllocatorType &allocator) const {
3169  value_.MemberReserve(newCapacity, allocator);
3170  return *this;
3171  }
3172  bool HasMember(const Ch *name) const { return value_.HasMember(name); }
3173 #if RAPIDJSON_HAS_STDSTRING
3174  bool HasMember(const std::basic_string<Ch> &name) const {
3175  return value_.HasMember(name);
3176  }
3177 #endif
3178  template <typename SourceAllocator>
3180  const GenericValue<EncodingType, SourceAllocator> &name) const {
3181  return value_.HasMember(name);
3182  }
3183  MemberIterator FindMember(const Ch *name) const {
3184  return value_.FindMember(name);
3185  }
3186  template <typename SourceAllocator>
3188  const GenericValue<EncodingType, SourceAllocator> &name) const {
3189  return value_.FindMember(name);
3190  }
3191 #if RAPIDJSON_HAS_STDSTRING
3192  MemberIterator FindMember(const std::basic_string<Ch> &name) const {
3193  return value_.FindMember(name);
3194  }
3195 #endif
3196  GenericObject AddMember(ValueType &name, ValueType &value,
3197  AllocatorType &allocator) const {
3198  value_.AddMember(name, value, allocator);
3199  return *this;
3200  }
3201  GenericObject AddMember(ValueType &name, StringRefType value,
3202  AllocatorType &allocator) const {
3203  value_.AddMember(name, value, allocator);
3204  return *this;
3205  }
3206 #if RAPIDJSON_HAS_STDSTRING
3207  GenericObject AddMember(ValueType &name, std::basic_string<Ch> &value,
3208  AllocatorType &allocator) const {
3209  value_.AddMember(name, value, allocator);
3210  return *this;
3211  }
3212 #endif
3213  template <typename T>
3215  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
3216  (ValueType &))
3217  AddMember(ValueType &name, T value, AllocatorType &allocator) const {
3218  value_.AddMember(name, value, allocator);
3219  return *this;
3220  }
3221 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
3222  GenericObject AddMember(ValueType &&name, ValueType &&value,
3223  AllocatorType &allocator) const {
3224  value_.AddMember(name, value, allocator);
3225  return *this;
3226  }
3227  GenericObject AddMember(ValueType &&name, ValueType &value,
3228  AllocatorType &allocator) const {
3229  value_.AddMember(name, value, allocator);
3230  return *this;
3231  }
3232  GenericObject AddMember(ValueType &name, ValueType &&value,
3233  AllocatorType &allocator) const {
3234  value_.AddMember(name, value, allocator);
3235  return *this;
3236  }
3237  GenericObject AddMember(StringRefType name, ValueType &&value,
3238  AllocatorType &allocator) const {
3239  value_.AddMember(name, value, allocator);
3240  return *this;
3241  }
3242 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
3244  AllocatorType &allocator) const {
3245  value_.AddMember(name, value, allocator);
3246  return *this;
3247  }
3249  AllocatorType &allocator) const {
3250  value_.AddMember(name, value, allocator);
3251  return *this;
3252  }
3253  template <typename T>
3255  (internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>),
3256  (GenericObject))
3257  AddMember(StringRefType name, T value, AllocatorType &allocator) const {
3258  value_.AddMember(name, value, allocator);
3259  return *this;
3260  }
3261  void RemoveAllMembers() { value_.RemoveAllMembers(); }
3262  bool RemoveMember(const Ch *name) const { return value_.RemoveMember(name); }
3263 #if RAPIDJSON_HAS_STDSTRING
3264  bool RemoveMember(const std::basic_string<Ch> &name) const {
3265  return value_.RemoveMember(name);
3266  }
3267 #endif
3268  template <typename SourceAllocator>
3270  const GenericValue<EncodingType, SourceAllocator> &name) const {
3271  return value_.RemoveMember(name);
3272  }
3274  return value_.RemoveMember(m);
3275  }
3277  return value_.EraseMember(pos);
3278  }
3280  ConstMemberIterator last) const {
3281  return value_.EraseMember(first, last);
3282  }
3283  bool EraseMember(const Ch *name) const { return value_.EraseMember(name); }
3284 #if RAPIDJSON_HAS_STDSTRING
3285  bool EraseMember(const std::basic_string<Ch> &name) const {
3286  return EraseMember(ValueType(StringRef(name)));
3287  }
3288 #endif
3289  template <typename SourceAllocator>
3291  const GenericValue<EncodingType, SourceAllocator> &name) const {
3292  return value_.EraseMember(name);
3293  }
3294 
3295 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
3296  MemberIterator begin() const { return value_.MemberBegin(); }
3297  MemberIterator end() const { return value_.MemberEnd(); }
3298 #endif
3299 
3300  private:
3301  GenericObject();
3302  GenericObject(ValueType &value) : value_(value) {}
3304 };
3305 
3307 RAPIDJSON_DIAG_POP
3308 
3309 #endif // RAPIDJSON_DOCUMENT_H_
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:858
bool RemoveMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:3269
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:179
void SetLength(SizeType len)
Definition: document.h:2413
ValueT PlainType
Definition: document.h:3125
d
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:924
bool Empty() const
Definition: document.h:3061
void Clear() const
Definition: document.h:3062
RAPIDJSON_FORCEINLINE const Ch * GetStringPointer() const
Definition: document.h:2471
Iterator operator--(int)
Definition: document.h:218
SizeType NotNullStrLen(const CharType *str)
Definition: document.h:405
GenericObject(ValueType &value)
Definition: document.h:3302
bool EndArray(SizeType elementCount)
Definition: document.h:2995
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:3043
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:2598
SizeType GetLength() const
Definition: document.h:2416
GenericStringRef(const GenericStringRef &rhs)
Definition: document.h:394
GenericArray PushBack(StringRefType value, AllocatorType &allocator) const
Definition: document.h:3080
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2597
GenericObject AddMember(StringRefType name, ValueType &value, AllocatorType &allocator) const
Definition: document.h:3243
static ValueType & Set(ValueType &v, uint64_t data)
Definition: document.h:590
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:411
Represents an in-memory input byte stream.
Definition: memorystream.h:48
GenericObject AddMember(ValueType &name, ValueType &value, AllocatorType &allocator) const
Definition: document.h:3196
bool String(const Ch *str, SizeType length, bool copy)
Definition: document.h:2964
ValueType * pointer
Definition: document.h:161
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition: document.h:963
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:433
reference Reference
Reference to (const) GenericMember.
Definition: document.h:170
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:148
ValueType::EncodingType EncodingType
Definition: document.h:3135
static bool Is(const ValueType &v)
Definition: document.h:601
ClearStackOnExit(GenericDocument &d)
Definition: document.h:2909
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:306
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:75
GenericArray< true, ValueT > ConstArray
Definition: document.h:3040
object
Definition: rapidjson.h:711
static bool Get(const ValueType &v)
Definition: document.h:517
Pointer ptr_
raw pointer
Definition: document.h:266
f
Helper class for accessing Value of array type.
Definition: document.h:692
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:770
bool StringEqual(const GenericValue< Encoding, SourceAllocator > &rhs) const
Definition: document.h:2552
Read-only string stream.
Definition: fwd.h:60
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2705
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition: document.h:908
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition: document.h:2716
(Constant) member iterator for a JSON object value
Definition: document.h:142
const Ch *const s
plain CharType pointer
Definition: document.h:400
TFSIMD_FORCE_INLINE bool operator==(const Matrix3x3 &m1, const Matrix3x3 &m2)
array
Definition: rapidjson.h:712
static ValueType & Set(ValueType &v, ObjectType data)
Definition: document.h:674
GenericArray PopBack() const
Definition: document.h:3092
static ValueType & Set(ValueType &v, ArrayType data)
Definition: document.h:655
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:152
GenericMemberIterator(Pointer p)
Internal constructor from plain pointer.
Definition: document.h:264
ValueType & operator[](SizeType index) const
Definition: document.h:3063
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition: document.h:2480
XmlRpcServer s
GenericDocument & Parse(const Ch *str, size_t length)
Definition: document.h:2845
GenericDocument & Parse(const Ch *str, size_t length)
Definition: document.h:2841
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:2595
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:2759
ValueType::StringRefType StringRefType
Definition: document.h:3047
internal::Stack< StackAllocator > stack_
Definition: document.h:3024
MemberIterator MemberEnd() const
Definition: document.h:3166
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:59
bool Bool(bool b)
Definition: document.h:2930
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:476
GenericMember< Encoding, Allocator > PlainType
Definition: document.h:147
std::ptrdiff_t difference_type
Definition: document.h:163
static bool Is(const ValueType &v)
Definition: document.h:588
ValueIterator Erase(ConstValueIterator pos) const
Definition: document.h:3096
bool operator!=(ConstIterator that) const
Definition: document.h:243
bool ObjectEmpty() const
Definition: document.h:3150
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:2877
pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:168
unsigned short uint16_t
Definition: stdint.h:126
static ValueType & Set(ValueType &v, double data, typename ValueType::AllocatorType &)
Definition: document.h:604
GenericArray PushBack(ValueType &value, AllocatorType &allocator) const
Definition: document.h:3070
false
Definition: rapidjson.h:709
static bool Is(const ValueType &v)
Definition: document.h:516
static ValueType & Set(ValueType &v, bool data)
Definition: document.h:518
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:929
bool EraseMember(const Ch *name) const
Definition: document.h:3283
difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:172
ValueType & operator[](T *name) const
Definition: document.h:3152
SizeType Capacity() const
Definition: document.h:3060
MemberIterator FindMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:3187
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator)
Definition: document.h:2493
MemberIterator MemberBegin() const
Definition: document.h:3165
static ValueType & Set(ValueType &v, ArrayType data, typename ValueType::AllocatorType &)
Definition: document.h:656
Result of parsing (wraps ParseErrorCode)
Definition: error.h:120
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:728
friend class GenericDocument
Definition: document.h:2337
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:715
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:76
bool operator<(ConstIterator that) const
Definition: document.h:246
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:2769
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
Assertion (in non-throwing contexts).
Definition: rapidjson.h:681
Pointer operator->() const
Definition: document.h:253
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
static unsigned Get(const ValueType &v)
Definition: document.h:539
GenericArray(const GenericArray &rhs)
Definition: document.h:3052
bool StartObject()
Definition: document.h:2973
SizeType MemberCapacity() const
Definition: document.h:3149
ValueType::StringRefType StringRefType
Definition: document.h:3134
bool StartArray()
Definition: document.h:2990
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:714
A document for parsing JSON text as DOM.
Definition: document.h:62
bool HasMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:3179
void RemoveAllMembers()
Definition: document.h:3261
static bool Is(const ValueType &v)
Definition: document.h:527
ShortString ss
Definition: document.h:2463
A read-write string stream.
Definition: fwd.h:65
GenericArray & operator=(const GenericArray &rhs)
Definition: document.h:3053
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:873
bool operator==(ConstIterator that) const
Definition: document.h:242
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:154
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:721
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:914
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2608
static ValueType & Set(ValueType &v, double data)
Definition: document.h:603
Iterator & operator--()
Definition: document.h:209
bool HasMember(const Ch *name) const
Definition: document.h:3172
GenericMemberIterator< true, typename ValueT::EncodingType, typename ValueT::AllocatorType > ConstMemberIterator
Definition: document.h:3132
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:716
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:690
ValueT PlainType
Definition: document.h:3042
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2626
GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:846
Reference operator[](DifferenceType n) const
Definition: document.h:254
bool EndObject(SizeType memberCount)
Definition: document.h:2982
ObjectData o
Definition: document.h:2465
string
Definition: rapidjson.h:713
Allocator * ownAllocator_
Definition: document.h:3023
GenericArray(ValueType &value)
Definition: document.h:3110
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:717
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:376
ParseResult parseResult_
Definition: document.h:3025
static ValueType & Set(ValueType &v, ObjectType data, typename ValueType::AllocatorType &)
Definition: document.h:675
static bool Is(const ValueType &v)
Definition: document.h:577
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2575
bool Double(double d)
Definition: document.h:2950
static ValueType & Set(ValueType &v, float data, typename ValueType::AllocatorType &)
Definition: document.h:615
ParseErrorCode
Error code of parsing.
Definition: error.h:68
bool RawNumber(const Ch *str, SizeType length, bool copy)
Definition: document.h:2955
GenericObject MemberReserve(SizeType newCapacity, AllocatorType &allocator) const
Definition: document.h:3167
RAPIDJSON_FORCEINLINE GenericValue * GetElementsPointer() const
Definition: document.h:2477
Helper class for accessing Value of object type.
Definition: document.h:694
GenericObject< true, ValueT > ConstObject
Definition: document.h:3123
static ValueType & Set(ValueType &v, float data)
Definition: document.h:614
Iterator & operator++()
Definition: document.h:205
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:2474
bool operator<=(ConstIterator that) const
Definition: document.h:244
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:2783
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:351
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:719
bool Int(int i)
Definition: document.h:2934
GenericObject(const GenericObject &rhs)
Definition: document.h:3141
unsigned __int64 uint64_t
Definition: stdint.h:137
ValueType::AllocatorType AllocatorType
Definition: document.h:3133
bool operator>(ConstIterator that) const
Definition: document.h:247
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2898
static bool Usable(SizeType len)
Definition: document.h:2412
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:3029
Iterator operator++(int)
Definition: document.h:213
Input byte stream wrapper with a statically bound encoding.
Definition: encodedstream.h:44
GenericArray< false, ValueType > Array
Definition: document.h:731
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:730
const SizeType length
Definition: document.h:401
number
Definition: rapidjson.h:714
const ValueT * ConstValueIterator
Definition: document.h:3045
ValueIterator Begin() const
Definition: document.h:3064
TFSIMD_FORCE_INLINE bool operator!=(const Vector3 &other) const
bool Int64(int64_t i)
Definition: document.h:2942
ValueType * ValueIterator
Definition: document.h:3044
SizeType hashcode
reserved
Definition: document.h:2390
Iterator & operator+=(DifferenceType n)
Definition: document.h:230
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:37
GenericArray< true, ValueType > ConstArray
Definition: document.h:732
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:694
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2806
ValueIterator End() const
Definition: document.h:3065
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition: document.h:3126
static ValueType & Set(ValueType &v, unsigned data)
Definition: document.h:540
~GenericValue()
Destructor.
Definition: document.h:971
static int Get(const ValueType &v)
Definition: document.h:528
GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType &allocator) const
Definition: document.h:3248
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:2792
friend void swap(GenericMember &a, GenericMember &b) RAPIDJSON_NOEXCEPT
Definition: document.h:103
GenericObject< false, ValueT > Object
Definition: document.h:3124
SizeType MemberCount() const
Definition: document.h:3148
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:345
static ValueType & Set(ValueType &v, unsigned data, typename ValueType::AllocatorType &)
Definition: document.h:541
MemberIterator FindMember(const Ch *name) const
Definition: document.h:3183
void SetObjectRaw(Member *members, SizeType count, Allocator &allocator)
Definition: document.h:2507
CharType Ch
character type of the string
Definition: document.h:323
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:495
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:258
static bool Is(const ValueType &v)
Definition: document.h:612
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition: document.h:2487
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1365
MemberIterator RemoveMember(MemberIterator m) const
Definition: document.h:3273
std::random_access_iterator_tag iterator_category
Definition: document.h:164
RAPIDJSON_FORCEINLINE Member * GetMembersPointer() const
Definition: document.h:2484
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:439
Reference operator*() const
Definition: document.h:252
Iterator & operator=(const NonConstIterator &it)
Definition: document.h:198
MemberIterator EraseMember(ConstMemberIterator pos) const
Definition: document.h:3276
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const
Definition: document.h:3099
void SetStringRaw(StringRefType s, Allocator &allocator)
Definition: document.h:2528
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:2880
bool operator>=(ConstIterator that) const
Definition: document.h:245
GenericDocument & Parse(const typename SourceEncoding::Ch *str, size_t length)
Definition: document.h:2830
static int64_t Get(const ValueType &v)
Definition: document.h:578
ValueType::AllocatorType AllocatorType
Definition: document.h:3046
GenericObject< true, ValueType > ConstObject
Definition: document.h:734
signed __int64 int64_t
Definition: stdint.h:136
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition: document.h:2520
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:865
static ValueType & Set(ValueType &v, int64_t data)
Definition: document.h:579
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:346
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:890
Iterator operator-(DifferenceType n) const
Definition: document.h:228
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:726
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T2 >, internal::IsGenericValue< T2 >>),(typename T::ValueType &)) GetValueByPointerWithDefault(T &root
Name-value pair in a JSON object value.
Definition: document.h:72
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:919
static const SizeType kDefaultObjectCapacity
Definition: document.h:2373
GenericObject< false, ValueType > Object
Definition: document.h:733
bool Uint64(uint64_t i)
Definition: document.h:2946
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:2818
true
Definition: rapidjson.h:710
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:156
GenericMember(const GenericMember &rhs)
Copy constructor is not permitted.
static const SizeType kDefaultArrayCapacity
Definition: document.h:2372
GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const
Definition: document.h:3066
ValueType::Ch Ch
Definition: document.h:3136
static float Get(const ValueType &v)
Definition: document.h:613
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
bool Uint(unsigned i)
Definition: document.h:2938
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:36
static ValueType & Set(ValueType &v, const StringType data)
Definition: document.h:626
Reference to a constant string (not taking a copy)
Definition: document.h:322
void ClearStack()
Definition: document.h:3008
GenericMember & operator=(GenericMember &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:94
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:197
static ValueType & Set(ValueType &v, int data)
Definition: document.h:529
bool EraseMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:3290
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:740
static double Get(const ValueType &v)
Definition: document.h:602
Iterator operator+(DifferenceType n) const
Definition: document.h:227
ValueType & operator[](const GenericValue< EncodingType, SourceAllocator > &name) const
Definition: document.h:3156
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:902
ValueType & reference
Definition: document.h:162
SizeType Size() const
Definition: document.h:3059
Allocator * allocator_
Definition: document.h:3022
GenericArray< false, ValueT > Array
Definition: document.h:3041
bool RemoveMember(const Ch *name) const
Definition: document.h:3262
Type
Type of JSON value.
Definition: rapidjson.h:707
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:1026
ValueType & value_
Definition: document.h:3303
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:2825
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:389
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition: document.h:2545
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:508
GenericObject & operator=(const GenericObject &rhs)
Definition: document.h:3142
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const
Definition: document.h:3279
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2682
static ValueType & Set(ValueType &v, uint64_t data, typename ValueType::AllocatorType &)
Definition: document.h:593
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:2904
ValueType & value_
Definition: document.h:3111
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Definition: document.h:723
GenericObject AddMember(ValueType &name, StringRefType value, AllocatorType &allocator) const
Definition: document.h:3201
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition: document.h:791
GenericValue * elements
Definition: document.h:2458
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:1006
static ValueType & Set(ValueType &v, int data, typename ValueType::AllocatorType &)
Definition: document.h:530
static ValueType & Set(ValueType &v, int64_t data, typename ValueType::AllocatorType &)
Definition: document.h:580
In-situ(destructive) parsing.
Definition: reader.h:155
static bool Is(const ValueType &v)
Definition: document.h:538
void Destroy()
Definition: document.h:3019
Iterator & operator-=(DifferenceType n)
Definition: document.h:234
static uint64_t Get(const ValueType &v)
Definition: document.h:589
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: document.h:2874
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:2738
static ValueType & Set(ValueType &v, const StringType data, typename ValueType::AllocatorType &a)
Definition: document.h:629
null
Definition: rapidjson.h:708
ValueType value_type
Definition: document.h:160
GenericMemberIterator< Const, typename ValueT::EncodingType, typename ValueT::AllocatorType > MemberIterator
Definition: document.h:3129
static ValueType & Set(ValueType &v, bool data, typename ValueType::AllocatorType &)
Definition: document.h:519
bool Key(const Ch *str, SizeType length, bool copy)
Definition: document.h:2978
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition: document.h:951


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46