Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
document.h
Go to the documentation of this file.
1// Tencent is pleased to support the open source community by making RapidJSON available.
2//
3// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4//
5// Licensed under the MIT License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// http://opensource.org/licenses/MIT
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#ifndef RAPIDJSON_DOCUMENT_H_
16#define RAPIDJSON_DOCUMENT_H_
17
20#include "reader.h"
21#include "internal/meta.h"
22#include "internal/strfunc.h"
23#include "memorystream.h"
24#include "encodedstream.h"
25#include <new> // placement new
26#include <limits>
27
28RAPIDJSON_DIAG_PUSH
29#ifdef __clang__
30RAPIDJSON_DIAG_OFF(padded)
31RAPIDJSON_DIAG_OFF(switch-enum)
32RAPIDJSON_DIAG_OFF(c++98-compat)
33#elif defined(_MSC_VER)
34RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
35RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
36#endif
37
38#ifdef __GNUC__
39RAPIDJSON_DIAG_OFF(effc++)
40#endif // __GNUC__
41
42#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
43#include <iterator> // std::random_access_iterator_tag
44#endif
45
46#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
47#include <utility> // std::move
48#endif
49
51
52// Forward declaration.
53template <typename Encoding, typename Allocator>
54class GenericValue;
55
56template <typename Encoding, typename Allocator, typename StackAllocator>
57class GenericDocument;
58
60
65template <typename Encoding, typename Allocator>
69
70 // swap() for std::sort() and other potential use in STL.
71 friend inline void swap(GenericMember& a, GenericMember& b) RAPIDJSON_NOEXCEPT {
72 a.name.Swap(b.name);
73 a.value.Swap(b.value);
74 }
75};
76
78// GenericMemberIterator
79
80#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
81
83
101template <bool Const, typename Encoding, typename Allocator>
103
104 friend class GenericValue<Encoding,Allocator>;
105 template <bool, typename, typename> friend class GenericMemberIterator;
106
108 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
109
110public:
117
120 typedef ValueType value_type;
121 typedef ValueType * pointer;
122 typedef ValueType & reference;
123 typedef std::ptrdiff_t difference_type;
124 typedef std::random_access_iterator_tag iterator_category;
126
133
135
139
141
156 GenericMemberIterator(const NonConstIterator & it) : ptr_(it.ptr_) {}
157 Iterator& operator=(const NonConstIterator & it) { ptr_ = it.ptr_; return *this; }
158
160
161 Iterator& operator++(){ ++ptr_; return *this; }
162 Iterator& operator--(){ --ptr_; return *this; }
163 Iterator operator++(int){ Iterator old(*this); ++ptr_; return old; }
164 Iterator operator--(int){ Iterator old(*this); --ptr_; return old; }
166
168
169 Iterator operator+(DifferenceType n) const { return Iterator(ptr_+n); }
170 Iterator operator-(DifferenceType n) const { return Iterator(ptr_-n); }
171
172 Iterator& operator+=(DifferenceType n) { ptr_+=n; return *this; }
173 Iterator& operator-=(DifferenceType n) { ptr_-=n; return *this; }
175
177
178 bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
179 bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
180 bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
181 bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
182 bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; }
183 bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; }
185
187
188 Reference operator*() const { return *ptr_; }
189 Pointer operator->() const { return ptr_; }
190 Reference operator[](DifferenceType n) const { return ptr_[n]; }
192
194 DifferenceType operator-(ConstIterator that) const { return ptr_-that.ptr_; }
195
196private:
198 explicit GenericMemberIterator(Pointer p) : ptr_(p) {}
199
200 Pointer ptr_;
201};
202
203#else // RAPIDJSON_NOMEMBERITERATORCLASS
204
205// class-based member iterator implementation disabled, use plain pointers
206
207template <bool Const, typename Encoding, typename Allocator>
209
211template <typename Encoding, typename Allocator>
215};
217template <typename Encoding, typename Allocator>
221};
222
223#endif // RAPIDJSON_NOMEMBERITERATORCLASS
224
226// GenericStringRef
227
229
255template<typename CharType>
257 typedef CharType Ch;
258
260#ifndef __clang__ // -Wdocumentation
283#endif
284 template<SizeType N>
285 GenericStringRef(const CharType (&str)[N]) RAPIDJSON_NOEXCEPT
286 : s(str), length(N-1) {}
287
289#ifndef __clang__ // -Wdocumentation
308#endif
309 explicit GenericStringRef(const CharType* str)
310 : s(str), length(NotNullStrLen(str)) {}
311
313#ifndef __clang__ // -Wdocumentation
320#endif
321 GenericStringRef(const CharType* str, SizeType len)
322 : s(RAPIDJSON_LIKELY(str) ? str : emptyString), length(len) { RAPIDJSON_ASSERT(str != 0 || len == 0u); }
323
324 GenericStringRef(const GenericStringRef& rhs) : s(rhs.s), length(rhs.length) {}
325
327 operator const Ch *() const { return s; }
328
329 const Ch* const s;
331
332private:
333 SizeType NotNullStrLen(const CharType* str) {
334 RAPIDJSON_ASSERT(str != 0);
335 return internal::StrLen(str);
336 }
337
339 static const Ch emptyString[];
340
342 template<SizeType N>
343 GenericStringRef(CharType (&str)[N]) /* = delete */;
345 GenericStringRef& operator=(const GenericStringRef& rhs) /* = delete */;
346};
347
348template<typename CharType>
349const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
350
352
363template<typename CharType>
364inline GenericStringRef<CharType> StringRef(const CharType* str) {
365 return GenericStringRef<CharType>(str);
366}
367
369
383template<typename CharType>
384inline GenericStringRef<CharType> StringRef(const CharType* str, size_t length) {
385 return GenericStringRef<CharType>(str, SizeType(length));
386}
387
388#if RAPIDJSON_HAS_STDSTRING
390
401template<typename CharType>
402inline GenericStringRef<CharType> StringRef(const std::basic_string<CharType>& str) {
403 return GenericStringRef<CharType>(str.data(), SizeType(str.size()));
404}
405#endif
406
408// GenericValue type traits
409namespace internal {
410
411template <typename T, typename Encoding = void, typename Allocator = void>
412struct IsGenericValueImpl : FalseType {};
413
414// select candidates according to nested encoding and allocator types
415template <typename T> struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
416 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
417
418// helper to match arbitrary GenericValue instantiations, including derived classes
419template <typename T> struct IsGenericValue : IsGenericValueImpl<T>::Type {};
420
421} // namespace internal
422
424// TypeHelper
425
426namespace internal {
427
428template <typename ValueType, typename T>
429struct TypeHelper {};
430
431template<typename ValueType>
432struct TypeHelper<ValueType, bool> {
433 static bool Is(const ValueType& v) { return v.IsBool(); }
434 static bool Get(const ValueType& v) { return v.GetBool(); }
435 static ValueType& Set(ValueType& v, bool data) { return v.SetBool(data); }
436 static ValueType& Set(ValueType& v, bool data, typename ValueType::AllocatorType&) { return v.SetBool(data); }
437};
438
439template<typename ValueType>
440struct TypeHelper<ValueType, int> {
441 static bool Is(const ValueType& v) { return v.IsInt(); }
442 static int Get(const ValueType& v) { return v.GetInt(); }
443 static ValueType& Set(ValueType& v, int data) { return v.SetInt(data); }
444 static ValueType& Set(ValueType& v, int data, typename ValueType::AllocatorType&) { return v.SetInt(data); }
445};
446
447template<typename ValueType>
448struct TypeHelper<ValueType, unsigned> {
449 static bool Is(const ValueType& v) { return v.IsUint(); }
450 static unsigned Get(const ValueType& v) { return v.GetUint(); }
451 static ValueType& Set(ValueType& v, unsigned data) { return v.SetUint(data); }
452 static ValueType& Set(ValueType& v, unsigned data, typename ValueType::AllocatorType&) { return v.SetUint(data); }
453};
454
455#ifdef _MSC_VER
456RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int));
457template<typename ValueType>
458struct TypeHelper<ValueType, long> {
459 static bool Is(const ValueType& v) { return v.IsInt(); }
460 static long Get(const ValueType& v) { return v.GetInt(); }
461 static ValueType& Set(ValueType& v, long data) { return v.SetInt(data); }
462 static ValueType& Set(ValueType& v, long data, typename ValueType::AllocatorType&) { return v.SetInt(data); }
463};
464
465RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned));
466template<typename ValueType>
467struct TypeHelper<ValueType, unsigned long> {
468 static bool Is(const ValueType& v) { return v.IsUint(); }
469 static unsigned long Get(const ValueType& v) { return v.GetUint(); }
470 static ValueType& Set(ValueType& v, unsigned long data) { return v.SetUint(data); }
471 static ValueType& Set(ValueType& v, unsigned long data, typename ValueType::AllocatorType&) { return v.SetUint(data); }
472};
473#endif
474
475template<typename ValueType>
476struct TypeHelper<ValueType, int64_t> {
477 static bool Is(const ValueType& v) { return v.IsInt64(); }
478 static int64_t Get(const ValueType& v) { return v.GetInt64(); }
479 static ValueType& Set(ValueType& v, int64_t data) { return v.SetInt64(data); }
480 static ValueType& Set(ValueType& v, int64_t data, typename ValueType::AllocatorType&) { return v.SetInt64(data); }
481};
482
483template<typename ValueType>
484struct TypeHelper<ValueType, uint64_t> {
485 static bool Is(const ValueType& v) { return v.IsUint64(); }
486 static uint64_t Get(const ValueType& v) { return v.GetUint64(); }
487 static ValueType& Set(ValueType& v, uint64_t data) { return v.SetUint64(data); }
488 static ValueType& Set(ValueType& v, uint64_t data, typename ValueType::AllocatorType&) { return v.SetUint64(data); }
489};
490
491template<typename ValueType>
492struct TypeHelper<ValueType, double> {
493 static bool Is(const ValueType& v) { return v.IsDouble(); }
494 static double Get(const ValueType& v) { return v.GetDouble(); }
495 static ValueType& Set(ValueType& v, double data) { return v.SetDouble(data); }
496 static ValueType& Set(ValueType& v, double data, typename ValueType::AllocatorType&) { return v.SetDouble(data); }
497};
498
499template<typename ValueType>
500struct TypeHelper<ValueType, float> {
501 static bool Is(const ValueType& v) { return v.IsFloat(); }
502 static float Get(const ValueType& v) { return v.GetFloat(); }
503 static ValueType& Set(ValueType& v, float data) { return v.SetFloat(data); }
504 static ValueType& Set(ValueType& v, float data, typename ValueType::AllocatorType&) { return v.SetFloat(data); }
505};
506
507template<typename ValueType>
508struct TypeHelper<ValueType, const typename ValueType::Ch*> {
509 typedef const typename ValueType::Ch* StringType;
510 static bool Is(const ValueType& v) { return v.IsString(); }
511 static StringType Get(const ValueType& v) { return v.GetString(); }
512 static ValueType& Set(ValueType& v, const StringType data) { return v.SetString(typename ValueType::StringRefType(data)); }
513 static ValueType& Set(ValueType& v, const StringType data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
514};
515
516#if RAPIDJSON_HAS_STDSTRING
517template<typename ValueType>
518struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
519 typedef std::basic_string<typename ValueType::Ch> StringType;
520 static bool Is(const ValueType& v) { return v.IsString(); }
521 static StringType Get(const ValueType& v) { return StringType(v.GetString(), v.GetStringLength()); }
522 static ValueType& Set(ValueType& v, const StringType& data, typename ValueType::AllocatorType& a) { return v.SetString(data, a); }
523};
524#endif
525
526template<typename ValueType>
527struct TypeHelper<ValueType, typename ValueType::Array> {
528 typedef typename ValueType::Array ArrayType;
529 static bool Is(const ValueType& v) { return v.IsArray(); }
530 static ArrayType Get(ValueType& v) { return v.GetArray(); }
531 static ValueType& Set(ValueType& v, ArrayType data) { return v = data; }
532 static ValueType& Set(ValueType& v, ArrayType data, typename ValueType::AllocatorType&) { return v = data; }
533};
534
535template<typename ValueType>
536struct TypeHelper<ValueType, typename ValueType::ConstArray> {
537 typedef typename ValueType::ConstArray ArrayType;
538 static bool Is(const ValueType& v) { return v.IsArray(); }
539 static ArrayType Get(const ValueType& v) { return v.GetArray(); }
540};
541
542template<typename ValueType>
543struct TypeHelper<ValueType, typename ValueType::Object> {
544 typedef typename ValueType::Object ObjectType;
545 static bool Is(const ValueType& v) { return v.IsObject(); }
546 static ObjectType Get(ValueType& v) { return v.GetObject(); }
547 static ValueType& Set(ValueType& v, ObjectType data) { return v = data; }
548 static ValueType& Set(ValueType& v, ObjectType data, typename ValueType::AllocatorType&) { return v = data; }
549};
550
551template<typename ValueType>
552struct TypeHelper<ValueType, typename ValueType::ConstObject> {
553 typedef typename ValueType::ConstObject ObjectType;
554 static bool Is(const ValueType& v) { return v.IsObject(); }
555 static ObjectType Get(const ValueType& v) { return v.GetObject(); }
556};
557
558} // namespace internal
559
560// Forward declarations
561template <bool, typename> class GenericArray;
562template <bool, typename> class GenericObject;
563
565// GenericValue
566
568
577template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
579public:
584 typedef typename Encoding::Ch Ch;
595
597
598
600 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
601
602#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
604 GenericValue(GenericValue&& rhs) RAPIDJSON_NOEXCEPT : data_(rhs.data_) {
605 rhs.data_.f.flags = kNullFlag; // give up contents
606 }
607#endif
608
609private:
611 GenericValue(const GenericValue& rhs);
612
613#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
615 template <typename StackAllocator>
617
619 template <typename StackAllocator>
621#endif
622
623public:
624
626
630 explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() {
631 static const uint16_t defaultFlags[] = {
634 };
636 data_.f.flags = defaultFlags[type];
637
638 // Use ShortString to store empty string.
639 if (type == kStringType)
640 data_.ss.SetLength(0);
641 }
642
644
651 template <typename SourceAllocator>
652 GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
653 switch (rhs.GetType()) {
654 case kObjectType: {
655 SizeType count = rhs.data_.o.size;
656 Member* lm = reinterpret_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
658 for (SizeType i = 0; i < count; i++) {
659 new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
660 new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings);
661 }
665 }
666 break;
667 case kArrayType: {
668 SizeType count = rhs.data_.a.size;
669 GenericValue* le = reinterpret_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
671 for (SizeType i = 0; i < count; i++)
672 new (&le[i]) GenericValue(re[i], allocator, copyConstStrings);
676 }
677 break;
678 case kStringType:
679 if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
680 data_.f.flags = rhs.data_.f.flags;
681 data_ = *reinterpret_cast<const Data*>(&rhs.data_);
682 }
683 else
684 SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
685 break;
686 default:
687 data_.f.flags = rhs.data_.f.flags;
688 data_ = *reinterpret_cast<const Data*>(&rhs.data_);
689 break;
690 }
691 }
692
694
699#ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
700 template <typename T>
701 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT // See #472
702#else
703 explicit GenericValue(bool b) RAPIDJSON_NOEXCEPT
704#endif
705 : data_() {
706 // safe-guard against failing SFINAE
707 RAPIDJSON_STATIC_ASSERT((internal::IsSame<bool,T>::Value));
709 }
710
712 explicit GenericValue(int i) RAPIDJSON_NOEXCEPT : data_() {
713 data_.n.i64 = i;
715 }
716
718 explicit GenericValue(unsigned u) RAPIDJSON_NOEXCEPT : data_() {
719 data_.n.u64 = u;
720 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
721 }
722
724 explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_() {
725 data_.n.i64 = i64;
727 if (i64 >= 0) {
729 if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
731 if (!(static_cast<uint64_t>(i64) & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
733 }
734 else if (i64 >= static_cast<int64_t>(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
736 }
737
739 explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_() {
740 data_.n.u64 = u64;
742 if (!(u64 & RAPIDJSON_UINT64_C2(0x80000000, 0x00000000)))
744 if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x00000000)))
746 if (!(u64 & RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0x80000000)))
748 }
749
751 explicit GenericValue(double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
752
754 explicit GenericValue(float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = static_cast<double>(f); data_.f.flags = kNumberDoubleFlag; }
755
757 GenericValue(const Ch* s, SizeType length) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(StringRef(s, length)); }
758
760 explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_() { SetStringRaw(s); }
761
763 GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_() { SetStringRaw(StringRef(s, length), allocator); }
764
766 GenericValue(const Ch*s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
767
768#if RAPIDJSON_HAS_STDSTRING
770
772 GenericValue(const std::basic_string<Ch>& s, Allocator& allocator) : data_() { SetStringRaw(StringRef(s), allocator); }
773#endif
774
776
781 GenericValue(Array a) RAPIDJSON_NOEXCEPT : data_(a.value_.data_) {
782 a.value_.data_ = Data();
783 a.value_.data_.f.flags = kArrayFlag;
784 }
785
787
792 GenericValue(Object o) RAPIDJSON_NOEXCEPT : data_(o.value_.data_) {
793 o.value_.data_ = Data();
794 o.value_.data_.f.flags = kObjectFlag;
795 }
796
798
801 if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
802 switch(data_.f.flags) {
803 case kArrayFlag:
804 {
806 for (GenericValue* v = e; v != e + data_.a.size; ++v)
807 v->~GenericValue();
808 Allocator::Free(e);
809 }
810 break;
811
812 case kObjectFlag:
813 for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
814 m->~Member();
815 Allocator::Free(GetMembersPointer());
816 break;
817
818 case kCopyStringFlag:
819 Allocator::Free(const_cast<Ch*>(GetStringPointer()));
820 break;
821
822 default:
823 break; // Do nothing for other types.
824 }
825 }
826 }
827
829
831
832
834
836 GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
837 if (RAPIDJSON_LIKELY(this != &rhs)) {
838 this->~GenericValue();
839 RawAssign(rhs);
840 }
841 return *this;
842 }
843
844#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
846 GenericValue& operator=(GenericValue&& rhs) RAPIDJSON_NOEXCEPT {
847 return *this = rhs.Move();
848 }
849#endif
850
852
856 GenericValue& operator=(StringRefType str) RAPIDJSON_NOEXCEPT {
857 GenericValue s(str);
858 return *this = s;
859 }
860
862
873 template <typename T>
874 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (GenericValue&))
875 operator=(T value) {
877 return *this = v;
878 }
879
881
887 template <typename SourceAllocator>
888 GenericValue& CopyFrom(const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false) {
889 RAPIDJSON_ASSERT(static_cast<void*>(this) != static_cast<void const*>(&rhs));
890 this->~GenericValue();
891 new (this) GenericValue(rhs, allocator, copyConstStrings);
892 return *this;
893 }
894
896
900 GenericValue& Swap(GenericValue& other) RAPIDJSON_NOEXCEPT {
901 GenericValue temp;
902 temp.RawAssign(*this);
903 RawAssign(other);
904 other.RawAssign(temp);
905 return *this;
906 }
907
909
920 friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
921
923
924 GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; }
926
928
929
934 template <typename SourceAllocator>
937 if (GetType() != rhs.GetType())
938 return false;
939
940 switch (GetType()) {
941 case kObjectType: // Warning: O(n^2) inner-loop
942 if (data_.o.size != rhs.data_.o.size)
943 return false;
944 for (ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
945 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name);
946 if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
947 return false;
948 }
949 return true;
950
951 case kArrayType:
952 if (data_.a.size != rhs.data_.a.size)
953 return false;
954 for (SizeType i = 0; i < data_.a.size; i++)
955 if ((*this)[i] != rhs[i])
956 return false;
957 return true;
958
959 case kStringType:
960 return StringEqual(rhs);
961
962 case kNumberType:
963 if (IsDouble() || rhs.IsDouble()) {
964 double a = GetDouble(); // May convert from integer to double.
965 double b = rhs.GetDouble(); // Ditto
966 return a >= b && a <= b; // Prevent -Wfloat-equal
967 }
968 else
969 return data_.n.u64 == rhs.data_.n.u64;
970
971 default:
972 return true;
973 }
974 }
975
977 bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); }
978
979#if RAPIDJSON_HAS_STDSTRING
981
983 bool operator==(const std::basic_string<Ch>& rhs) const { return *this == GenericValue(StringRef(rhs)); }
984#endif
985
987
989 template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (bool)) operator==(const T& rhs) const { return *this == GenericValue(rhs); }
990
992
994 template <typename SourceAllocator>
995 bool operator!=(const GenericValue<Encoding, SourceAllocator>& rhs) const { return !(*this == rhs); }
996
998 bool operator!=(const Ch* rhs) const { return !(*this == rhs); }
999
1001
1003 template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& rhs) const { return !(*this == rhs); }
1004
1006
1008 template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator==(const T& lhs, const GenericValue& rhs) { return rhs == lhs; }
1009
1011
1013 template <typename T> friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (bool)) operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); }
1015
1017
1018
1019 Type GetType() const { return static_cast<Type>(data_.f.flags & kTypeMask); }
1020 bool IsNull() const { return data_.f.flags == kNullFlag; }
1021 bool IsFalse() const { return data_.f.flags == kFalseFlag; }
1022 bool IsTrue() const { return data_.f.flags == kTrueFlag; }
1023 bool IsBool() const { return (data_.f.flags & kBoolFlag) != 0; }
1024 bool IsObject() const { return data_.f.flags == kObjectFlag; }
1025 bool IsArray() const { return data_.f.flags == kArrayFlag; }
1026 bool IsNumber() const { return (data_.f.flags & kNumberFlag) != 0; }
1027 bool IsInt() const { return (data_.f.flags & kIntFlag) != 0; }
1028 bool IsUint() const { return (data_.f.flags & kUintFlag) != 0; }
1029 bool IsInt64() const { return (data_.f.flags & kInt64Flag) != 0; }
1030 bool IsUint64() const { return (data_.f.flags & kUint64Flag) != 0; }
1031 bool IsDouble() const { return (data_.f.flags & kDoubleFlag) != 0; }
1032 bool IsString() const { return (data_.f.flags & kStringFlag) != 0; }
1033
1034 // Checks whether a number can be losslessly converted to a double.
1035 bool IsLosslessDouble() const {
1036 if (!IsNumber()) return false;
1037 if (IsUint64()) {
1038 uint64_t u = GetUint64();
1039 volatile double d = static_cast<double>(u);
1040 return (d >= 0.0)
1041 && (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
1042 && (u == static_cast<uint64_t>(d));
1043 }
1044 if (IsInt64()) {
1045 int64_t i = GetInt64();
1046 volatile double d = static_cast<double>(i);
1047 return (d >= static_cast<double>((std::numeric_limits<int64_t>::min)()))
1048 && (d < static_cast<double>((std::numeric_limits<int64_t>::max)()))
1049 && (i == static_cast<int64_t>(d));
1050 }
1051 return true; // double, int, uint are always lossless
1052 }
1053
1054 // Checks whether a number is a float (possible lossy).
1055 bool IsFloat() const {
1056 if ((data_.f.flags & kDoubleFlag) == 0)
1057 return false;
1058 double d = GetDouble();
1059 return d >= -3.4028234e38 && d <= 3.4028234e38;
1060 }
1061 // Checks whether a number can be losslessly converted to a float.
1062 bool IsLosslessFloat() const {
1063 if (!IsNumber()) return false;
1064 double a = GetDouble();
1065 if (a < static_cast<double>(-(std::numeric_limits<float>::max)())
1066 || a > static_cast<double>((std::numeric_limits<float>::max)()))
1067 return false;
1068 double b = static_cast<double>(static_cast<float>(a));
1069 return a >= b && a <= b; // Prevent -Wfloat-equal
1070 }
1071
1073
1075
1076
1077 GenericValue& SetNull() { this->~GenericValue(); new (this) GenericValue(); return *this; }
1078
1080
1082
1083
1084 bool GetBool() const { RAPIDJSON_ASSERT(IsBool()); return data_.f.flags == kTrueFlag; }
1086
1087 GenericValue& SetBool(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
1088
1090
1092
1093
1095
1096 GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
1097
1099 SizeType MemberCount() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size; }
1100
1102 SizeType MemberCapacity() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.capacity; }
1103
1105 bool ObjectEmpty() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.size == 0; }
1106
1108
1116 template <typename T>
1117 RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(GenericValue&)) operator[](T* name) {
1119 return (*this)[n];
1120 }
1121 template <typename T>
1122 RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >),(const GenericValue&)) operator[](T* name) const { return const_cast<GenericValue&>(*this)[name]; }
1123
1125
1133 template <typename SourceAllocator>
1135 MemberIterator member = FindMember(name);
1136 if (member != MemberEnd())
1137 return member->value;
1138 else {
1139 RAPIDJSON_ASSERT(false); // see above note
1140
1141 // This will generate -Wexit-time-destructors in clang
1142 // static GenericValue NullValue;
1143 // return NullValue;
1144
1145 // Use static buffer and placement-new to prevent destruction
1146 static char buffer[sizeof(GenericValue)];
1147 return *new (buffer) GenericValue();
1148 }
1149 }
1150 template <typename SourceAllocator>
1151 const GenericValue& operator[](const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this)[name]; }
1152
1153#if RAPIDJSON_HAS_STDSTRING
1155 GenericValue& operator[](const std::basic_string<Ch>& name) { return (*this)[GenericValue(StringRef(name))]; }
1156 const GenericValue& operator[](const std::basic_string<Ch>& name) const { return (*this)[GenericValue(StringRef(name))]; }
1157#endif
1158
1160
1161 ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer()); }
1163
1164 ConstMemberIterator MemberEnd() const { RAPIDJSON_ASSERT(IsObject()); return ConstMemberIterator(GetMembersPointer() + data_.o.size); }
1166
1167 MemberIterator MemberBegin() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer()); }
1169
1170 MemberIterator MemberEnd() { RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer() + data_.o.size); }
1171
1173
1178 GenericValue& MemberReserve(SizeType newCapacity, Allocator &allocator) {
1179 RAPIDJSON_ASSERT(IsObject());
1180 if (newCapacity > data_.o.capacity) {
1181 SetMembersPointer(reinterpret_cast<Member*>(allocator.Realloc(GetMembersPointer(), data_.o.capacity * sizeof(Member), newCapacity * sizeof(Member))));
1182 data_.o.capacity = newCapacity;
1183 }
1184 return *this;
1185 }
1186
1188
1195 bool HasMember(const Ch* name) const { return FindMember(name) != MemberEnd(); }
1196
1197#if RAPIDJSON_HAS_STDSTRING
1199
1206 bool HasMember(const std::basic_string<Ch>& name) const { return FindMember(name) != MemberEnd(); }
1207#endif
1208
1210
1218 template <typename SourceAllocator>
1219 bool HasMember(const GenericValue<Encoding, SourceAllocator>& name) const { return FindMember(name) != MemberEnd(); }
1220
1222
1233 MemberIterator FindMember(const Ch* name) {
1235 return FindMember(n);
1236 }
1237
1238 ConstMemberIterator FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
1239
1241
1253 template <typename SourceAllocator>
1255 RAPIDJSON_ASSERT(IsObject());
1256 RAPIDJSON_ASSERT(name.IsString());
1257 MemberIterator member = MemberBegin();
1258 for ( ; member != MemberEnd(); ++member)
1259 if (name.StringEqual(member->name))
1260 break;
1261 return member;
1262 }
1263 template <typename SourceAllocator> ConstMemberIterator FindMember(const GenericValue<Encoding, SourceAllocator>& name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
1264
1265#if RAPIDJSON_HAS_STDSTRING
1267
1273 MemberIterator FindMember(const std::basic_string<Ch>& name) { return FindMember(GenericValue(StringRef(name))); }
1274 ConstMemberIterator FindMember(const std::basic_string<Ch>& name) const { return FindMember(GenericValue(StringRef(name))); }
1275#endif
1276
1278
1287 GenericValue& AddMember(GenericValue& name, GenericValue& value, Allocator& allocator) {
1288 RAPIDJSON_ASSERT(IsObject());
1289 RAPIDJSON_ASSERT(name.IsString());
1290
1291 ObjectData& o = data_.o;
1292 if (o.size >= o.capacity)
1293 MemberReserve(o.capacity == 0 ? kDefaultObjectCapacity : (o.capacity + (o.capacity + 1) / 2), allocator);
1294 Member* members = GetMembersPointer();
1295 members[o.size].name.RawAssign(name);
1296 members[o.size].value.RawAssign(value);
1297 o.size++;
1298 return *this;
1299 }
1300
1302
1310 GenericValue& AddMember(GenericValue& name, StringRefType value, Allocator& allocator) {
1312 return AddMember(name, v, allocator);
1313 }
1314
1315#if RAPIDJSON_HAS_STDSTRING
1317
1325 GenericValue& AddMember(GenericValue& name, std::basic_string<Ch>& value, Allocator& allocator) {
1326 GenericValue v(value, allocator);
1327 return AddMember(name, v, allocator);
1328 }
1329#endif
1330
1332
1348 template <typename T>
1349 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1350 AddMember(GenericValue& name, T value, Allocator& allocator) {
1352 return AddMember(name, v, allocator);
1353 }
1354
1355#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1356 GenericValue& AddMember(GenericValue&& name, GenericValue&& value, Allocator& allocator) {
1357 return AddMember(name, value, allocator);
1358 }
1359 GenericValue& AddMember(GenericValue&& name, GenericValue& value, Allocator& allocator) {
1360 return AddMember(name, value, allocator);
1361 }
1362 GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) {
1363 return AddMember(name, value, allocator);
1364 }
1365 GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) {
1366 GenericValue n(name);
1367 return AddMember(n, value, allocator);
1368 }
1369#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1370
1371
1373
1382 GenericValue& AddMember(StringRefType name, GenericValue& value, Allocator& allocator) {
1383 GenericValue n(name);
1384 return AddMember(n, value, allocator);
1385 }
1386
1388
1396 GenericValue& AddMember(StringRefType name, StringRefType value, Allocator& allocator) {
1398 return AddMember(name, v, allocator);
1399 }
1400
1402
1418 template <typename T>
1419 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1420 AddMember(StringRefType name, T value, Allocator& allocator) {
1421 GenericValue n(name);
1422 return AddMember(n, value, allocator);
1423 }
1424
1426
1429 void RemoveAllMembers() {
1430 RAPIDJSON_ASSERT(IsObject());
1431 for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
1432 m->~Member();
1433 data_.o.size = 0;
1434 }
1435
1437
1444 bool RemoveMember(const Ch* name) {
1446 return RemoveMember(n);
1447 }
1448
1449#if RAPIDJSON_HAS_STDSTRING
1450 bool RemoveMember(const std::basic_string<Ch>& name) { return RemoveMember(GenericValue(StringRef(name))); }
1451#endif
1452
1453 template <typename SourceAllocator>
1454 bool RemoveMember(const GenericValue<Encoding, SourceAllocator>& name) {
1455 MemberIterator m = FindMember(name);
1456 if (m != MemberEnd()) {
1457 RemoveMember(m);
1458 return true;
1459 }
1460 else
1461 return false;
1462 }
1463
1465
1472 MemberIterator RemoveMember(MemberIterator m) {
1473 RAPIDJSON_ASSERT(IsObject());
1476 RAPIDJSON_ASSERT(m >= MemberBegin() && m < MemberEnd());
1477
1479 if (data_.o.size > 1 && m != last)
1480 *m = *last; // Move the last one to this place
1481 else
1482 m->~Member(); // Only one left, just destroy
1483 --data_.o.size;
1484 return m;
1485 }
1486
1488
1496 MemberIterator EraseMember(ConstMemberIterator pos) {
1497 return EraseMember(pos, pos +1);
1498 }
1499
1501
1509 MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) {
1510 RAPIDJSON_ASSERT(IsObject());
1513 RAPIDJSON_ASSERT(first >= MemberBegin());
1514 RAPIDJSON_ASSERT(first <= last);
1515 RAPIDJSON_ASSERT(last <= MemberEnd());
1516
1517 MemberIterator pos = MemberBegin() + (first - MemberBegin());
1518 for (MemberIterator itr = pos; itr != last; ++itr)
1519 itr->~Member();
1520 std::memmove(static_cast<void*>(&*pos), &*last, static_cast<size_t>(MemberEnd() - last) * sizeof(Member));
1521 data_.o.size -= static_cast<SizeType>(last - first);
1522 return pos;
1523 }
1524
1526
1530 bool EraseMember(const Ch* name) {
1532 return EraseMember(n);
1533 }
1534
1535#if RAPIDJSON_HAS_STDSTRING
1536 bool EraseMember(const std::basic_string<Ch>& name) { return EraseMember(GenericValue(StringRef(name))); }
1537#endif
1538
1539 template <typename SourceAllocator>
1540 bool EraseMember(const GenericValue<Encoding, SourceAllocator>& name) {
1541 MemberIterator m = FindMember(name);
1542 if (m != MemberEnd()) {
1543 EraseMember(m);
1544 return true;
1545 }
1546 else
1547 return false;
1548 }
1549
1550 Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
1551 ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
1552
1554
1556
1557
1559
1560 GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
1561
1563 SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
1564
1566 SizeType Capacity() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.capacity; }
1567
1569 bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
1570
1572
1575 void Clear() {
1576 RAPIDJSON_ASSERT(IsArray());
1578 for (GenericValue* v = e; v != e + data_.a.size; ++v)
1579 v->~GenericValue();
1580 data_.a.size = 0;
1581 }
1582
1584
1588 GenericValue& operator[](SizeType index) {
1589 RAPIDJSON_ASSERT(IsArray());
1590 RAPIDJSON_ASSERT(index < data_.a.size);
1591 return GetElementsPointer()[index];
1592 }
1593 const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
1594
1596
1597 ValueIterator Begin() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer(); }
1599
1600 ValueIterator End() { RAPIDJSON_ASSERT(IsArray()); return GetElementsPointer() + data_.a.size; }
1602
1603 ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
1605
1606 ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
1607
1609
1614 GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
1615 RAPIDJSON_ASSERT(IsArray());
1616 if (newCapacity > data_.a.capacity) {
1617 SetElementsPointer(reinterpret_cast<GenericValue*>(allocator.Realloc(GetElementsPointer(), data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue))));
1618 data_.a.capacity = newCapacity;
1619 }
1620 return *this;
1621 }
1622
1624
1633 GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
1634 RAPIDJSON_ASSERT(IsArray());
1635 if (data_.a.size >= data_.a.capacity)
1636 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1638 return *this;
1639 }
1640
1641#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1642 GenericValue& PushBack(GenericValue&& value, Allocator& allocator) {
1643 return PushBack(value, allocator);
1644 }
1645#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1646
1648
1656 GenericValue& PushBack(StringRefType value, Allocator& allocator) {
1657 return (*this).template PushBack<StringRefType>(value, allocator);
1658 }
1659
1661
1677 template <typename T>
1678 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1679 PushBack(T value, Allocator& allocator) {
1681 return PushBack(v, allocator);
1682 }
1683
1685
1688 GenericValue& PopBack() {
1689 RAPIDJSON_ASSERT(IsArray());
1690 RAPIDJSON_ASSERT(!Empty());
1692 return *this;
1693 }
1694
1696
1703 return Erase(pos, pos + 1);
1704 }
1705
1707
1715 RAPIDJSON_ASSERT(IsArray());
1718 RAPIDJSON_ASSERT(first >= Begin());
1719 RAPIDJSON_ASSERT(first <= last);
1720 RAPIDJSON_ASSERT(last <= End());
1721 ValueIterator pos = Begin() + (first - Begin());
1722 for (ValueIterator itr = pos; itr != last; ++itr)
1723 itr->~GenericValue();
1724 std::memmove(static_cast<void*>(pos), last, static_cast<size_t>(End() - last) * sizeof(GenericValue));
1725 data_.a.size -= static_cast<SizeType>(last - first);
1726 return pos;
1727 }
1728
1729 Array GetArray() { RAPIDJSON_ASSERT(IsArray()); return Array(*this); }
1730 ConstArray GetArray() const { RAPIDJSON_ASSERT(IsArray()); return ConstArray(*this); }
1731
1733
1735
1736
1737 int GetInt() const { RAPIDJSON_ASSERT(data_.f.flags & kIntFlag); return data_.n.i.i; }
1738 unsigned GetUint() const { RAPIDJSON_ASSERT(data_.f.flags & kUintFlag); return data_.n.u.u; }
1739 int64_t GetInt64() const { RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag); return data_.n.i64; }
1740 uint64_t GetUint64() const { RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag); return data_.n.u64; }
1741
1743
1745 double GetDouble() const {
1746 RAPIDJSON_ASSERT(IsNumber());
1747 if ((data_.f.flags & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
1748 if ((data_.f.flags & kIntFlag) != 0) return data_.n.i.i; // int -> double
1749 if ((data_.f.flags & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
1750 if ((data_.f.flags & kInt64Flag) != 0) return static_cast<double>(data_.n.i64); // int64_t -> double (may lose precision)
1751 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0); return static_cast<double>(data_.n.u64); // uint64_t -> double (may lose precision)
1752 }
1753
1755
1757 float GetFloat() const {
1758 return static_cast<float>(GetDouble());
1759 }
1760
1761 GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
1762 GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
1763 GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
1764 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
1765 GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
1766 GenericValue& SetFloat(float f) { this->~GenericValue(); new (this) GenericValue(static_cast<double>(f)); return *this; }
1767
1769
1771
1772
1773 const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1774
1776
1778 SizeType GetStringLength() const { RAPIDJSON_ASSERT(IsString()); return ((data_.f.flags & kInlineStrFlag) ? (data_.ss.GetLength()) : data_.s.length); }
1779
1781
1788 GenericValue& SetString(const Ch* s, SizeType length) { return SetString(StringRef(s, length)); }
1789
1791
1795 GenericValue& SetString(StringRefType s) { this->~GenericValue(); SetStringRaw(s); return *this; }
1796
1798
1805 GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { return SetString(StringRef(s, length), allocator); }
1806
1808
1813 GenericValue& SetString(const Ch* s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
1814
1816
1821 GenericValue& SetString(StringRefType s, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, allocator); return *this; }
1822
1823#if RAPIDJSON_HAS_STDSTRING
1825
1831 GenericValue& SetString(const std::basic_string<Ch>& s, Allocator& allocator) { return SetString(StringRef(s), allocator); }
1832#endif
1833
1835
1837
1838
1840
1843 template <typename T>
1844 bool Is() const { return internal::TypeHelper<ValueType, T>::Is(*this); }
1845
1846 template <typename T>
1847 T Get() const { return internal::TypeHelper<ValueType, T>::Get(*this); }
1848
1849 template <typename T>
1850 T Get() { return internal::TypeHelper<ValueType, T>::Get(*this); }
1851
1852 template<typename T>
1853 ValueType& Set(const T& data) { return internal::TypeHelper<ValueType, T>::Set(*this, data); }
1854
1855 template<typename T>
1856 ValueType& Set(const T& data, AllocatorType& allocator) { return internal::TypeHelper<ValueType, T>::Set(*this, data, allocator); }
1857
1859
1861
1867 template <typename Handler>
1868 bool Accept(Handler& handler) const {
1869 switch(GetType()) {
1870 case kNullType: return handler.Null();
1871 case kFalseType: return handler.Bool(false);
1872 case kTrueType: return handler.Bool(true);
1873
1874 case kObjectType:
1875 if (RAPIDJSON_UNLIKELY(!handler.StartObject()))
1876 return false;
1877 for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
1878 RAPIDJSON_ASSERT(m->name.IsString()); // User may change the type of name by MemberIterator.
1879 if (RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1880 return false;
1881 if (RAPIDJSON_UNLIKELY(!m->value.Accept(handler)))
1882 return false;
1883 }
1884 return handler.EndObject(data_.o.size);
1885
1886 case kArrayType:
1887 if (RAPIDJSON_UNLIKELY(!handler.StartArray()))
1888 return false;
1889 for (const GenericValue* v = Begin(); v != End(); ++v)
1890 if (RAPIDJSON_UNLIKELY(!v->Accept(handler)))
1891 return false;
1892 return handler.EndArray(data_.a.size);
1893
1894 case kStringType:
1895 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1896
1897 default:
1898 RAPIDJSON_ASSERT(GetType() == kNumberType);
1899 if (IsDouble()) return handler.Double(data_.n.d);
1900 else if (IsInt()) return handler.Int(data_.n.i.i);
1901 else if (IsUint()) return handler.Uint(data_.n.u.u);
1902 else if (IsInt64()) return handler.Int64(data_.n.i64);
1903 else return handler.Uint64(data_.n.u64);
1904 }
1905 }
1906
1907private:
1908 template <typename, typename> friend class GenericValue;
1909 template <typename, typename, typename> friend class GenericDocument;
1910
1911 enum {
1912 kBoolFlag = 0x0008,
1913 kNumberFlag = 0x0010,
1914 kIntFlag = 0x0020,
1915 kUintFlag = 0x0040,
1916 kInt64Flag = 0x0080,
1917 kUint64Flag = 0x0100,
1918 kDoubleFlag = 0x0200,
1919 kStringFlag = 0x0400,
1920 kCopyFlag = 0x0800,
1922
1923 // Initial flags of different types.
1938
1939 kTypeMask = 0x07
1941
1944
1945 struct Flag {
1946#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1947 char payload[sizeof(SizeType) * 2 + 6]; // 2 x SizeType + lower 48-bit pointer
1948#elif RAPIDJSON_64BIT
1949 char payload[sizeof(SizeType) * 2 + sizeof(void*) + 6]; // 6 padding bytes
1950#else
1951 char payload[sizeof(SizeType) * 2 + sizeof(void*) + 2]; // 2 padding bytes
1952#endif
1954 };
1955
1956 struct String {
1959 const Ch* str;
1960 }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1961
1962 // implementation detail: ShortString can represent zero-terminated strings up to MaxSize chars
1963 // (excluding the terminating zero) and store a value to determine the length of the contained
1964 // string in the last character str[LenPos] by storing "MaxSize - length" there. If the string
1965 // to store has the maximal length of MaxSize then str[LenPos] will be 0 and therefore act as
1966 // the string terminator as well. For getting the string length back from that value just use
1967 // "MaxSize - str[LenPos]".
1968 // This allows to store 13-chars strings in 32-bit mode, 21-chars strings in 64-bit mode,
1969 // 13-chars strings for RAPIDJSON_48BITPOINTER_OPTIMIZATION=1 inline (for `UTF8`-encoded strings).
1971 enum { MaxChars = sizeof(static_cast<Flag*>(0)->payload) / sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1973
1974 inline static bool Usable(SizeType len) { return (MaxSize >= len); }
1975 inline void SetLength(SizeType len) { str[LenPos] = static_cast<Ch>(MaxSize - len); }
1976 inline SizeType GetLength() const { return static_cast<SizeType>(MaxSize - str[LenPos]); }
1977 }; // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
1978
1979 // By using proper binary layout, retrieval of different integer types do not need conversions.
1980 union Number {
1981#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1982 struct I {
1983 int i;
1984 char padding[4];
1986 struct U {
1987 unsigned u;
1988 char padding2[4];
1990#else
1991 struct I {
1992 char padding[4];
1993 int i;
1994 }i;
1995 struct U {
1996 char padding2[4];
1997 unsigned u;
1998 }u;
1999#endif
2002 double d;
2003 }; // 8 bytes
2004
2005 struct ObjectData {
2009 }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2010
2011 struct ArrayData {
2015 }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
2016
2017 union Data {
2024 }; // 16 bytes in 32-bit mode, 24 bytes in 64-bit mode, 16 bytes in 64-bit with RAPIDJSON_48BITPOINTER_OPTIMIZATION
2025
2026 RAPIDJSON_FORCEINLINE const Ch* GetStringPointer() const { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
2027 RAPIDJSON_FORCEINLINE const Ch* SetStringPointer(const Ch* str) { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
2029 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
2030 RAPIDJSON_FORCEINLINE Member* GetMembersPointer() const { return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
2031 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
2032
2033 // Initialize this value as array with initial data, without calling destructor.
2034 void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
2036 if (count) {
2037 GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
2039 std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
2040 }
2041 else
2044 }
2045
2047 void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
2049 if (count) {
2050 Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
2052 std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
2053 }
2054 else
2057 }
2058
2060 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2063 data_.s.length = s.length;
2064 }
2065
2068 Ch* str = 0;
2069 if (ShortString::Usable(s.length)) {
2071 data_.ss.SetLength(s.length);
2072 str = data_.ss.str;
2073 } else {
2075 data_.s.length = s.length;
2076 str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2077 SetStringPointer(str);
2078 }
2079 std::memcpy(str, s, s.length * sizeof(Ch));
2080 str[s.length] = '\0';
2081 }
2082
2084 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2085 data_ = rhs.data_;
2086 // data_.f.flags = rhs.data_.f.flags;
2087 rhs.data_.f.flags = kNullFlag;
2088 }
2089
2090 template <typename SourceAllocator>
2092 RAPIDJSON_ASSERT(IsString());
2093 RAPIDJSON_ASSERT(rhs.IsString());
2094
2095 const SizeType len1 = GetStringLength();
2096 const SizeType len2 = rhs.GetStringLength();
2097 if(len1 != len2) { return false; }
2098
2099 const Ch* const str1 = GetString();
2100 const Ch* const str2 = rhs.GetString();
2101 if(str1 == str2) { return true; } // fast path for constant string
2102
2103 return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
2104 }
2105
2107};
2108
2111
2113// GenericDocument
2114
2116
2123template <typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
2124class GenericDocument : public GenericValue<Encoding, Allocator> {
2125public:
2126 typedef typename Encoding::Ch Ch;
2129
2131
2137 explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2138 GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2139 {
2140 if (!allocator_)
2141 ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2142 }
2143
2145
2150 GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
2151 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2152 {
2153 if (!allocator_)
2154 ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2155 }
2156
2157#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2159 GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2160 : ValueType(std::forward<ValueType>(rhs)), // explicit cast to avoid prohibited move from Document
2161 allocator_(rhs.allocator_),
2162 ownAllocator_(rhs.ownAllocator_),
2163 stack_(std::move(rhs.stack_)),
2164 parseResult_(rhs.parseResult_)
2165 {
2166 rhs.allocator_ = 0;
2167 rhs.ownAllocator_ = 0;
2168 rhs.parseResult_ = ParseResult();
2169 }
2170#endif
2171
2173 Destroy();
2174 }
2175
2176#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2178 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2179 {
2180 // The cast to ValueType is necessary here, because otherwise it would
2181 // attempt to call GenericValue's templated assignment operator.
2182 ValueType::operator=(std::forward<ValueType>(rhs));
2183
2184 // Calling the destructor here would prematurely call stack_'s destructor
2185 Destroy();
2186
2187 allocator_ = rhs.allocator_;
2188 ownAllocator_ = rhs.ownAllocator_;
2189 stack_ = std::move(rhs.stack_);
2190 parseResult_ = rhs.parseResult_;
2191
2192 rhs.allocator_ = 0;
2193 rhs.ownAllocator_ = 0;
2194 rhs.parseResult_ = ParseResult();
2195
2196 return *this;
2197 }
2198#endif
2199
2201
2206 GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT {
2207 ValueType::Swap(rhs);
2208 stack_.Swap(rhs.stack_);
2209 internal::Swap(allocator_, rhs.allocator_);
2210 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2211 internal::Swap(parseResult_, rhs.parseResult_);
2212 return *this;
2213 }
2214
2215 // Allow Swap with ValueType.
2216 // Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
2217 using ValueType::Swap;
2218
2220
2231 friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
2232
2234
2238 template <typename Generator>
2239 GenericDocument& Populate(Generator& g) {
2240 ClearStackOnExit scope(*this);
2241 if (g(*this)) {
2242 RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2243 ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2244 }
2245 return *this;
2246 }
2247
2250
2252
2258 template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
2259 GenericDocument& ParseStream(InputStream& is) {
2261 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2262 ClearStackOnExit scope(*this);
2263 parseResult_ = reader.template Parse<parseFlags>(is, *this);
2264 if (parseResult_) {
2265 RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2266 ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2267 }
2268 return *this;
2269 }
2270
2272
2277 template <unsigned parseFlags, typename InputStream>
2281
2283
2287 template <typename InputStream>
2292
2295
2297
2301 template <unsigned parseFlags>
2306
2308
2315
2318
2320
2324 template <unsigned parseFlags, typename SourceEncoding>
2325 GenericDocument& Parse(const typename SourceEncoding::Ch* str) {
2326 RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2329 }
2330
2332
2335 template <unsigned parseFlags>
2336 GenericDocument& Parse(const Ch* str) {
2337 return Parse<parseFlags, Encoding>(str);
2338 }
2339
2341
2343 GenericDocument& Parse(const Ch* str) {
2344 return Parse<kParseDefaultFlags>(str);
2345 }
2346
2347 template <unsigned parseFlags, typename SourceEncoding>
2348 GenericDocument& Parse(const typename SourceEncoding::Ch* str, size_t length) {
2349 RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2350 MemoryStream ms(reinterpret_cast<const char*>(str), length * sizeof(typename SourceEncoding::Ch));
2353 return *this;
2354 }
2355
2356 template <unsigned parseFlags>
2357 GenericDocument& Parse(const Ch* str, size_t length) {
2358 return Parse<parseFlags, Encoding>(str, length);
2359 }
2360
2361 GenericDocument& Parse(const Ch* str, size_t length) {
2362 return Parse<kParseDefaultFlags>(str, length);
2363 }
2364
2365#if RAPIDJSON_HAS_STDSTRING
2366 template <unsigned parseFlags, typename SourceEncoding>
2367 GenericDocument& Parse(const std::basic_string<typename SourceEncoding::Ch>& str) {
2368 // c_str() is constant complexity according to standard. Should be faster than Parse(const char*, size_t)
2369 return Parse<parseFlags, SourceEncoding>(str.c_str());
2370 }
2371
2372 template <unsigned parseFlags>
2373 GenericDocument& Parse(const std::basic_string<Ch>& str) {
2374 return Parse<parseFlags, Encoding>(str.c_str());
2375 }
2376
2377 GenericDocument& Parse(const std::basic_string<Ch>& str) {
2378 return Parse<kParseDefaultFlags>(str);
2379 }
2380#endif // RAPIDJSON_HAS_STDSTRING
2381
2383
2386
2388 bool HasParseError() const { return parseResult_.IsError(); }
2389
2391 ParseErrorCode GetParseError() const { return parseResult_.Code(); }
2392
2394 size_t GetErrorOffset() const { return parseResult_.Offset(); }
2395
2397#ifndef __clang // -Wdocumentation
2407#endif
2408 operator ParseResult() const { return parseResult_; }
2410
2413 RAPIDJSON_ASSERT(allocator_);
2414 return *allocator_;
2415 }
2416
2418 size_t GetStackCapacity() const { return stack_.GetCapacity(); }
2419
2420private:
2421 // clear stack on any exit from ParseStream, e.g. due to exception
2422 struct ClearStackOnExit {
2423 explicit ClearStackOnExit(GenericDocument& d) : d_(d) {}
2424 ~ClearStackOnExit() { d_.ClearStack(); }
2425 private:
2426 ClearStackOnExit(const ClearStackOnExit&);
2427 ClearStackOnExit& operator=(const ClearStackOnExit&);
2428 GenericDocument& d_;
2429 };
2430
2431 // callers of the following private Handler functions
2432 // template <typename,typename,typename> friend class GenericReader; // for parsing
2433 template <typename, typename> friend class GenericValue; // for deep copying
2434
2435public:
2436 // Implementation of Handler
2437 bool Null() { new (stack_.template Push<ValueType>()) ValueType(); return true; }
2438 bool Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
2439 bool Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2440 bool Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2441 bool Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2442 bool Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
2443 bool Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); return true; }
2444
2445 bool RawNumber(const Ch* str, SizeType length, bool copy) {
2446 if (copy)
2447 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2448 else
2449 new (stack_.template Push<ValueType>()) ValueType(str, length);
2450 return true;
2451 }
2452
2453 bool String(const Ch* str, SizeType length, bool copy) {
2454 if (copy)
2455 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2456 else
2457 new (stack_.template Push<ValueType>()) ValueType(str, length);
2458 return true;
2459 }
2460
2461 bool StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); return true; }
2462
2463 bool Key(const Ch* str, SizeType length, bool copy) { return String(str, length, copy); }
2464
2465 bool EndObject(SizeType memberCount) {
2466 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2467 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2468 return true;
2469 }
2470
2471 bool StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); return true; }
2472
2473 bool EndArray(SizeType elementCount) {
2474 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2475 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2476 return true;
2477 }
2478
2479private:
2483 GenericDocument& operator=(const GenericDocument&);
2484
2485 void ClearStack() {
2486 if (Allocator::kNeedFree)
2487 while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
2488 (stack_.template Pop<ValueType>(1))->~ValueType();
2489 else
2490 stack_.Clear();
2491 stack_.ShrinkToFit();
2492 }
2493
2494 void Destroy() {
2495 RAPIDJSON_DELETE(ownAllocator_);
2496 }
2497
2498 static const size_t kDefaultStackCapacity = 1024;
2499 Allocator* allocator_;
2500 Allocator* ownAllocator_;
2502 ParseResult parseResult_;
2503};
2504
2507
2509
2513template <bool Const, typename ValueT>
2515public:
2518 typedef ValueT PlainType;
2519 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2520 typedef ValueType* ValueIterator; // This may be const or non-const iterator
2521 typedef const ValueT* ConstValueIterator;
2522 typedef typename ValueType::AllocatorType AllocatorType;
2523 typedef typename ValueType::StringRefType StringRefType;
2524
2525 template <typename, typename>
2526 friend class GenericValue;
2527
2528 GenericArray(const GenericArray& rhs) : value_(rhs.value_) {}
2529 GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; }
2531
2532 SizeType Size() const { return value_.Size(); }
2533 SizeType Capacity() const { return value_.Capacity(); }
2534 bool Empty() const { return value_.Empty(); }
2535 void Clear() const { value_.Clear(); }
2536 ValueType& operator[](SizeType index) const { return value_[index]; }
2537 ValueIterator Begin() const { return value_.Begin(); }
2538 ValueIterator End() const { return value_.End(); }
2539 GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const { value_.Reserve(newCapacity, allocator); return *this; }
2540 GenericArray PushBack(ValueType& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2541#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2542 GenericArray PushBack(ValueType&& value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2543#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2544 GenericArray PushBack(StringRefType value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2545 template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (const GenericArray&)) PushBack(T value, AllocatorType& allocator) const { value_.PushBack(value, allocator); return *this; }
2546 GenericArray PopBack() const { value_.PopBack(); return *this; }
2547 ValueIterator Erase(ConstValueIterator pos) const { return value_.Erase(pos); }
2548 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const { return value_.Erase(first, last); }
2549
2550#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2551 ValueIterator begin() const { return value_.Begin(); }
2552 ValueIterator end() const { return value_.End(); }
2553#endif
2554
2555private:
2556 GenericArray();
2557 GenericArray(ValueType& value) : value_(value) {}
2558 ValueType& value_;
2559};
2560
2562
2566template <bool Const, typename ValueT>
2568public:
2571 typedef ValueT PlainType;
2572 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2575 typedef typename ValueType::AllocatorType AllocatorType;
2576 typedef typename ValueType::StringRefType StringRefType;
2577 typedef typename ValueType::EncodingType EncodingType;
2578 typedef typename ValueType::Ch Ch;
2579
2580 template <typename, typename>
2581 friend class GenericValue;
2582
2583 GenericObject(const GenericObject& rhs) : value_(rhs.value_) {}
2584 GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; }
2586
2587 SizeType MemberCount() const { return value_.MemberCount(); }
2588 SizeType MemberCapacity() const { return value_.MemberCapacity(); }
2589 bool ObjectEmpty() const { return value_.ObjectEmpty(); }
2590 template <typename T> ValueType& operator[](T* name) const { return value_[name]; }
2591 template <typename SourceAllocator> ValueType& operator[](const GenericValue<EncodingType, SourceAllocator>& name) const { return value_[name]; }
2592#if RAPIDJSON_HAS_STDSTRING
2593 ValueType& operator[](const std::basic_string<Ch>& name) const { return value_[name]; }
2594#endif
2595 MemberIterator MemberBegin() const { return value_.MemberBegin(); }
2596 MemberIterator MemberEnd() const { return value_.MemberEnd(); }
2597 GenericObject MemberReserve(SizeType newCapacity, AllocatorType &allocator) const { value_.MemberReserve(newCapacity, allocator); return *this; }
2598 bool HasMember(const Ch* name) const { return value_.HasMember(name); }
2599#if RAPIDJSON_HAS_STDSTRING
2600 bool HasMember(const std::basic_string<Ch>& name) const { return value_.HasMember(name); }
2601#endif
2602 template <typename SourceAllocator> bool HasMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.HasMember(name); }
2603 MemberIterator FindMember(const Ch* name) const { return value_.FindMember(name); }
2604 template <typename SourceAllocator> MemberIterator FindMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.FindMember(name); }
2605#if RAPIDJSON_HAS_STDSTRING
2606 MemberIterator FindMember(const std::basic_string<Ch>& name) const { return value_.FindMember(name); }
2607#endif
2608 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2609 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2610#if RAPIDJSON_HAS_STDSTRING
2611 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2612#endif
2613 template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&)) AddMember(ValueType& name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2614#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2615 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2616 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2617 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2618 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2619#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2620 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2621 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2622 template <typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericObject)) AddMember(StringRefType name, T value, AllocatorType& allocator) const { value_.AddMember(name, value, allocator); return *this; }
2623 void RemoveAllMembers() { value_.RemoveAllMembers(); }
2624 bool RemoveMember(const Ch* name) const { return value_.RemoveMember(name); }
2625#if RAPIDJSON_HAS_STDSTRING
2626 bool RemoveMember(const std::basic_string<Ch>& name) const { return value_.RemoveMember(name); }
2627#endif
2628 template <typename SourceAllocator> bool RemoveMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.RemoveMember(name); }
2629 MemberIterator RemoveMember(MemberIterator m) const { return value_.RemoveMember(m); }
2630 MemberIterator EraseMember(ConstMemberIterator pos) const { return value_.EraseMember(pos); }
2631 MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const { return value_.EraseMember(first, last); }
2632 bool EraseMember(const Ch* name) const { return value_.EraseMember(name); }
2633#if RAPIDJSON_HAS_STDSTRING
2634 bool EraseMember(const std::basic_string<Ch>& name) const { return EraseMember(ValueType(StringRef(name))); }
2635#endif
2636 template <typename SourceAllocator> bool EraseMember(const GenericValue<EncodingType, SourceAllocator>& name) const { return value_.EraseMember(name); }
2637
2638#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2639 MemberIterator begin() const { return value_.MemberBegin(); }
2640 MemberIterator end() const { return value_.MemberEnd(); }
2641#endif
2642
2643private:
2644 GenericObject();
2645 GenericObject(ValueType& value) : value_(value) {}
2646 ValueType& value_;
2647};
2648
2650RAPIDJSON_DIAG_POP
2651
2652#endif // RAPIDJSON_DOCUMENT_H_
const mie::Vuint & p
Definition bn.cpp:27
std::string name
Input byte stream wrapper with a statically bound encoding.
Helper class for accessing Value of array type.
Definition document.h:2514
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(const GenericArray &)) PushBack(T value
GenericArray PushBack(ValueType &value, AllocatorType &allocator) const
Definition document.h:2540
ValueIterator End() const
Definition document.h:2538
ValueIterator Begin() const
Definition document.h:2537
ValueType::StringRefType StringRefType
Definition document.h:2523
void Clear() const
Definition document.h:2535
SizeType Size() const
Definition document.h:2532
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition document.h:2519
GenericArray< false, ValueT > Array
Definition document.h:2517
GenericArray Reserve(SizeType newCapacity, AllocatorType &allocator) const
Definition document.h:2539
GenericArray & operator=(const GenericArray &rhs)
Definition document.h:2529
GenericArray< true, ValueT > ConstArray
Definition document.h:2516
ValueType * ValueIterator
Definition document.h:2520
GenericArray(const GenericArray &rhs)
Definition document.h:2528
ValueT PlainType
Definition document.h:2518
SizeType Capacity() const
Definition document.h:2533
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) const
Definition document.h:2548
GenericArray PushBack(StringRefType value, AllocatorType &allocator) const
Definition document.h:2544
ValueType::AllocatorType AllocatorType
Definition document.h:2522
ValueIterator Erase(ConstValueIterator pos) const
Definition document.h:2547
bool Empty() const
Definition document.h:2534
const ValueT * ConstValueIterator
Definition document.h:2521
ValueType & operator[](SizeType index) const
Definition document.h:2536
GenericArray PopBack() const
Definition document.h:2546
A document for parsing JSON text as DOM.
Definition document.h:2124
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:2231
Allocator & GetAllocator()
Get the allocator of this document.
Definition document.h:2412
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition document.h:2302
bool EndArray(SizeType elementCount)
Definition document.h:2473
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:2126
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition document.h:2206
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition document.h:2336
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition document.h:2137
GenericDocument & Parse(const Ch *str, size_t length)
Definition document.h:2357
bool EndObject(SizeType memberCount)
Definition document.h:2465
bool Bool(bool b)
Definition document.h:2438
bool Uint64(uint64_t i)
Definition document.h:2442
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition document.h:2388
bool Uint(unsigned i)
Definition document.h:2440
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition document.h:2278
bool Key(const Ch *str, SizeType length, bool copy)
Definition document.h:2463
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition document.h:2150
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition document.h:2288
GenericDocument & Parse(const Ch *str, size_t length)
Definition document.h:2361
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition document.h:2259
bool Int(int i)
Definition document.h:2439
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2325
bool Int64(int64_t i)
Definition document.h:2441
bool Double(double d)
Definition document.h:2443
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition document.h:2391
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition document.h:2311
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition document.h:2418
bool StartObject()
Definition document.h:2461
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition document.h:2239
bool String(const Ch *str, SizeType length, bool copy)
Definition document.h:2453
bool StartArray()
Definition document.h:2471
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition document.h:2394
GenericDocument & Parse(const typename SourceEncoding::Ch *str, size_t length)
Definition document.h:2348
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:2128
bool RawNumber(const Ch *str, SizeType length, bool copy)
Definition document.h:2445
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition document.h:2127
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition document.h:2343
(Constant) member iterator for a JSON object value
Definition document.h:102
difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition document.h:132
bool operator==(ConstIterator that) const
Definition document.h:178
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition document.h:114
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition document.h:156
GenericMemberIterator()
Default constructor (singular value)
Definition document.h:138
bool operator!=(ConstIterator that) const
Definition document.h:179
Iterator & operator=(const NonConstIterator &it)
Definition document.h:157
Iterator operator-(DifferenceType n) const
Definition document.h:170
Iterator & operator++()
Definition document.h:161
Reference operator[](DifferenceType n) const
Definition document.h:190
Iterator operator--(int)
Definition document.h:164
Iterator operator+(DifferenceType n) const
Definition document.h:169
GenericMemberIterator Iterator
Iterator type itself.
Definition document.h:112
Reference operator*() const
Definition document.h:188
bool operator<=(ConstIterator that) const
Definition document.h:180
Iterator & operator+=(DifferenceType n)
Definition document.h:172
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition document.h:116
bool operator>=(ConstIterator that) const
Definition document.h:181
std::random_access_iterator_tag iterator_category
Definition document.h:124
Iterator operator++(int)
Definition document.h:163
std::ptrdiff_t difference_type
Definition document.h:123
ValueType * pointer
Definition document.h:121
reference Reference
Reference to (const) GenericMember.
Definition document.h:130
ValueType & reference
Definition document.h:122
friend class GenericMemberIterator
Definition document.h:105
Iterator & operator-=(DifferenceType n)
Definition document.h:173
Pointer operator->() const
Definition document.h:189
bool operator<(ConstIterator that) const
Definition document.h:182
DifferenceType operator-(ConstIterator that) const
Distance.
Definition document.h:194
Iterator & operator--()
Definition document.h:162
bool operator>(ConstIterator that) const
Definition document.h:183
pointer Pointer
Pointer to (const) GenericMember.
Definition document.h:128
Helper class for accessing Value of object type.
Definition document.h:2567
MemberIterator RemoveMember(MemberIterator m) const
Definition document.h:2629
GenericObject AddMember(StringRefType name, ValueType &value, AllocatorType &allocator) const
Definition document.h:2620
SizeType MemberCapacity() const
Definition document.h:2588
bool HasMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition document.h:2602
GenericObject(const GenericObject &rhs)
Definition document.h:2583
void RemoveAllMembers()
Definition document.h:2623
MemberIterator FindMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition document.h:2604
SizeType MemberCount() const
Definition document.h:2587
ValueType & operator[](const GenericValue< EncodingType, SourceAllocator > &name) const
Definition document.h:2591
ValueType::Ch Ch
Definition document.h:2578
ValueT PlainType
Definition document.h:2571
MemberIterator EraseMember(ConstMemberIterator pos) const
Definition document.h:2630
ValueType & operator[](T *name) const
Definition document.h:2590
GenericObject AddMember(ValueType &name, ValueType &value, AllocatorType &allocator) const
Definition document.h:2608
GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType &allocator) const
Definition document.h:2621
bool EraseMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition document.h:2636
ValueType::EncodingType EncodingType
Definition document.h:2577
internal::MaybeAddConst< Const, PlainType >::Type ValueType
Definition document.h:2572
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last) const
Definition document.h:2631
MemberIterator MemberEnd() const
Definition document.h:2596
bool RemoveMember(const GenericValue< EncodingType, SourceAllocator > &name) const
Definition document.h:2628
MemberIterator FindMember(const Ch *name) const
Definition document.h:2603
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(ValueType &)) AddMember(ValueType &name
GenericObject & operator=(const GenericObject &rhs)
Definition document.h:2584
bool HasMember(const Ch *name) const
Definition document.h:2598
bool ObjectEmpty() const
Definition document.h:2589
GenericMemberIterator< Const, typename ValueT::EncodingType, typename ValueT::AllocatorType > MemberIterator
Definition document.h:2573
GenericMemberIterator< true, typename ValueT::EncodingType, typename ValueT::AllocatorType > ConstMemberIterator
Definition document.h:2574
ValueType::AllocatorType AllocatorType
Definition document.h:2575
GenericObject< false, ValueT > Object
Definition document.h:2570
GenericObject< true, ValueT > ConstObject
Definition document.h:2569
ValueType::StringRefType StringRefType
Definition document.h:2576
GenericObject AddMember(ValueType &name, StringRefType value, AllocatorType &allocator) const
Definition document.h:2609
bool RemoveMember(const Ch *name) const
Definition document.h:2624
bool EraseMember(const Ch *name) const
Definition document.h:2632
MemberIterator MemberBegin() const
Definition document.h:2595
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T >, internal::IsGenericValue< T > >),(GenericObject)) AddMember(StringRefType name
GenericObject MemberReserve(SizeType newCapacity, AllocatorType &allocator) const
Definition document.h:2597
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition pointer.h:79
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition reader.h:537
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition document.h:578
GenericArray< false, ValueType > Array
Definition document.h:591
Encoding EncodingType
Encoding type from template parameter.
Definition document.h:582
GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition document.h:701
void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT
Initialize this value as constant string, without calling destructor.
Definition document.h:2060
static const SizeType kDefaultArrayCapacity
Definition document.h:1942
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition document.h:2029
~GenericValue()
Destructor.
Definition document.h:800
GenericArray< true, ValueType > ConstArray
Definition document.h:592
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition document.h:751
void SetObjectRaw(Member *members, SizeType count, Allocator &allocator)
Initialize this value as object with initial data, without calling destructor.
Definition document.h:2047
static const SizeType kDefaultObjectCapacity
Definition document.h:1943
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition document.h:856
RAPIDJSON_FORCEINLINE GenericValue * GetElementsPointer() const
Definition document.h:2028
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition document.h:581
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:584
RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer< T >),(GenericValue &)) operator
Assignment with primitive types.
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:757
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition document.h:588
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition document.h:585
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition document.h:2031
GenericObject< true, ValueType > ConstObject
Definition document.h:594
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition document.h:652
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:583
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition document.h:630
RAPIDJSON_FORCEINLINE Member * GetMembersPointer() const
Definition document.h:2030
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator)
Definition document.h:2034
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition document.h:781
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition document.h:724
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition document.h:718
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:766
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition document.h:792
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:763
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition document.h:586
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition document.h:712
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition document.h:600
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition document.h:2027
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:760
void RawAssign(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment without calling destructor.
Definition document.h:2084
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition document.h:754
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition document.h:739
void SetStringRaw(StringRefType s, Allocator &allocator)
Initialize this value as copy string with initial data, without calling destructor.
Definition document.h:2067
bool StringEqual(const GenericValue< Encoding, SourceAllocator > &rhs) const
Definition document.h:2091
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition document.h:836
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition document.h:590
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition document.h:587
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition document.h:589
GenericObject< false, ValueType > Object
Definition document.h:593
RAPIDJSON_FORCEINLINE const Ch * GetStringPointer() const
Definition document.h:2026
A type-unsafe stack for storing different types of data.
Definition stack.h:37
void Clear()
Definition stack.h:99
void ShrinkToFit()
Definition stack.h:101
void Swap(Stack &rhs) RAPIDJSON_NOEXCEPT
Definition stack.h:90
bool HasAllocator() const
Definition stack.h:168
size_t GetCapacity() const
Definition stack.h:179
Allocator & GetAllocator()
Definition stack.h:172
size_t GetSize() const
Definition stack.h:178
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition document.h:2110
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:364
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition document.h:2506
bool operator!=(const environment &other)
bool operator==(const environment &other)
int * count
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
Assertion (in non-throwing contexts).
Definition rapidjson.h:618
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition rapidjson.h:463
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:476
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:406
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition rapidjson.h:124
ParseErrorCode
Error code of parsing.
Definition error.h:64
#define Ch(x, y, z)
Definition hash_impl.h:17
return str
Definition CLI11.hpp:1359
ValueType
Definition Types.h:14
bip::allocator< T, pinnable_mapped_file::segment_manager > allocator
Definition chainbase.hpp:56
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition swap.h:33
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition strfunc.h:31
Definition name.hpp:106
void swap(picojson::value &x, picojson::value &y)
GTEST_API_ bool IsTrue(bool condition)
Definition gtest.cc:5404
#define value
Definition pkcs11.h:157
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define T(meth, val, expected)
const int N
Definition quantize.cpp:54
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition rapidjson.h:318
Type
Type of JSON value.
Definition rapidjson.h:644
@ kFalseType
false
Definition rapidjson.h:646
@ kObjectType
object
Definition rapidjson.h:648
@ kTrueType
true
Definition rapidjson.h:647
@ kStringType
string
Definition rapidjson.h:650
@ kNullType
null
Definition rapidjson.h:645
@ kArrayType
array
Definition rapidjson.h:649
@ kNumberType
number
Definition rapidjson.h:651
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition rapidjson.h:631
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition rapidjson.h:384
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:289
#define RAPIDJSON_GETPOINTER(type, p)
Definition rapidjson.h:319
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition rapidjson.h:627
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition rapidjson.h:445
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition reader.h:147
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned __int64 uint64_t
Definition stdint.h:136
A read-write string stream.
Definition stream.h:188
Name-value pair in a JSON object value.
Definition document.h:66
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition document.h:67
GenericValue< Encoding, Allocator > value
value of member.
Definition document.h:68
friend void swap(GenericMember &a, GenericMember &b) RAPIDJSON_NOEXCEPT
Definition document.h:71
Reference to a constant string (not taking a copy)
Definition document.h:256
CharType Ch
character type of the string
Definition document.h:257
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition document.h:330
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string.
Definition document.h:384
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition document.h:321
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition document.h:309
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:364
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition document.h:285
GenericStringRef(const GenericStringRef &rhs)
Definition document.h:324
const Ch *const s
plain CharType pointer
Definition document.h:329
Read-only string stream.
Definition stream.h:154
GenericValue * elements
Definition document.h:2014
char payload[sizeof(SizeType) *2+sizeof(void *)+2]
Definition document.h:1951
SizeType GetLength() const
Definition document.h:1976
static bool Usable(SizeType len)
Definition document.h:1974
void SetLength(SizeType len)
Definition document.h:1975
SizeType hashcode
reserved
Definition document.h:1958
Represents an in-memory input byte stream.
Result of parsing (wraps ParseErrorCode)
Definition error.h:106
ParseErrorCode Code() const
Get the error code.
Definition error.h:116
bool IsError() const
Whether the result is an error.
Definition error.h:123
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition error.h:118
static bool Is(const ValueType &v)
Definition document.h:433
static ValueType & Set(ValueType &v, bool data, typename ValueType::AllocatorType &)
Definition document.h:436
static ValueType & Set(ValueType &v, bool data)
Definition document.h:435
static bool Get(const ValueType &v)
Definition document.h:434
static ValueType & Set(ValueType &v, const StringType data)
Definition document.h:512
static ValueType & Set(ValueType &v, const StringType data, typename ValueType::AllocatorType &a)
Definition document.h:513
static ValueType & Set(ValueType &v, double data, typename ValueType::AllocatorType &)
Definition document.h:496
static bool Is(const ValueType &v)
Definition document.h:493
static ValueType & Set(ValueType &v, double data)
Definition document.h:495
static double Get(const ValueType &v)
Definition document.h:494
static bool Is(const ValueType &v)
Definition document.h:501
static ValueType & Set(ValueType &v, float data)
Definition document.h:503
static float Get(const ValueType &v)
Definition document.h:502
static ValueType & Set(ValueType &v, float data, typename ValueType::AllocatorType &)
Definition document.h:504
static ValueType & Set(ValueType &v, int64_t data, typename ValueType::AllocatorType &)
Definition document.h:480
static ValueType & Set(ValueType &v, int64_t data)
Definition document.h:479
static bool Is(const ValueType &v)
Definition document.h:477
static int64_t Get(const ValueType &v)
Definition document.h:478
static ValueType & Set(ValueType &v, int data, typename ValueType::AllocatorType &)
Definition document.h:444
static ValueType & Set(ValueType &v, int data)
Definition document.h:443
static int Get(const ValueType &v)
Definition document.h:442
static bool Is(const ValueType &v)
Definition document.h:441
static ValueType & Set(ValueType &v, ArrayType data)
Definition document.h:531
static ValueType & Set(ValueType &v, ArrayType data, typename ValueType::AllocatorType &)
Definition document.h:532
static ValueType & Set(ValueType &v, ObjectType data)
Definition document.h:547
static ValueType & Set(ValueType &v, ObjectType data, typename ValueType::AllocatorType &)
Definition document.h:548
static uint64_t Get(const ValueType &v)
Definition document.h:486
static bool Is(const ValueType &v)
Definition document.h:485
static ValueType & Set(ValueType &v, uint64_t data, typename ValueType::AllocatorType &)
Definition document.h:488
static ValueType & Set(ValueType &v, uint64_t data)
Definition document.h:487
static ValueType & Set(ValueType &v, unsigned data)
Definition document.h:451
static unsigned Get(const ValueType &v)
Definition document.h:450
static bool Is(const ValueType &v)
Definition document.h:449
static ValueType & Set(ValueType &v, unsigned data, typename ValueType::AllocatorType &)
Definition document.h:452
ShortString ss
Definition document.h:2019
struct GenericValue::Number::I i
struct GenericValue::Number::U u
Definition dtoa.c:306
yh_object_type type
Definition yubihsm.h:672
CK_ULONG d
char * s
size_t len