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>
110 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
122 typedef ValueType value_type;
123 typedef ValueType * pointer;
124 typedef ValueType & reference;
125 typedef std::ptrdiff_t difference_type;
126 typedef std::random_access_iterator_tag iterator_category;
159 Iterator& operator=(
const NonConstIterator & it) { ptr_ = it.ptr_;
return *
this; }
163 Iterator& operator++(){ ++ptr_;
return *
this; }
164 Iterator& operator--(){ --ptr_;
return *
this; }
165 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
166 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
171 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
172 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
174 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
175 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
180 template <
bool Const_>
bool operator==(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ == that.ptr_; }
181 template <
bool Const_>
bool operator!=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ != that.ptr_; }
182 template <
bool Const_>
bool operator<=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ <= that.ptr_; }
183 template <
bool Const_>
bool operator>=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ >= that.ptr_; }
184 template <
bool Const_>
bool operator< (
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ < that.ptr_; }
185 template <
bool Const_>
bool operator> (
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ > that.ptr_; }
187#ifdef __cpp_lib_three_way_comparison
188 template <
bool Const_> std::strong_ordering operator<=>(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ <=> that.ptr_; }
194 Reference operator*()
const {
return *ptr_; }
195 Pointer operator->()
const {
return ptr_; }
196 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
213template <
bool Const,
typename Encoding,
typename Allocator>
214struct GenericMemberIterator;
217template <
typename Encoding,
typename Allocator>
220 typedef GenericMember<Encoding,Allocator>* Iterator;
223template <
typename Encoding,
typename Allocator>
226 typedef const GenericMember<Encoding,Allocator>* Iterator;
261template<
typename CharType>
262struct GenericStringRef {
292 : s(str), length(N-1) {}
333 operator const Ch *()
const {
return s; }
358template<
typename CharType>
378template<
typename CharType>
383#if RAPIDJSON_HAS_STDSTRING
396template<
typename CharType>
406template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
407struct IsGenericValueImpl : FalseType {};
410template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
411 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
414template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>::Type {};
423template <
typename ValueType,
typename T>
426template<
typename ValueType>
427struct TypeHelper<ValueType, bool> {
428 static bool Is(
const ValueType& v) {
return v.IsBool(); }
429 static bool Get(
const ValueType& v) {
return v.GetBool(); }
430 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
431 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
434template<
typename ValueType>
435struct TypeHelper<ValueType, int> {
436 static bool Is(
const ValueType& v) {
return v.IsInt(); }
437 static int Get(
const ValueType& v) {
return v.GetInt(); }
438 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
439 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
442template<
typename ValueType>
443struct TypeHelper<ValueType, unsigned> {
444 static bool Is(
const ValueType& v) {
return v.IsUint(); }
445 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
446 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
447 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
450template<
typename ValueType>
451struct TypeHelper<ValueType, int64_t> {
452 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
453 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
454 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
455 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
458template<
typename ValueType>
459struct TypeHelper<ValueType, uint64_t> {
460 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
461 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
462 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
463 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
466template<
typename ValueType>
467struct TypeHelper<ValueType, double> {
468 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
469 static double Get(
const ValueType& v) {
return v.GetDouble(); }
470 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
471 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
474template<
typename ValueType>
475struct TypeHelper<ValueType, float> {
476 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
477 static float Get(
const ValueType& v) {
return v.GetFloat(); }
478 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
479 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
482template<
typename ValueType>
483struct TypeHelper<ValueType, const typename ValueType::Ch*> {
484 typedef const typename ValueType::Ch* StringType;
485 static bool Is(
const ValueType& v) {
return v.IsString(); }
486 static StringType Get(
const ValueType& v) {
return v.GetString(); }
487 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
488 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
491#if RAPIDJSON_HAS_STDSTRING
492template<
typename ValueType>
493struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
494 typedef std::basic_string<typename ValueType::Ch> StringType;
495 static bool Is(
const ValueType& v) {
return v.IsString(); }
496 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
497 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
501template<
typename ValueType>
502struct TypeHelper<ValueType, typename ValueType::Array> {
503 typedef typename ValueType::Array ArrayType;
504 static bool Is(
const ValueType& v) {
return v.IsArray(); }
505 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
506 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
507 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
510template<
typename ValueType>
511struct TypeHelper<ValueType, typename ValueType::ConstArray> {
512 typedef typename ValueType::ConstArray ArrayType;
513 static bool Is(
const ValueType& v) {
return v.IsArray(); }
514 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
517template<
typename ValueType>
518struct TypeHelper<ValueType, typename ValueType::Object> {
519 typedef typename ValueType::Object ObjectType;
520 static bool Is(
const ValueType& v) {
return v.IsObject(); }
521 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
522 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
523 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) { v = data; }
526template<
typename ValueType>
527struct TypeHelper<ValueType, typename ValueType::ConstObject> {
528 typedef typename ValueType::ConstObject ObjectType;
529 static bool Is(
const ValueType& v) {
return v.IsObject(); }
530 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
536template <
bool,
typename>
class GenericArray;
537template <
bool,
typename>
class GenericObject;
552template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
559 typedef typename Encoding::Ch
Ch;
575 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
577#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
580 rhs.data_.f.flags = kNullFlag;
586 GenericValue(
const GenericValue& rhs);
588#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
590 template <
typename StackAllocator>
591 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
594 template <
typename StackAllocator>
595 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
606 static const uint16_t defaultFlags[7] = {
607 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
611 data_.f.flags = defaultFlags[type];
615 data_.ss.SetLength(0);
625 template<
typename SourceAllocator >
634#ifndef RAPIDJSON_DOXYGEN_RUNNING
635 template <
typename T>
636 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT
643 data_.f.flags = b ? kTrueFlag : kFalseFlag;
649 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
655 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
661 data_.f.flags = kNumberInt64Flag;
663 data_.f.flags |= kNumberUint64Flag;
665 data_.f.flags |= kUintFlag;
667 data_.f.flags |= kIntFlag;
670 data_.f.flags |= kIntFlag;
676 data_.f.flags = kNumberUint64Flag;
678 data_.f.flags |= kInt64Flag;
680 data_.f.flags |= kUintFlag;
682 data_.f.flags |= kIntFlag;
686 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
700#if RAPIDJSON_HAS_STDSTRING
714 a.value_.data_ = Data();
715 a.value_.data_.f.flags = kArrayFlag;
725 o.value_.data_ = Data();
726 o.value_.data_.f.flags = kObjectFlag;
733 if (Allocator::kNeedFree) {
734 switch(data_.f.flags) {
747 Allocator::Free(GetMembersPointer());
750 case kCopyStringFlag:
751 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
775#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
778 return *
this = rhs.Move();
804 template <
typename T>
805 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
817 template <
typename SourceAllocator>
819 RAPIDJSON_ASSERT(
static_cast<void*
>(
this) !=
static_cast<void const*
>(&rhs));
832 temp.RawAssign(*
this);
834 other.RawAssign(temp);
864 template <
typename SourceAllocator>
867 if (GetType() != rhs.GetType())
872 if (data_.o.size != rhs.data_.o.size)
874 for (
ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
875 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name);
876 if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
882 if (data_.a.size != rhs.data_.a.size)
884 for (
SizeType i = 0; i < data_.a.size; i++)
885 if ((*
this)[i] != rhs[i])
890 return StringEqual(rhs);
893 if (IsDouble() || rhs.IsDouble()) {
894 double a = GetDouble();
895 double b = rhs.GetDouble();
896 return a >= b && a <= b;
899 return data_.n.u64 == rhs.data_.n.u64;
909#if RAPIDJSON_HAS_STDSTRING
913 bool operator==(
const std::basic_string<Ch>& rhs)
const {
return *
this ==
GenericValue(
StringRef(rhs)); }
919 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
921#ifndef __cpp_impl_three_way_comparison
925 template <
typename SourceAllocator>
934 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
939 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
944 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
951 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
952 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
953 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
954 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
955 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
956 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
957 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
958 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
959 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
960 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
961 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
962 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
963 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
964 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
967 bool IsLosslessDouble()
const {
968 if (!IsNumber())
return false;
970 uint64_t u = GetUint64();
971 volatile double d =
static_cast<double>(u);
973 && (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
974 && (u ==
static_cast<uint64_t
>(d));
977 int64_t i = GetInt64();
978 volatile double d =
static_cast<double>(i);
979 return (d >=
static_cast<double>(std::numeric_limits<int64_t>::min()))
980 && (d < static_cast<double>(std::numeric_limits<int64_t>::max()))
981 && (i ==
static_cast<int64_t
>(d));
987 bool IsFloat()
const {
988 if ((data_.f.flags & kDoubleFlag) == 0)
990 double d = GetDouble();
991 return d >= -3.4028234e38 && d <= 3.4028234e38;
994 bool IsLosslessFloat()
const {
995 if (!IsNumber())
return false;
996 double a = GetDouble();
997 if (a <
static_cast<double>(-std::numeric_limits<float>::max())
998 || a >
static_cast<double>(std::numeric_limits<float>::max()))
1000 double b =
static_cast<double>(
static_cast<float>(a));
1001 return a >= b && a <= b;
1009 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1045 template <
typename T>
1046 RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<
typename internal::RemoveConst<T>::Type,
Ch> >),(
GenericValue&))
operator[](T* name) {
1050 template <
typename T>
1051 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]; }
1062 template <
typename SourceAllocator>
1065 if (member != MemberEnd())
1066 return member->value;
1079 template <
typename SourceAllocator>
1082#if RAPIDJSON_HAS_STDSTRING
1084 GenericValue& operator[](
const std::basic_string<Ch>& name) {
return (*
this)[GenericValue(StringRef(name))]; }
1085 const GenericValue& operator[](
const std::basic_string<Ch>& name)
const {
return (*
this)[GenericValue(
StringRef(name))]; }
1109 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
1111#if RAPIDJSON_HAS_STDSTRING
1120 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1132 template <
typename SourceAllocator>
1149 return FindMember(n);
1152 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1167 template <
typename SourceAllocator>
1172 for ( ; member != MemberEnd(); ++member)
1173 if (name.StringEqual(member->name))
1179#if RAPIDJSON_HAS_STDSTRING
1187 MemberIterator FindMember(
const std::basic_string<Ch>& name) {
return FindMember(GenericValue(StringRef(name))); }
1188 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(GenericValue(
StringRef(name))); }
1205 ObjectData& o = data_.o;
1206 if (o.size >= o.capacity) {
1207 if (o.capacity == 0) {
1208 o.capacity = kDefaultObjectCapacity;
1209 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Malloc(o.capacity *
sizeof(
Member))));
1213 o.capacity += (oldCapacity + 1) / 2;
1214 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Realloc(GetMembersPointer(), oldCapacity *
sizeof(
Member), o.capacity *
sizeof(
Member))));
1217 Member* members = GetMembersPointer();
1218 members[o.size].
name.RawAssign(name);
1219 members[o.size].
value.RawAssign(value);
1235 return AddMember(name, v, allocator);
1238#if RAPIDJSON_HAS_STDSTRING
1250 return AddMember(name, v, allocator);
1271 template <
typename T>
1272 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1275 return AddMember(name, v, allocator);
1278#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1280 return AddMember(name, value, allocator);
1282 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1283 return AddMember(name, value, allocator);
1285 GenericValue& AddMember(GenericValue& name, GenericValue&& value,
Allocator& allocator) {
1286 return AddMember(name, value, allocator);
1288 GenericValue& AddMember(StringRefType name, GenericValue&& value,
Allocator& allocator) {
1289 GenericValue n(name);
1290 return AddMember(n, value, allocator);
1307 return AddMember(n, value, allocator);
1321 return AddMember(name, v, allocator);
1341 template <
typename T>
1342 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1345 return AddMember(n, value, allocator);
1369 return RemoveMember(n);
1372#if RAPIDJSON_HAS_STDSTRING
1373 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1376 template <
typename SourceAllocator>
1377 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1378 MemberIterator m = FindMember(name);
1379 if (m != MemberEnd()) {
1402 if (data_.o.size > 1 && m != last)
1420 return EraseMember(pos, pos +1);
1443 std::memmove(
static_cast<void*
>(&*pos), &*last,
static_cast<size_t>(MemberEnd() - last) *
sizeof(
Member));
1444 data_.o.size -=
static_cast<SizeType>(last - first);
1455 return EraseMember(n);
1458#if RAPIDJSON_HAS_STDSTRING
1459 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1462 template <
typename SourceAllocator>
1463 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1464 MemberIterator m = FindMember(name);
1465 if (m != MemberEnd()) {
1474 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1514 return GetElementsPointer()[index];
1539 if (newCapacity > data_.a.capacity) {
1541 data_.a.capacity = newCapacity;
1558 if (data_.a.size >= data_.a.capacity)
1559 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1560 GetElementsPointer()[data_.a.size++].RawAssign(value);
1564#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1566 return PushBack(value, allocator);
1580 return (*this).template PushBack<StringRefType>(value, allocator);
1600 template <
typename T>
1601 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1604 return PushBack(v, allocator);
1614 GetElementsPointer()[--data_.a.size].~GenericValue();
1626 return Erase(pos, pos + 1);
1647 std::memmove(
static_cast<void*
>(pos), last,
static_cast<size_t>(End() - last) *
sizeof(
GenericValue));
1648 data_.a.size -=
static_cast<SizeType>(last - first);
1653 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1660 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1661 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1662 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1663 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1670 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1671 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1672 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1673 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1674 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1681 return static_cast<float>(GetDouble());
1685 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1686 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1687 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1688 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1689 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(f);
return *
this; }
1696 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1738#if RAPIDJSON_HAS_STDSTRING
1746 GenericValue& SetString(
const std::basic_string<Ch>& s,
Allocator& allocator) {
return SetString(s.data(),
SizeType(s.size()), allocator); }
1758 template <
typename T>
1759 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1761 template <
typename T>
1762 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1764 template <
typename T>
1765 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1767 template<
typename T>
1768 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1770 template<
typename T>
1771 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1782 template <
typename Handler>
1787 case kTrueType:
return handler.Bool(
true);
1794 if (
RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1799 return handler.EndObject(data_.o.size);
1807 return handler.EndArray(data_.a.size);
1810 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1814 if (IsDouble())
return handler.Double(data_.n.d);
1815 else if (IsInt())
return handler.Int(data_.n.i.i);
1816 else if (IsUint())
return handler.Uint(data_.n.u.u);
1817 else if (IsInt64())
return handler.Int64(data_.n.i64);
1818 else return handler.Uint64(data_.n.u64);
1823 template <
typename,
typename>
friend class GenericValue;
1828 kNumberFlag = 0x0010,
1831 kInt64Flag = 0x0080,
1832 kUint64Flag = 0x0100,
1833 kDoubleFlag = 0x0200,
1834 kStringFlag = 0x0400,
1836 kInlineStrFlag = 0x1000,
1842 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1843 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1844 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1845 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1846 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1847 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1849 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1850 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1857 static const SizeType kDefaultArrayCapacity = 16;
1858 static const SizeType kDefaultObjectCapacity = 16;
1861#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1862 char payload[
sizeof(SizeType) * 2 + 6];
1863#elif RAPIDJSON_64BIT
1864 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 6];
1866 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 2];
1885 struct ShortString {
1886 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1889 inline static bool Usable(SizeType len) {
return (MaxSize >= len); }
1890 inline void SetLength(SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
1891 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
1896#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1929 GenericValue* elements;
1941 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
1942 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
1943 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
1944 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
1945 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
1946 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
1949 void SetArrayRaw(GenericValue* values, SizeType count,
Allocator& allocator) {
1950 data_.f.flags = kArrayFlag;
1952 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
1953 SetElementsPointer(e);
1954 std::memcpy(
static_cast<void*
>(e), values, count *
sizeof(GenericValue));
1957 SetElementsPointer(0);
1958 data_.a.size = data_.a.capacity = count;
1962 void SetObjectRaw(Member* members, SizeType count,
Allocator& allocator) {
1963 data_.f.flags = kObjectFlag;
1965 Member* m =
static_cast<Member*
>(allocator.Malloc(count *
sizeof(Member)));
1966 SetMembersPointer(m);
1967 std::memcpy(
static_cast<void*
>(m), members, count *
sizeof(Member));
1970 SetMembersPointer(0);
1971 data_.o.size = data_.o.capacity = count;
1975 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
1976 data_.f.flags = kConstStringFlag;
1977 SetStringPointer(s);
1978 data_.s.length = s.length;
1982 void SetStringRaw(StringRefType s,
Allocator& allocator) {
1984 if (ShortString::Usable(s.length)) {
1985 data_.f.flags = kShortStringFlag;
1986 data_.ss.SetLength(s.length);
1989 data_.f.flags = kCopyStringFlag;
1990 data_.s.length = s.length;
1991 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
1992 SetStringPointer(str);
1994 std::memcpy(str, s, s.length *
sizeof(Ch));
1995 str[s.length] =
'\0';
1999 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2002 rhs.data_.f.flags = kNullFlag;
2005 template <
typename SourceAllocator>
2006 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
2010 const SizeType len1 = GetStringLength();
2011 const SizeType len2 = rhs.GetStringLength();
2012 if(len1 != len2) {
return false; }
2014 const Ch*
const str1 = GetString();
2015 const Ch*
const str2 = rhs.GetString();
2016 if(str1 == str2) {
return true; }
2018 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2038template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
2041 typedef typename Encoding::Ch
Ch;
2066 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2072#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2075 : ValueType(std::forward<ValueType>(rhs)),
2076 allocator_(rhs.allocator_),
2077 ownAllocator_(rhs.ownAllocator_),
2078 stack_(std::move(rhs.stack_)),
2079 parseResult_(rhs.parseResult_)
2082 rhs.ownAllocator_ = 0;
2087 ~GenericDocument() {
2091#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2093 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2097 ValueType::operator=(std::forward<ValueType>(rhs));
2102 allocator_ = rhs.allocator_;
2103 ownAllocator_ = rhs.ownAllocator_;
2104 stack_ = std::move(rhs.stack_);
2105 parseResult_ = rhs.parseResult_;
2108 rhs.ownAllocator_ = 0;
2109 rhs.parseResult_ = ParseResult();
2122 ValueType::Swap(rhs);
2123 stack_.Swap(rhs.stack_);
2124 internal::Swap(allocator_, rhs.allocator_);
2125 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2126 internal::Swap(parseResult_, rhs.parseResult_);
2149 template <
typename Generator>
2151 ClearStackOnExit scope(*
this);
2154 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2169 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2172 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2173 ClearStackOnExit scope(*
this);
2174 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
2177 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2188 template <
unsigned parseFlags,
typename InputStream>
2190 return ParseStream<parseFlags, Encoding, InputStream>(is);
2198 template <
typename InputStream>
2200 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2212 template <
unsigned parseFlags>
2215 return ParseStream<parseFlags | kParseInsituFlag>(s);
2223 return ParseInsitu<kParseDefaultFlags>(str);
2235 template <
unsigned parseFlags,
typename SourceEncoding>
2239 return ParseStream<parseFlags, SourceEncoding>(s);
2246 template <
unsigned parseFlags>
2248 return Parse<parseFlags, Encoding>(str);
2255 return Parse<kParseDefaultFlags>(str);
2258 template <
unsigned parseFlags,
typename SourceEncoding>
2259 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2261 MemoryStream ms(
static_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2263 ParseStream<parseFlags, SourceEncoding>(is);
2267 template <
unsigned parseFlags>
2268 GenericDocument& Parse(
const Ch* str,
size_t length) {
2269 return Parse<parseFlags, Encoding>(str, length);
2272 GenericDocument& Parse(
const Ch* str,
size_t length) {
2273 return Parse<kParseDefaultFlags>(str, length);
2276#if RAPIDJSON_HAS_STDSTRING
2277 template <
unsigned parseFlags,
typename SourceEncoding>
2278 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2280 return Parse<parseFlags, SourceEncoding>(str.c_str());
2283 template <
unsigned parseFlags>
2284 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2285 return Parse<parseFlags, Encoding>(str.c_str());
2288 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2289 return Parse<kParseDefaultFlags>(str);
2333 struct ClearStackOnExit {
2335 ~ClearStackOnExit() { d_.ClearStack(); }
2337 ClearStackOnExit(
const ClearStackOnExit&);
2338 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2339 GenericDocument& d_;
2344 template <
typename,
typename>
friend class GenericValue;
2348 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2349 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2350 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2351 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2352 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2353 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2354 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2356 bool RawNumber(
const Ch* str, SizeType length,
bool copy) {
2358 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2360 new (stack_.template Push<ValueType>()) ValueType(str, length);
2364 bool String(
const Ch* str, SizeType length,
bool copy) {
2366 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2368 new (stack_.template Push<ValueType>()) ValueType(str, length);
2372 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(kObjectType);
return true; }
2374 bool Key(
const Ch* str, SizeType length,
bool copy) {
return String(str, length, copy); }
2376 bool EndObject(SizeType memberCount) {
2377 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2378 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2382 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(kArrayType);
return true; }
2384 bool EndArray(SizeType elementCount) {
2385 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2386 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2392 GenericDocument(
const GenericDocument&);
2394 GenericDocument& operator=(
const GenericDocument&);
2397 if (Allocator::kNeedFree)
2398 while (stack_.GetSize() > 0)
2399 (stack_.template Pop<ValueType>(1))->~ValueType();
2402 stack_.ShrinkToFit();
2409 static const size_t kDefaultStackCapacity = 1024;
2412 internal::Stack<StackAllocator> stack_;
2413 ParseResult parseResult_;
2420template <
typename Encoding,
typename Allocator>
2421template <
typename SourceAllocator>
2425 switch (rhs.GetType()) {
2430 RawAssign(*d.stack_.template Pop<GenericValue>(1));
2434 if (rhs.data_.f.flags == kConstStringFlag) {
2435 data_.f.flags = rhs.data_.f.flags;
2436 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2438 SetStringRaw(
StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
2442 data_.f.flags = rhs.data_.f.flags;
2443 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2453template <
bool Const,
typename ValueT>
2458 typedef ValueT PlainType;
2459 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2460 typedef ValueType* ValueIterator;
2461 typedef const ValueT* ConstValueIterator;
2462 typedef typename ValueType::AllocatorType AllocatorType;
2463 typedef typename ValueType::StringRefType StringRefType;
2465 template <
typename,
typename>
2472 SizeType Size()
const {
return value_.Size(); }
2473 SizeType Capacity()
const {
return value_.Capacity(); }
2474 bool Empty()
const {
return value_.Empty(); }
2475 void Clear()
const { value_.Clear(); }
2476 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2477 ValueIterator Begin()
const {
return value_.Begin(); }
2478 ValueIterator End()
const {
return value_.End(); }
2479 GenericArray Reserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.Reserve(newCapacity, allocator);
return *
this; }
2480 GenericArray PushBack(ValueType& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2481#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2482 GenericArray PushBack(ValueType&& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2484 GenericArray PushBack(StringRefType value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2485 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; }
2486 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2487 ValueIterator Erase(ConstValueIterator pos)
const {
return value_.Erase(pos); }
2488 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
const {
return value_.Erase(first, last); }
2490#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2491 ValueIterator begin()
const {
return value_.Begin(); }
2492 ValueIterator end()
const {
return value_.End(); }
2506template <
bool Const,
typename ValueT>
2511 typedef ValueT PlainType;
2512 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2515 typedef typename ValueType::AllocatorType AllocatorType;
2516 typedef typename ValueType::StringRefType StringRefType;
2517 typedef typename ValueType::EncodingType EncodingType;
2518 typedef typename ValueType::Ch Ch;
2520 template <
typename,
typename>
2527 SizeType MemberCount()
const {
return value_.MemberCount(); }
2528 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2529 template <
typename T> ValueType& operator[](T* name)
const {
return value_[name]; }
2531#if RAPIDJSON_HAS_STDSTRING
2532 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2534 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2536 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2537#if RAPIDJSON_HAS_STDSTRING
2538 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2541 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2543#if RAPIDJSON_HAS_STDSTRING
2544 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2546 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2547 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2548#if RAPIDJSON_HAS_STDSTRING
2549 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2551 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; }
2552#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2553 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2554 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2555 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2556 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2558 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2559 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2560 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; }
2561 void RemoveAllMembers() {
return value_.RemoveAllMembers(); }
2562 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
2563#if RAPIDJSON_HAS_STDSTRING
2564 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
2570 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
2571#if RAPIDJSON_HAS_STDSTRING
2572 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
2576#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2587RAPIDJSON_NAMESPACE_END
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
Helper class for accessing Value of array type.
Definition document.h:2454
A document for parsing JSON text as DOM.
Definition fwd.h:119
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition document.h:2150
Allocator & GetAllocator()
Get the allocator of this document.
Definition document.h:2323
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition document.h:2222
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:2142
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition document.h:2329
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition document.h:2189
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition document.h:2170
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition document.h:2299
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition document.h:2065
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition document.h:2199
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition document.h:2052
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2236
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:2041
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition document.h:2302
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition document.h:2121
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition document.h:2213
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:2043
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition document.h:2254
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition document.h:2042
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition document.h:2305
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition document.h:2247
(Constant) member iterator for a JSON object value
Definition fwd.h:108
difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition document.h:134
reference Reference
Reference to (const) GenericMember.
Definition document.h:132
GenericMemberIterator Iterator
Iterator type itself.
Definition document.h:114
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition document.h:118
pointer Pointer
Pointer to (const) GenericMember.
Definition document.h:130
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition document.h:158
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition document.h:116
DifferenceType operator-(ConstIterator that) const
Distance.
Definition document.h:200
GenericMemberIterator()
Default constructor (singular value)
Definition document.h:140
Helper class for accessing Value of object type.
Definition document.h:2507
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition pointer.h:81
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition reader.h:466
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition fwd.h:114
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1736
ConstValueIterator Begin() const
Constant element iterator.
Definition document.h:1526
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition document.h:787
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition document.h:563
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition document.h:1432
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition document.h:1419
GenericValue & SetObject()
Set this value as an empty object.
Definition document.h:1028
SizeType GetStringLength() const
Get the length of string.
Definition document.h:1701
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition document.h:560
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition document.h:674
bool ObjectEmpty() const
Check whether the object is empty.
Definition document.h:1034
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition document.h:1718
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition document.h:1093
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition document.h:768
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics.
Definition document.h:854
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition document.h:1556
~GenericValue()
Destructor.
Definition document.h:732
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition document.h:564
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition document.h:1201
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition document.h:653
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Deep-copy assignment from Value.
Definition document.h:818
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition document.h:1537
GenericValue & SetArray()
Set this value as an empty array.
Definition document.h:1483
GenericValue & PopBack()
Remove the last element in the array.
Definition document.h:1611
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:689
float GetFloat() const
Get the value as float type.
Definition document.h:1680
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:850
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition document.h:562
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:558
GenericValue & SetBool(bool b)
Definition document.h:1019
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition document.h:830
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition document.h:1319
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Explicit copy constructor (with allocator)
Definition document.h:2423
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition document.h:929
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition document.h:605
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:692
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition document.h:1625
void RemoveAllMembers()
Remove all members in the object.
Definition document.h:1352
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition document.h:1305
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition document.h:686
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition document.h:713
bool GetBool() const
Set boolean value.
Definition document.h:1016
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition document.h:1133
SizeType Size() const
Get the number of elements in array.
Definition document.h:1486
SizeType Capacity() const
Get the capacity of array.
Definition document.h:1489
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:698
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition document.h:724
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition document.h:1063
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition document.h:1579
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition document.h:561
SizeType MemberCount() const
Get the number of members in the object.
Definition document.h:1031
ValueIterator Begin()
Element iterator.
Definition document.h:1520
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition document.h:1168
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition document.h:1637
MemberIterator MemberBegin()
Member iterator.
Definition document.h:1096
Encoding EncodingType
Encoding type from template parameter.
Definition document.h:557
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition document.h:556
double GetDouble() const
Get the value as double type.
Definition document.h:1668
void Clear()
Remove all elements in the array.
Definition document.h:1498
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition document.h:1367
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition document.h:1109
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition document.h:939
bool operator==(const T &rhs) const
Equal-to operator with primitive types.
Definition document.h:919
ValueIterator End()
Past-the-end element iterator
Definition document.h:1523
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition document.h:865
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition document.h:1711
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition document.h:638
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition document.h:647
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition document.h:1529
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:559
bool EraseMember(const Ch *name)
Erase a member in object by its name.
Definition document.h:1453
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition document.h:1046
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition document.h:1511
bool Is() const
Templated version for checking whether this value is type T.
Definition document.h:1759
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition document.h:659
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition document.h:565
bool Empty() const
Check whether the array is empty.
Definition document.h:1492
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition document.h:575
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition document.h:1147
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition document.h:1783
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition document.h:926
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1728
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:695
MemberIterator MemberEnd()
Past-the-end member iterator
Definition document.h:1099
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition document.h:944
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types.
Definition document.h:934
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition document.h:1090
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition document.h:1233
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition document.h:907
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition document.h:1395
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.
Definition rapidjson.h:468
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:402
ParseErrorCode
Error code of parsing.
Definition error.h:64
Result of parsing (wraps ParseErrorCode)
Definition error.h:106
GenericPointer< Value, CrtAllocator > Pointer
GenericPointer for Value (UTF-8, default allocator).
Definition fwd.h:128
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition rapidjson.h:380
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition reader.h:147
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:359
Type
Type of JSON value.
Definition rapidjson.h:603
@ kArrayType
array
Definition rapidjson.h:608
@ kTrueType
true
Definition rapidjson.h:606
@ kNullType
null
Definition rapidjson.h:604
@ kFalseType
false
Definition rapidjson.h:605
@ kNumberType
number
Definition rapidjson.h:610
@ kObjectType
object
Definition rapidjson.h:607
@ kStringType
string
Definition rapidjson.h:609
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition rapidjson.h:590
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:289
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition rapidjson.h:586
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition rapidjson.h:437
A read-write string stream.
Definition stream.h:144
Name-value pair in a JSON object value.
Definition fwd.h:105
GenericValue< Encoding, Allocator > value
value of member.
Definition document.h:76
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition document.h:75
Reference to a constant string (not taking a copy)
Definition fwd.h:111
const Ch *const s
plain CharType pointer
Definition document.h:335
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition document.h:315
CharType Ch
character type of the string
Definition document.h:263
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string.
Definition document.h:379
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:359
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition document.h:291
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition document.h:327
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition document.h:336
Read-only string stream.
Definition stream.h:110
Definition document.h:1897
Definition document.h:1901
Represents an in-memory input byte stream.
Definition memorystream.h:40