15#ifndef RAPIDJSON_DOCUMENT_H_
16#define RAPIDJSON_DOCUMENT_H_
21#include "internal/meta.h"
22#include "internal/strfunc.h"
23#include "memorystream.h"
24#include "encodedstream.h"
27#ifdef __cpp_lib_three_way_comparison
33RAPIDJSON_DIAG_OFF(4127)
34RAPIDJSON_DIAG_OFF(4244)
38RAPIDJSON_DIAG_OFF(padded)
39RAPIDJSON_DIAG_OFF(
switch-
enum)
40RAPIDJSON_DIAG_OFF(c++98-compat)
44RAPIDJSON_DIAG_OFF(effc++)
46RAPIDJSON_DIAG_OFF(terminate)
50#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
54#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
58RAPIDJSON_NAMESPACE_BEGIN
61template <
typename Encoding,
typename Allocator>
64template <
typename Encoding,
typename Allocator,
typename StackAllocator>
73template <
typename Encoding,
typename Allocator>
82#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
103template <
bool Const,
typename Encoding,
typename Allocator>
104class GenericMemberIterator
105 :
public std::iterator<std::random_access_iterator_tag
106 , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
109 template <
bool,
typename,
typename>
friend class GenericMemberIterator;
112 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
113 typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
153 Iterator& operator=(
const NonConstIterator & it) { ptr_ = it.ptr_;
return *
this; }
157 Iterator& operator++(){ ++ptr_;
return *
this; }
158 Iterator& operator--(){ --ptr_;
return *
this; }
159 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
160 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
165 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
166 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
168 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
169 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
174 template <
bool Const_>
bool operator==(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ == that.ptr_; }
175 template <
bool Const_>
bool operator!=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ != that.ptr_; }
176 template <
bool Const_>
bool operator<=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ <= that.ptr_; }
177 template <
bool Const_>
bool operator>=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ >= that.ptr_; }
178 template <
bool Const_>
bool operator< (
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ < that.ptr_; }
179 template <
bool Const_>
bool operator> (
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ > that.ptr_; }
181#ifdef __cpp_lib_three_way_comparison
182 template <
bool Const_> std::strong_ordering operator<=>(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ <=> that.ptr_; }
188 Reference operator*()
const {
return *ptr_; }
189 Pointer operator->()
const {
return ptr_; }
190 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
207template <
bool Const,
typename Encoding,
typename Allocator>
208struct GenericMemberIterator;
211template <
typename Encoding,
typename Allocator>
214 typedef GenericMember<Encoding,Allocator>* Iterator;
217template <
typename Encoding,
typename Allocator>
220 typedef const GenericMember<Encoding,Allocator>* Iterator;
255template<
typename CharType>
327 operator const Ch *()
const {
return s; }
352template<
typename CharType>
372template<
typename CharType>
377#if RAPIDJSON_HAS_STDSTRING
390template<
typename CharType>
400template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
401struct IsGenericValueImpl : FalseType {};
404template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
405 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
408template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>::Type {};
417template <
typename ValueType,
typename T>
420template<
typename ValueType>
421struct TypeHelper<ValueType, bool> {
422 static bool Is(
const ValueType& v) {
return v.IsBool(); }
423 static bool Get(
const ValueType& v) {
return v.GetBool(); }
424 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
425 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
428template<
typename ValueType>
429struct TypeHelper<ValueType, int> {
430 static bool Is(
const ValueType& v) {
return v.IsInt(); }
431 static int Get(
const ValueType& v) {
return v.GetInt(); }
432 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
433 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
436template<
typename ValueType>
437struct TypeHelper<ValueType, unsigned> {
438 static bool Is(
const ValueType& v) {
return v.IsUint(); }
439 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
440 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
441 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
444template<
typename ValueType>
445struct TypeHelper<ValueType, int64_t> {
446 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
447 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
448 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
449 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
452template<
typename ValueType>
453struct TypeHelper<ValueType, uint64_t> {
454 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
455 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
456 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
457 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
460template<
typename ValueType>
461struct TypeHelper<ValueType, double> {
462 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
463 static double Get(
const ValueType& v) {
return v.GetDouble(); }
464 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
465 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
468template<
typename ValueType>
469struct TypeHelper<ValueType, float> {
470 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
471 static float Get(
const ValueType& v) {
return v.GetFloat(); }
472 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
473 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
476template<
typename ValueType>
477struct TypeHelper<ValueType, const typename ValueType::Ch*> {
478 typedef const typename ValueType::Ch* StringType;
479 static bool Is(
const ValueType& v) {
return v.IsString(); }
480 static StringType Get(
const ValueType& v) {
return v.GetString(); }
481 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
482 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
485#if RAPIDJSON_HAS_STDSTRING
486template<
typename ValueType>
487struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
488 typedef std::basic_string<typename ValueType::Ch> StringType;
489 static bool Is(
const ValueType& v) {
return v.IsString(); }
490 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
491 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
495template<
typename ValueType>
496struct TypeHelper<ValueType, typename ValueType::Array> {
497 typedef typename ValueType::Array ArrayType;
498 static bool Is(
const ValueType& v) {
return v.IsArray(); }
499 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
500 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
501 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
504template<
typename ValueType>
505struct TypeHelper<ValueType, typename ValueType::ConstArray> {
506 typedef typename ValueType::ConstArray ArrayType;
507 static bool Is(
const ValueType& v) {
return v.IsArray(); }
508 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
511template<
typename ValueType>
512struct TypeHelper<ValueType, typename ValueType::Object> {
513 typedef typename ValueType::Object ObjectType;
514 static bool Is(
const ValueType& v) {
return v.IsObject(); }
515 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
516 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
517 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) { v = data; }
520template<
typename ValueType>
521struct TypeHelper<ValueType, typename ValueType::ConstObject> {
522 typedef typename ValueType::ConstObject ObjectType;
523 static bool Is(
const ValueType& v) {
return v.IsObject(); }
524 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
530template <
bool,
typename>
class GenericArray;
531template <
bool,
typename>
class GenericObject;
546template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
553 typedef typename Encoding::Ch
Ch;
569 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
571#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
574 rhs.data_.f.flags = kNullFlag;
580 GenericValue(
const GenericValue& rhs);
582#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
584 template <
typename StackAllocator>
585 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
588 template <
typename StackAllocator>
589 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
600 static const uint16_t defaultFlags[7] = {
601 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
605 data_.f.flags = defaultFlags[type];
609 data_.ss.SetLength(0);
619 template<
typename SourceAllocator >
628#ifndef RAPIDJSON_DOXYGEN_RUNNING
629 template <
typename T>
630 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT
637 data_.f.flags = b ? kTrueFlag : kFalseFlag;
643 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
649 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
655 data_.f.flags = kNumberInt64Flag;
657 data_.f.flags |= kNumberUint64Flag;
659 data_.f.flags |= kUintFlag;
661 data_.f.flags |= kIntFlag;
664 data_.f.flags |= kIntFlag;
670 data_.f.flags = kNumberUint64Flag;
672 data_.f.flags |= kInt64Flag;
674 data_.f.flags |= kUintFlag;
676 data_.f.flags |= kIntFlag;
680 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
694#if RAPIDJSON_HAS_STDSTRING
708 a.value_.data_ = Data();
709 a.value_.data_.f.flags = kArrayFlag;
719 o.value_.data_ = Data();
720 o.value_.data_.f.flags = kObjectFlag;
727 if (Allocator::kNeedFree) {
728 switch(data_.f.flags) {
731 GenericValue* e = GetElementsPointer();
732 for (GenericValue* v = e; v != e + data_.a.size; ++v)
741 Allocator::Free(GetMembersPointer());
744 case kCopyStringFlag:
745 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
762 GenericValue&
operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
764 this->~GenericValue();
769#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
772 return *
this = rhs.Move();
798 template <
typename T>
799 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
801 GenericValue v(value);
811 template <
typename SourceAllocator>
812 GenericValue&
CopyFrom(
const GenericValue<Encoding, SourceAllocator>& rhs,
Allocator& allocator) {
813 RAPIDJSON_ASSERT(
static_cast<void*
>(
this) !=
static_cast<void const*
>(&rhs));
814 this->~GenericValue();
815 new (
this) GenericValue(rhs, allocator);
824 GenericValue&
Swap(GenericValue& other) RAPIDJSON_NOEXCEPT {
826 temp.RawAssign(*
this);
828 other.RawAssign(temp);
844 friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); }
848 GenericValue&
Move() RAPIDJSON_NOEXCEPT {
return *
this; }
858 template <
typename SourceAllocator>
859 bool operator==(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
860 typedef GenericValue<Encoding, SourceAllocator> RhsType;
861 if (GetType() != rhs.GetType())
866 if (data_.o.size != rhs.data_.o.size)
869 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.
FindMember(lhsMemberItr->name);
870 if (rhsMemberItr == rhs.
MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
876 if (data_.a.size != rhs.data_.a.size)
878 for (
SizeType i = 0; i < data_.a.size; i++)
879 if ((*
this)[i] != rhs[i])
884 return StringEqual(rhs);
887 if (IsDouble() || rhs.IsDouble()) {
890 return a >= b && a <= b;
893 return data_.n.u64 == rhs.data_.n.u64;
903#if RAPIDJSON_HAS_STDSTRING
907 bool operator==(
const std::basic_string<Ch>& rhs)
const {
return *
this ==
GenericValue(
StringRef(rhs)); }
913 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this == GenericValue(rhs); }
915#ifndef __cpp_impl_three_way_comparison
919 template <
typename SourceAllocator>
920 bool operator!=(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
return !(*
this == rhs); }
928 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
933 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
938 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
945 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
946 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
947 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
948 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
949 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
950 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
951 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
952 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
953 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
954 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
955 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
956 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
957 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
958 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
961 bool IsLosslessDouble()
const {
962 if (!IsNumber())
return false;
964 uint64_t u = GetUint64();
965 volatile double d =
static_cast<double>(u);
967 && (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
968 && (u ==
static_cast<uint64_t
>(d));
971 int64_t i = GetInt64();
972 volatile double d =
static_cast<double>(i);
973 return (d >=
static_cast<double>(std::numeric_limits<int64_t>::min()))
974 && (d < static_cast<double>(std::numeric_limits<int64_t>::max()))
975 && (i ==
static_cast<int64_t
>(d));
981 bool IsFloat()
const {
982 if ((data_.f.flags & kDoubleFlag) == 0)
984 double d = GetDouble();
985 return d >= -3.4028234e38 && d <= 3.4028234e38;
988 bool IsLosslessFloat()
const {
989 if (!IsNumber())
return false;
990 double a = GetDouble();
991 if (a <
static_cast<double>(-std::numeric_limits<float>::max())
992 || a >
static_cast<double>(std::numeric_limits<float>::max()))
994 double b =
static_cast<double>(
static_cast<float>(a));
995 return a >= b && a <= b;
1003 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1013 GenericValue&
SetBool(
bool b) { this->~GenericValue();
new (
this) GenericValue(b);
return *
this; }
1039 template <
typename T>
1040 RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<
typename internal::RemoveConst<T>::Type,
Ch> >),(GenericValue&))
operator[](T* name) {
1044 template <
typename T>
1045 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]; }
1056 template <
typename SourceAllocator>
1057 GenericValue&
operator[](
const GenericValue<Encoding, SourceAllocator>& name) {
1060 return member->value;
1069 static char buffer[
sizeof(GenericValue)];
1070 return *
new (buffer) GenericValue();
1073 template <
typename SourceAllocator>
1076#if RAPIDJSON_HAS_STDSTRING
1078 GenericValue& operator[](
const std::basic_string<Ch>& name) {
return (*
this)[GenericValue(StringRef(name))]; }
1079 const GenericValue& operator[](
const std::basic_string<Ch>& name)
const {
return (*
this)[GenericValue(
StringRef(name))]; }
1105#if RAPIDJSON_HAS_STDSTRING
1114 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1126 template <
typename SourceAllocator>
1146 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1161 template <
typename SourceAllocator>
1166 for ( ; member !=
MemberEnd(); ++member)
1167 if (name.StringEqual(member->name))
1173#if RAPIDJSON_HAS_STDSTRING
1181 MemberIterator FindMember(
const std::basic_string<Ch>& name) {
return FindMember(GenericValue(StringRef(name))); }
1182 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(GenericValue(
StringRef(name))); }
1199 ObjectData& o = data_.o;
1200 if (o.size >= o.capacity) {
1201 if (o.capacity == 0) {
1202 o.capacity = kDefaultObjectCapacity;
1203 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Malloc(o.capacity *
sizeof(
Member))));
1207 o.capacity += (oldCapacity + 1) / 2;
1208 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Realloc(GetMembersPointer(), oldCapacity *
sizeof(
Member), o.capacity *
sizeof(
Member))));
1211 Member* members = GetMembersPointer();
1212 members[o.size].
name.RawAssign(name);
1213 members[o.size].
value.RawAssign(value);
1228 GenericValue v(value);
1232#if RAPIDJSON_HAS_STDSTRING
1244 return AddMember(name, v, allocator);
1265 template <
typename T>
1266 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1268 GenericValue v(value);
1272#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1274 return AddMember(name, value, allocator);
1276 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1277 return AddMember(name, value, allocator);
1279 GenericValue& AddMember(GenericValue& name, GenericValue&& value, Allocator& allocator) {
1280 return AddMember(name, value, allocator);
1282 GenericValue& AddMember(StringRefType name, GenericValue&& value, Allocator& allocator) {
1283 GenericValue n(name);
1284 return AddMember(n, value, allocator);
1300 GenericValue n(name);
1314 GenericValue v(value);
1335 template <
typename T>
1336 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1338 GenericValue n(name);
1366#if RAPIDJSON_HAS_STDSTRING
1367 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1370 template <
typename SourceAllocator>
1371 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1372 MemberIterator m = FindMember(name);
1373 if (m != MemberEnd()) {
1396 if (data_.o.size > 1 && m != last)
1437 std::memmove(&*pos, &*last,
static_cast<size_t>(
MemberEnd() - last) *
sizeof(
Member));
1438 data_.o.size -=
static_cast<SizeType>(last - first);
1452#if RAPIDJSON_HAS_STDSTRING
1453 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1456 template <
typename SourceAllocator>
1457 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1458 MemberIterator m = FindMember(name);
1459 if (m != MemberEnd()) {
1468 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1494 GenericValue* e = GetElementsPointer();
1495 for (GenericValue* v = e; v != e + data_.a.size; ++v)
1508 return GetElementsPointer()[index];
1533 if (newCapacity > data_.a.capacity) {
1534 SetElementsPointer(
reinterpret_cast<GenericValue*
>(allocator.Realloc(GetElementsPointer(), data_.a.capacity *
sizeof(GenericValue), newCapacity *
sizeof(GenericValue))));
1535 data_.a.capacity = newCapacity;
1552 if (data_.a.size >= data_.a.capacity)
1553 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1554 GetElementsPointer()[data_.a.size++].RawAssign(value);
1558#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1560 return PushBack(value, allocator);
1594 template <
typename T>
1595 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1597 GenericValue v(value);
1608 GetElementsPointer()[--data_.a.size].~GenericValue();
1620 return Erase(pos, pos + 1);
1640 itr->~GenericValue();
1641 std::memmove(pos, last,
static_cast<size_t>(
End() - last) *
sizeof(GenericValue));
1642 data_.a.size -=
static_cast<SizeType>(last - first);
1647 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1654 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1655 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1656 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1657 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1664 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1665 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1666 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1667 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1668 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1679 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1680 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1681 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1682 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1683 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(f);
return *
this; }
1690 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1732#if RAPIDJSON_HAS_STDSTRING
1740 GenericValue& SetString(
const std::basic_string<Ch>& s,
Allocator& allocator) {
return SetString(s.data(),
SizeType(s.size()), allocator); }
1752 template <
typename T>
1753 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1755 template <
typename T>
1756 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1758 template <
typename T>
1759 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1761 template<
typename T>
1762 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1764 template<
typename T>
1765 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1776 template <
typename Handler>
1781 case kTrueType:
return handler.Bool(
true);
1788 if (
RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1793 return handler.EndObject(data_.o.size);
1798 for (
const GenericValue* v =
Begin(); v !=
End(); ++v)
1801 return handler.EndArray(data_.a.size);
1804 return handler.String(GetString(),
GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1808 if (IsDouble())
return handler.Double(data_.n.d);
1809 else if (IsInt())
return handler.Int(data_.n.i.i);
1810 else if (IsUint())
return handler.Uint(data_.n.u.u);
1811 else if (IsInt64())
return handler.Int64(data_.n.i64);
1812 else return handler.Uint64(data_.n.u64);
1817 template <
typename,
typename>
friend class GenericValue;
1822 kNumberFlag = 0x0010,
1825 kInt64Flag = 0x0080,
1826 kUint64Flag = 0x0100,
1827 kDoubleFlag = 0x0200,
1828 kStringFlag = 0x0400,
1830 kInlineStrFlag = 0x1000,
1836 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1837 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1838 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1839 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1840 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1841 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1843 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1844 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1851 static const SizeType kDefaultArrayCapacity = 16;
1852 static const SizeType kDefaultObjectCapacity = 16;
1855#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1856 char payload[
sizeof(SizeType) * 2 + 6];
1857#elif RAPIDJSON_64BIT
1858 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 6];
1860 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 2];
1879 struct ShortString {
1880 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1883 inline static bool Usable(SizeType len) {
return (MaxSize >= len); }
1884 inline void SetLength(SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
1885 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
1890#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1923 GenericValue* elements;
1935 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
1936 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
1937 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
1938 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
1939 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
1940 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
1943 void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
1944 data_.f.flags = kArrayFlag;
1946 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
1947 SetElementsPointer(e);
1948 std::memcpy(e, values, count *
sizeof(GenericValue));
1951 SetElementsPointer(0);
1952 data_.a.size = data_.a.capacity = count;
1956 void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
1957 data_.f.flags = kObjectFlag;
1959 Member* m =
static_cast<Member*
>(allocator.Malloc(count *
sizeof(Member)));
1960 SetMembersPointer(m);
1961 std::memcpy(m, members, count *
sizeof(Member));
1964 SetMembersPointer(0);
1965 data_.o.size = data_.o.capacity = count;
1969 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
1970 data_.f.flags = kConstStringFlag;
1971 SetStringPointer(s);
1972 data_.s.length = s.length;
1976 void SetStringRaw(StringRefType s, Allocator& allocator) {
1978 if (ShortString::Usable(s.length)) {
1979 data_.f.flags = kShortStringFlag;
1980 data_.ss.SetLength(s.length);
1983 data_.f.flags = kCopyStringFlag;
1984 data_.s.length = s.length;
1985 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
1986 SetStringPointer(str);
1988 std::memcpy(str, s, s.length *
sizeof(Ch));
1989 str[s.length] =
'\0';
1993 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
1996 rhs.data_.f.flags = kNullFlag;
1999 template <
typename SourceAllocator>
2000 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
2004 const SizeType len1 = GetStringLength();
2005 const SizeType len2 = rhs.GetStringLength();
2006 if(len1 != len2) {
return false; }
2008 const Ch*
const str1 = GetString();
2009 const Ch*
const str2 = rhs.GetString();
2010 if(str1 == str2) {
return true; }
2012 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2032template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
2035 typedef typename Encoding::Ch
Ch;
2047 GenericValue<
Encoding,
Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2060 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2066#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2069 : ValueType(std::forward<ValueType>(rhs)),
2070 allocator_(rhs.allocator_),
2071 ownAllocator_(rhs.ownAllocator_),
2072 stack_(std::move(rhs.stack_)),
2073 parseResult_(rhs.parseResult_)
2076 rhs.ownAllocator_ = 0;
2081 ~GenericDocument() {
2085#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2087 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2091 ValueType::operator=(std::forward<ValueType>(rhs));
2096 allocator_ = rhs.allocator_;
2097 ownAllocator_ = rhs.ownAllocator_;
2098 stack_ = std::move(rhs.stack_);
2099 parseResult_ = rhs.parseResult_;
2102 rhs.ownAllocator_ = 0;
2103 rhs.parseResult_ = ParseResult();
2117 stack_.Swap(rhs.stack_);
2118 internal::Swap(allocator_, rhs.allocator_);
2119 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2120 internal::Swap(parseResult_, rhs.parseResult_);
2143 template <
typename Generator>
2145 ClearStackOnExit scope(*
this);
2163 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2166 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2167 ClearStackOnExit scope(*
this);
2182 template <
unsigned parseFlags,
typename InputStream>
2192 template <
typename InputStream>
2206 template <
unsigned parseFlags>
2229 template <
unsigned parseFlags,
typename SourceEncoding>
2240 template <
unsigned parseFlags>
2252 template <
unsigned parseFlags,
typename SourceEncoding>
2253 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2255 MemoryStream ms(
static_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2257 ParseStream<parseFlags, SourceEncoding>(is);
2261 template <
unsigned parseFlags>
2262 GenericDocument& Parse(
const Ch* str,
size_t length) {
2263 return Parse<parseFlags, Encoding>(str, length);
2266 GenericDocument& Parse(
const Ch* str,
size_t length) {
2267 return Parse<kParseDefaultFlags>(str, length);
2270#if RAPIDJSON_HAS_STDSTRING
2271 template <
unsigned parseFlags,
typename SourceEncoding>
2272 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2274 return Parse<parseFlags, SourceEncoding>(str.c_str());
2277 template <
unsigned parseFlags>
2278 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2279 return Parse<parseFlags, Encoding>(str.c_str());
2282 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2283 return Parse<kParseDefaultFlags>(str);
2327 struct ClearStackOnExit {
2329 ~ClearStackOnExit() { d_.ClearStack(); }
2331 ClearStackOnExit(
const ClearStackOnExit&);
2332 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2333 GenericDocument& d_;
2338 template <
typename,
typename>
friend class GenericValue;
2342 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2343 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2344 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2345 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2346 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2347 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2348 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2350 bool RawNumber(
const Ch* str, SizeType length,
bool copy) {
2352 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2354 new (stack_.template Push<ValueType>()) ValueType(str, length);
2358 bool String(
const Ch* str, SizeType length,
bool copy) {
2360 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2362 new (stack_.template Push<ValueType>()) ValueType(str, length);
2366 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(kObjectType);
return true; }
2368 bool Key(
const Ch* str, SizeType length,
bool copy) {
return String(str, length, copy); }
2370 bool EndObject(SizeType memberCount) {
2371 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2372 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2376 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(kArrayType);
return true; }
2378 bool EndArray(SizeType elementCount) {
2379 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2380 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2386 GenericDocument(
const GenericDocument&);
2388 GenericDocument& operator=(
const GenericDocument&);
2391 if (Allocator::kNeedFree)
2392 while (stack_.GetSize() > 0)
2393 (stack_.template Pop<ValueType>(1))->~ValueType();
2396 stack_.ShrinkToFit();
2403 static const size_t kDefaultStackCapacity = 1024;
2404 Allocator* allocator_;
2405 Allocator* ownAllocator_;
2406 internal::Stack<StackAllocator> stack_;
2407 ParseResult parseResult_;
2414template <
typename Encoding,
typename Allocator>
2415template <
typename SourceAllocator>
2417GenericValue<Encoding,Allocator>::GenericValue(
const GenericValue<Encoding,SourceAllocator>& rhs,
Allocator& allocator)
2419 switch (rhs.GetType()) {
2422 GenericDocument<Encoding,Allocator> d(&allocator);
2424 RawAssign(*d.stack_.template Pop<GenericValue>(1));
2428 if (rhs.data_.f.flags == kConstStringFlag) {
2429 data_.f.flags = rhs.data_.f.flags;
2430 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2436 data_.f.flags = rhs.data_.f.flags;
2437 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2447template <
bool Const,
typename ValueT>
2450 typedef GenericArray<true, ValueT> ConstArray;
2451 typedef GenericArray<false, ValueT> Array;
2452 typedef ValueT PlainType;
2453 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2454 typedef ValueType* ValueIterator;
2455 typedef const ValueT* ConstValueIterator;
2456 typedef typename ValueType::AllocatorType AllocatorType;
2457 typedef typename ValueType::StringRefType StringRefType;
2459 template <
typename,
typename>
2460 friend class GenericValue;
2462 GenericArray(
const GenericArray& rhs) : value_(rhs.value_) {}
2463 GenericArray& operator=(
const GenericArray& rhs) { value_ = rhs.value_;
return *
this; }
2466 SizeType Size()
const {
return value_.Size(); }
2467 SizeType Capacity()
const {
return value_.Capacity(); }
2468 bool Empty()
const {
return value_.Empty(); }
2469 void Clear()
const { value_.Clear(); }
2470 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2471 ValueIterator Begin()
const {
return value_.Begin(); }
2472 ValueIterator End()
const {
return value_.End(); }
2473 GenericArray Reserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.Reserve(newCapacity, allocator);
return *
this; }
2474 GenericArray PushBack(ValueType& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2475#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2476 GenericArray PushBack(ValueType&& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2478 GenericArray PushBack(StringRefType value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2479 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; }
2480 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2481 ValueIterator Erase(ConstValueIterator pos)
const {
return value_.Erase(pos); }
2482 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
const {
return value_.Erase(first, last); }
2484#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2485 ValueIterator begin()
const {
return value_.Begin(); }
2486 ValueIterator end()
const {
return value_.End(); }
2491 GenericArray(ValueType& value) : value_(value) {}
2500template <
bool Const,
typename ValueT>
2501class GenericObject {
2503 typedef GenericObject<true, ValueT> ConstObject;
2504 typedef GenericObject<false, ValueT> Object;
2505 typedef ValueT PlainType;
2506 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2509 typedef typename ValueType::AllocatorType AllocatorType;
2510 typedef typename ValueType::StringRefType StringRefType;
2511 typedef typename ValueType::EncodingType EncodingType;
2512 typedef typename ValueType::Ch Ch;
2514 template <
typename,
typename>
2515 friend class GenericValue;
2517 GenericObject(
const GenericObject& rhs) : value_(rhs.value_) {}
2518 GenericObject& operator=(
const GenericObject& rhs) { value_ = rhs.value_;
return *
this; }
2521 SizeType MemberCount()
const {
return value_.MemberCount(); }
2522 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2523 template <
typename T> ValueType& operator[](T* name)
const {
return value_[name]; }
2524 template <
typename SourceAllocator> ValueType& operator[](
const GenericValue<EncodingType, SourceAllocator>& name)
const {
return value_[name]; }
2525#if RAPIDJSON_HAS_STDSTRING
2526 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2528 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2529 MemberIterator MemberEnd()
const {
return value_.MemberEnd(); }
2530 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2531#if RAPIDJSON_HAS_STDSTRING
2532 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2534 template <
typename SourceAllocator>
bool HasMember(
const GenericValue<EncodingType, SourceAllocator>& name)
const {
return value_.HasMember(name); }
2535 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2536 template <
typename SourceAllocator> MemberIterator FindMember(
const GenericValue<EncodingType, SourceAllocator>& name)
const {
return value_.FindMember(name); }
2537#if RAPIDJSON_HAS_STDSTRING
2538 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2540 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2541 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2542#if RAPIDJSON_HAS_STDSTRING
2543 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2545 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; }
2546#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2547 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2548 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2549 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2550 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2552 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2553 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2554 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; }
2555 void RemoveAllMembers() {
return value_.RemoveAllMembers(); }
2556 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
2557#if RAPIDJSON_HAS_STDSTRING
2558 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
2560 template <
typename SourceAllocator>
bool RemoveMember(
const GenericValue<EncodingType, SourceAllocator>& name)
const {
return value_.RemoveMember(name); }
2561 MemberIterator RemoveMember(MemberIterator m)
const {
return value_.RemoveMember(m); }
2562 MemberIterator EraseMember(ConstMemberIterator pos)
const {
return value_.EraseMember(pos); }
2563 MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
const {
return value_.EraseMember(first, last); }
2564 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
2565#if RAPIDJSON_HAS_STDSTRING
2566 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
2568 template <
typename SourceAllocator>
bool EraseMember(
const GenericValue<EncodingType, SourceAllocator>& name)
const {
return value_.EraseMember(name); }
2570#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2571 MemberIterator begin()
const {
return value_.MemberBegin(); }
2572 MemberIterator end()
const {
return value_.MemberEnd(); }
2577 GenericObject(ValueType& value) : value_(value) {}
2581RAPIDJSON_NAMESPACE_END
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
Helper class for accessing Value of array type.
定义 document.h:2448
A document for parsing JSON text as DOM.
定义 document.h:2033
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
定义 document.h:2144
Allocator & GetAllocator()
Get the allocator of this document.
定义 document.h:2317
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
定义 document.h:2216
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
定义 document.h:2136
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
定义 document.h:2323
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream
定义 document.h:2183
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
定义 document.h:2036
Allocator AllocatorType
Allocator type from template parameter.
定义 document.h:2037
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
定义 document.h:2164
bool HasParseError() const
Whether a parse error has occured in the last parsing.
定义 document.h:2293
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor
定义 document.h:2059
Encoding::Ch Ch
Character type derived from Encoding.
定义 document.h:2035
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
定义 document.h:2193
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor
定义 document.h:2046
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
定义 document.h:2230
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
定义 document.h:2296
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
定义 document.h:2115
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string
定义 document.h:2207
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
定义 document.h:2248
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
定义 document.h:2299
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string
定义 document.h:2241
BaseType::pointer Pointer
定义 document.h:124
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
定义 document.h:121
GenericMemberIterator Iterator
Iterator type itself
定义 document.h:117
BaseType::difference_type DifferenceType
定义 document.h:128
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type
定义 document.h:119
BaseType::reference Reference
定义 document.h:126
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const
定义 document.h:152
DifferenceType operator-(ConstIterator that) const
Distance
定义 document.h:194
GenericMemberIterator()
Default constructor (singular value)
定义 document.h:134
Helper class for accessing Value of object type.
定义 document.h:2501
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
定义 reader.h:466
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
定义 document.h:547
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
定义 document.h:550
Encoding EncodingType
Encoding type from template parameter.
定义 document.h:551
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
定义 document.h:1730
GenericValue * ValueIterator
Value iterator for iterating in array.
定义 document.h:557
ConstValueIterator Begin() const
Constant element iterator
定义 document.h:1520
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
定义 document.h:781
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
定义 document.h:1426
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
定义 document.h:1413
GenericValue & SetObject()
Set this value as an empty object.
定义 document.h:1022
SizeType GetStringLength() const
Get the length of string.
定义 document.h:1695
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
定义 document.h:668
bool ObjectEmpty() const
Check whether the object is empty.
定义 document.h:1028
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
定义 document.h:1712
ConstMemberIterator MemberEnd() const
定义 document.h:1087
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
定义 document.h:762
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics
定义 document.h:848
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
定义 document.h:1550
~GenericValue()
Destructor.
定义 document.h:726
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
定义 document.h:1195
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
定义 document.h:647
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Deep-copy assignment from Value
定义 document.h:812
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
定义 document.h:1531
GenericValue & SetArray()
Set this value as an empty array.
定义 document.h:1477
GenericValue & PopBack()
Remove the last element in the array.
定义 document.h:1605
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
定义 document.h:683
GenericStringRef< Ch > StringRefType
Reference to a constant string
定义 document.h:554
float GetFloat() const
Get the value as float type.
定义 document.h:1674
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
定义 document.h:844
Allocator AllocatorType
Allocator type from template parameter.
定义 document.h:552
GenericValue & SetBool(bool b)
定义 document.h:1013
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
定义 document.h:824
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
定义 document.h:1313
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Explicit copy constructor (with allocator)
定义 document.h:2417
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer
定义 document.h:923
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
定义 document.h:599
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
定义 document.h:686
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
定义 document.h:1619
void RemoveAllMembers()
Remove all members in the object.
定义 document.h:1346
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
定义 document.h:1299
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
定义 document.h:556
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
定义 document.h:680
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
定义 document.h:707
bool GetBool() const
Set boolean value
定义 document.h:1010
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
定义 document.h:1127
SizeType Size() const
Get the number of elements in array.
定义 document.h:1480
SizeType Capacity() const
Get the capacity of array.
定义 document.h:1483
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
定义 document.h:692
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
定义 document.h:718
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
定义 document.h:558
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
定义 document.h:1057
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
定义 document.h:1573
SizeType MemberCount() const
Get the number of members in the object.
定义 document.h:1025
ValueIterator Begin()
Element iterator
定义 document.h:1514
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
定义 document.h:1162
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
定义 document.h:1631
MemberIterator MemberBegin()
Member iterator
定义 document.h:1090
double GetDouble() const
定义 document.h:1662
void Clear()
Remove all elements in the array.
定义 document.h:1492
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
定义 document.h:1361
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
定义 document.h:1103
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
定义 document.h:933
bool operator==(const T &rhs) const
Equal-to operator with primitive types
定义 document.h:913
ValueIterator End()
Past-the-end element iterator
定义 document.h:1517
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator
定义 document.h:859
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
定义 document.h:1705
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
定义 document.h:632
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
定义 document.h:641
ConstValueIterator End() const
Constant past-the-end element iterator
定义 document.h:1523
bool EraseMember(const Ch *name)
Erase a member in object by its name.
定义 document.h:1447
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
定义 document.h:1040
GenericValue & operator[](SizeType index)
Get an element from array by index.
定义 document.h:1505
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
定义 document.h:555
bool Is() const
Templated version for checking whether this value is type T.
定义 document.h:1753
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
定义 document.h:653
bool Empty() const
Check whether the array is empty.
定义 document.h:1486
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
定义 document.h:569
MemberIterator FindMember(const Ch *name)
Find member by name.
定义 document.h:1141
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
定义 document.h:559
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
定义 document.h:1777
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator
定义 document.h:920
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
定义 document.h:1722
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
定义 document.h:689
MemberIterator MemberEnd()
Past-the-end member iterator
定义 document.h:1093
Encoding::Ch Ch
Character type derived from Encoding.
定义 document.h:553
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
定义 document.h:938
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types
定义 document.h:928
ConstMemberIterator MemberBegin() const
定义 document.h:1084
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
定义 document.h:1227
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer
定义 document.h:901
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
定义 document.h:1389
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
定义 rapidjson.h:468
#define RAPIDJSON_ASSERT(x)
Assertion.
定义 rapidjson.h:402
ParseErrorCode
Error code of parsing.
定义 error.h:64
Result of parsing (wraps ParseErrorCode)
定义 error.h:106
GenericPointer< Value, CrtAllocator > Pointer
GenericPointer for Value (UTF-8, default allocator).
定义 fwd.h:128
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
定义 rapidjson.h:380
@ kParseInsituFlag
In-situ(destructive) parsing.
定义 reader.h:147
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding
定义 document.h:2019
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string
定义 document.h:353
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding
定义 document.h:2411
Type
Type of JSON value
定义 rapidjson.h:603
@ kArrayType
array
定义 rapidjson.h:608
@ kTrueType
true
定义 rapidjson.h:606
@ kNullType
null
定义 rapidjson.h:604
@ kFalseType
false
定义 rapidjson.h:605
@ kNumberType
number
定义 rapidjson.h:610
@ kObjectType
object
定义 rapidjson.h:607
@ kStringType
string
定义 rapidjson.h:609
#define RAPIDJSON_DELETE(x)
! customization point for global delete
定义 rapidjson.h:590
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
定义 rapidjson.h:289
#define RAPIDJSON_NEW(x)
! customization point for global new
定义 rapidjson.h:586
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
定义 rapidjson.h:437
A read-write string stream.
定义 stream.h:144
Name-value pair in a JSON object value.
定义 document.h:74
GenericValue< Encoding, Allocator > value
value of member.
定义 document.h:76
GenericValue< Encoding, Allocator > name
name of member (must be a string)
定义 document.h:75
Reference to a constant string (not taking a copy)
定义 document.h:256
const Ch *const s
定义 document.h:329
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer
定义 document.h:309
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string
定义 document.h:373
CharType Ch
character type of the string
定义 document.h:257
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string
定义 document.h:353
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array
定义 document.h:285
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length
定义 document.h:321
const SizeType length
定义 document.h:330
Read-only string stream.
定义 stream.h:110
Represents an in-memory input byte stream.
定义 memorystream.h:40