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"
30RAPIDJSON_DIAG_OFF(4127)
31RAPIDJSON_DIAG_OFF(4244)
35RAPIDJSON_DIAG_OFF(padded)
36RAPIDJSON_DIAG_OFF(
switch-
enum)
37RAPIDJSON_DIAG_OFF(c++98-compat)
41RAPIDJSON_DIAG_OFF(effc++)
43RAPIDJSON_DIAG_OFF(terminate)
47#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
51#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
55RAPIDJSON_NAMESPACE_BEGIN
58template <
typename Encoding,
typename Allocator>
61template <
typename Encoding,
typename Allocator,
typename StackAllocator>
70template <
typename Encoding,
typename Allocator>
79#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
100template <
bool Const,
typename Encoding,
typename Allocator>
102 :
public std::iterator<std::random_access_iterator_tag
103 , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
110 typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
150 Iterator& operator=(
const NonConstIterator & it) { ptr_ = it.ptr_;
return *
this; }
154 Iterator& operator++(){ ++ptr_;
return *
this; }
155 Iterator& operator--(){ --ptr_;
return *
this; }
156 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
157 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
162 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
163 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
165 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
166 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
171 bool operator==(ConstIterator that)
const {
return ptr_ == that.ptr_; }
172 bool operator!=(ConstIterator that)
const {
return ptr_ != that.ptr_; }
173 bool operator<=(ConstIterator that)
const {
return ptr_ <= that.ptr_; }
174 bool operator>=(ConstIterator that)
const {
return ptr_ >= that.ptr_; }
175 bool operator< (ConstIterator that)
const {
return ptr_ < that.ptr_; }
176 bool operator> (ConstIterator that)
const {
return ptr_ > that.ptr_; }
181 Reference operator*()
const {
return *ptr_; }
182 Pointer operator->()
const {
return ptr_; }
183 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
200template <
bool Const,
typename Encoding,
typename Allocator>
201struct GenericMemberIterator;
204template <
typename Encoding,
typename Allocator>
207 typedef GenericMember<Encoding,Allocator>* Iterator;
210template <
typename Encoding,
typename Allocator>
213 typedef const GenericMember<Encoding,Allocator>* Iterator;
248template<
typename CharType>
279 : s(str), length(N-1) {}
320 operator const Ch *()
const {
return s; }
343template<
typename CharType>
363template<
typename CharType>
368#if RAPIDJSON_HAS_STDSTRING
381template<
typename CharType>
391template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
392struct IsGenericValueImpl : FalseType {};
395template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>
::Type, typename Void<typename T::AllocatorType>
::Type>
396 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>
::Type {};
399template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>
::Type {};
408template <
typename ValueType,
typename T>
411template<
typename ValueType>
412struct TypeHelper<ValueType, bool> {
413 static bool Is(
const ValueType& v) {
return v.IsBool(); }
414 static bool Get(
const ValueType& v) {
return v.GetBool(); }
415 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
416 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
419template<
typename ValueType>
420struct TypeHelper<ValueType, int> {
421 static bool Is(
const ValueType& v) {
return v.IsInt(); }
422 static int Get(
const ValueType& v) {
return v.GetInt(); }
423 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
424 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
427template<
typename ValueType>
428struct TypeHelper<ValueType, unsigned> {
429 static bool Is(
const ValueType& v) {
return v.IsUint(); }
430 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
431 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
432 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
435template<
typename ValueType>
436struct TypeHelper<ValueType, int64_t> {
437 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
438 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
439 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
440 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
443template<
typename ValueType>
444struct TypeHelper<ValueType, uint64_t> {
445 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
446 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
447 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
448 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
451template<
typename ValueType>
452struct TypeHelper<ValueType, double> {
453 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
454 static double Get(
const ValueType& v) {
return v.GetDouble(); }
455 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
456 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
459template<
typename ValueType>
460struct TypeHelper<ValueType, float> {
461 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
462 static float Get(
const ValueType& v) {
return v.GetFloat(); }
463 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
464 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
467template<
typename ValueType>
468struct TypeHelper<ValueType, const typename ValueType::Ch*> {
469 typedef const typename ValueType::Ch* StringType;
470 static bool Is(
const ValueType& v) {
return v.IsString(); }
471 static StringType Get(
const ValueType& v) {
return v.GetString(); }
472 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
473 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
476#if RAPIDJSON_HAS_STDSTRING
477template<
typename ValueType>
478struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
479 typedef std::basic_string<typename ValueType::Ch> StringType;
480 static bool Is(
const ValueType& v) {
return v.IsString(); }
481 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
482 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
486template<
typename ValueType>
487struct TypeHelper<ValueType, typename ValueType::Array> {
488 typedef typename ValueType::Array ArrayType;
489 static bool Is(
const ValueType& v) {
return v.IsArray(); }
490 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
491 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
492 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
495template<
typename ValueType>
496struct TypeHelper<ValueType, typename ValueType::ConstArray> {
497 typedef typename ValueType::ConstArray ArrayType;
498 static bool Is(
const ValueType& v) {
return v.IsArray(); }
499 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
502template<
typename ValueType>
503struct TypeHelper<ValueType, typename ValueType::Object> {
504 typedef typename ValueType::Object ObjectType;
505 static bool Is(
const ValueType& v) {
return v.IsObject(); }
506 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
507 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
508 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) { v = data; }
511template<
typename ValueType>
512struct TypeHelper<ValueType, typename ValueType::ConstObject> {
513 typedef typename ValueType::ConstObject ObjectType;
514 static bool Is(
const ValueType& v) {
return v.IsObject(); }
515 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
521template <
bool,
typename>
class GenericArray;
522template <
bool,
typename>
class GenericObject;
537template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
544 typedef typename Encoding::Ch
Ch;
560 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
562#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
565 rhs.data_.f.flags = kNullFlag;
571 GenericValue(
const GenericValue& rhs);
573#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
575 template <
typename StackAllocator>
576 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
579 template <
typename StackAllocator>
580 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
591 static const uint16_t defaultFlags[7] = {
592 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
596 data_.f.flags = defaultFlags[type];
600 data_.ss.SetLength(0);
610 template<
typename SourceAllocator >
619#ifndef RAPIDJSON_DOXYGEN_RUNNING
620 template <
typename T>
621 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT
628 data_.f.flags = b ? kTrueFlag : kFalseFlag;
634 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
640 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
646 data_.f.flags = kNumberInt64Flag;
648 data_.f.flags |= kNumberUint64Flag;
650 data_.f.flags |= kUintFlag;
652 data_.f.flags |= kIntFlag;
655 data_.f.flags |= kIntFlag;
661 data_.f.flags = kNumberUint64Flag;
663 data_.f.flags |= kInt64Flag;
665 data_.f.flags |= kUintFlag;
667 data_.f.flags |= kIntFlag;
671 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
685#if RAPIDJSON_HAS_STDSTRING
699 a.value_.data_ = Data();
700 a.value_.data_.f.flags = kArrayFlag;
710 o.value_.data_ = Data();
711 o.value_.data_.f.flags = kObjectFlag;
718 if (Allocator::kNeedFree) {
719 switch(data_.f.flags) {
732 Allocator::Free(GetMembersPointer());
735 case kCopyStringFlag:
736 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
760#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
763 return *
this = rhs.
Move();
789 template <
typename T>
790 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
802 template <
typename SourceAllocator>
804 RAPIDJSON_ASSERT(
static_cast<void*
>(
this) !=
static_cast<void const*
>(&rhs));
817 temp.RawAssign(*
this);
819 other.RawAssign(temp);
849 template <
typename SourceAllocator>
852 if (GetType() != rhs.GetType())
857 if (data_.o.size != rhs.data_.o.size)
859 for (
ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
860 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.
FindMember(lhsMemberItr->name);
861 if (rhsMemberItr == rhs.
MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
867 if (data_.a.size != rhs.data_.a.size)
869 for (
SizeType i = 0; i < data_.a.size; i++)
870 if ((*
this)[i] != rhs[i])
875 return StringEqual(rhs);
878 if (IsDouble() || rhs.IsDouble()) {
879 double a = GetDouble();
881 return a >= b && a <= b;
884 return data_.n.u64 == rhs.data_.n.u64;
894#if RAPIDJSON_HAS_STDSTRING
904 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
909 template <
typename SourceAllocator>
918 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
923 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
928 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
934 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
935 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
936 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
937 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
938 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
939 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
940 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
941 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
942 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
943 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
944 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
945 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
946 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
947 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
950 bool IsLosslessDouble()
const {
951 if (!IsNumber())
return false;
953 uint64_t u = GetUint64();
954 volatile double d =
static_cast<double>(u);
956 && (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
957 && (u ==
static_cast<uint64_t
>(d));
960 int64_t i = GetInt64();
961 volatile double d =
static_cast<double>(i);
962 return (d >=
static_cast<double>(std::numeric_limits<int64_t>::min()))
963 && (d <
static_cast<double>(std::numeric_limits<int64_t>::max()))
964 && (i ==
static_cast<int64_t
>(d));
970 bool IsFloat()
const {
971 if ((data_.f.flags & kDoubleFlag) == 0)
973 double d = GetDouble();
974 return d >= -3.4028234e38 && d <= 3.4028234e38;
977 bool IsLosslessFloat()
const {
978 if (!IsNumber())
return false;
979 double a = GetDouble();
980 if (a <
static_cast<double>(-std::numeric_limits<float>::max())
981 || a >
static_cast<double>(std::numeric_limits<float>::max()))
983 double b =
static_cast<double>(
static_cast<float>(a));
984 return a >= b && a <= b;
992 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1028 template <
typename T>
1033 template <
typename T>
1045 template <
typename SourceAllocator>
1048 if (member != MemberEnd())
1049 return member->value;
1062 template <
typename SourceAllocator>
1065#if RAPIDJSON_HAS_STDSTRING
1092 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
1094#if RAPIDJSON_HAS_STDSTRING
1103 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1115 template <
typename SourceAllocator>
1132 return FindMember(n);
1135 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1150 template <
typename SourceAllocator>
1155 for ( ; member != MemberEnd(); ++member)
1156 if (name.StringEqual(member->name))
1162#if RAPIDJSON_HAS_STDSTRING
1171 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(
GenericValue(
StringRef(name))); }
1188 ObjectData& o = data_.o;
1189 if (o.size >= o.capacity) {
1190 if (o.capacity == 0) {
1191 o.capacity = kDefaultObjectCapacity;
1192 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Malloc(o.capacity *
sizeof(
Member))));
1196 o.capacity += (oldCapacity + 1) / 2;
1197 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Realloc(GetMembersPointer(), oldCapacity *
sizeof(
Member), o.capacity *
sizeof(
Member))));
1200 Member* members = GetMembersPointer();
1201 members[o.size].
name.RawAssign(name);
1202 members[o.size].
value.RawAssign(value);
1218 return AddMember(name, v, allocator);
1221#if RAPIDJSON_HAS_STDSTRING
1233 return AddMember(name, v, allocator);
1254 template <
typename T>
1255 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1258 return AddMember(name, v, allocator);
1261#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1263 return AddMember(name, value, allocator);
1265 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1266 return AddMember(name, value, allocator);
1268 GenericValue& AddMember(GenericValue& name, GenericValue&& value,
Allocator& allocator) {
1269 return AddMember(name, value, allocator);
1271 GenericValue& AddMember(StringRefType name, GenericValue&& value,
Allocator& allocator) {
1272 GenericValue n(name);
1273 return AddMember(n, value, allocator);
1290 return AddMember(n, value, allocator);
1304 return AddMember(name, v, allocator);
1324 template <
typename T>
1325 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1328 return AddMember(n, value, allocator);
1352 return RemoveMember(n);
1355#if RAPIDJSON_HAS_STDSTRING
1356 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1359 template <
typename SourceAllocator>
1360 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1361 MemberIterator m = FindMember(name);
1362 if (m != MemberEnd()) {
1385 if (data_.o.size > 1 && m != last)
1403 return EraseMember(pos, pos +1);
1426 std::memmove(&*pos, &*last,
static_cast<size_t>(MemberEnd() - last) *
sizeof(
Member));
1427 data_.o.size -=
static_cast<SizeType>(last - first);
1438 return EraseMember(n);
1441#if RAPIDJSON_HAS_STDSTRING
1442 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1445 template <
typename SourceAllocator>
1446 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1447 MemberIterator m = FindMember(name);
1448 if (m != MemberEnd()) {
1457 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1497 return GetElementsPointer()[index];
1522 if (newCapacity > data_.a.capacity) {
1524 data_.a.capacity = newCapacity;
1541 if (data_.a.size >= data_.a.capacity)
1542 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1543 GetElementsPointer()[data_.a.size++].RawAssign(value);
1547#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1549 return PushBack(value, allocator);
1563 return (*this).template PushBack<StringRefType>(value, allocator);
1583 template <
typename T>
1584 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1587 return PushBack(v, allocator);
1597 GetElementsPointer()[--data_.a.size].~GenericValue();
1609 return Erase(pos, pos + 1);
1630 std::memmove(pos, last,
static_cast<size_t>(End() - last) *
sizeof(
GenericValue));
1631 data_.a.size -=
static_cast<SizeType>(last - first);
1636 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1643 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1644 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1645 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1646 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1653 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1654 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1655 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1656 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1657 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1664 return static_cast<float>(GetDouble());
1668 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1669 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1670 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1671 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1672 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(f);
return *
this; }
1679 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1721#if RAPIDJSON_HAS_STDSTRING
1741 template <
typename T>
1742 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1744 template <
typename T>
1745 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1747 template <
typename T>
1748 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1750 template<
typename T>
1751 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1753 template<
typename T>
1754 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1765 template <
typename Handler>
1770 case kTrueType:
return handler.Bool(
true);
1777 if (
RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1782 return handler.EndObject(data_.o.size);
1790 return handler.EndArray(data_.a.size);
1793 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1797 if (IsDouble())
return handler.Double(data_.n.d);
1798 else if (IsInt())
return handler.Int(data_.n.i.i);
1799 else if (IsUint())
return handler.Uint(data_.n.u.u);
1800 else if (IsInt64())
return handler.Int64(data_.n.i64);
1801 else return handler.Uint64(data_.n.u64);
1806 template <
typename,
typename>
friend class GenericValue;
1811 kNumberFlag = 0x0010,
1814 kInt64Flag = 0x0080,
1815 kUint64Flag = 0x0100,
1816 kDoubleFlag = 0x0200,
1817 kStringFlag = 0x0400,
1819 kInlineStrFlag = 0x1000,
1825 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1826 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1827 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1828 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1829 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1830 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1832 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1833 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1840 static const SizeType kDefaultArrayCapacity = 16;
1841 static const SizeType kDefaultObjectCapacity = 16;
1844#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1845 char payload[
sizeof(
SizeType) * 2 + 6];
1846#elif RAPIDJSON_64BIT
1847 char payload[
sizeof(
SizeType) * 2 +
sizeof(
void*) + 6];
1849 char payload[
sizeof(
SizeType) * 2 +
sizeof(
void*) + 2];
1868 struct ShortString {
1869 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1872 inline static bool Usable(
SizeType len) {
return (MaxSize >= len); }
1873 inline void SetLength(
SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
1874 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
1879#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1924 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
1925 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
1926 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
1927 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
1928 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
1929 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
1933 data_.f.flags = kArrayFlag;
1935 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
1936 SetElementsPointer(e);
1937 std::memcpy(e, values, count *
sizeof(GenericValue));
1940 SetElementsPointer(0);
1941 data_.a.size = data_.a.capacity = count;
1946 data_.f.flags = kObjectFlag;
1948 Member* m =
static_cast<Member*
>(allocator.Malloc(count *
sizeof(Member)));
1949 SetMembersPointer(m);
1950 std::memcpy(m, members, count *
sizeof(Member));
1953 SetMembersPointer(0);
1954 data_.o.size = data_.o.capacity = count;
1958 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
1959 data_.f.flags = kConstStringFlag;
1960 SetStringPointer(s);
1961 data_.s.length = s.length;
1965 void SetStringRaw(StringRefType s,
Allocator& allocator) {
1967 if (ShortString::Usable(s.length)) {
1968 data_.f.flags = kShortStringFlag;
1969 data_.ss.SetLength(s.length);
1972 data_.f.flags = kCopyStringFlag;
1973 data_.s.length = s.length;
1974 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
1975 SetStringPointer(str);
1977 std::memcpy(str, s, s.length *
sizeof(Ch));
1978 str[s.length] =
'\0';
1982 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
1985 rhs.data_.f.flags = kNullFlag;
1988 template <
typename SourceAllocator>
1989 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
1993 const SizeType len1 = GetStringLength();
1994 const SizeType len2 = rhs.GetStringLength();
1995 if(len1 != len2) {
return false; }
1997 const Ch*
const str1 = GetString();
1998 const Ch*
const str2 = rhs.GetString();
1999 if(str1 == str2) {
return true; }
2001 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2021template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
2024 typedef typename Encoding::Ch
Ch;
2049 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2055#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2058 : ValueType(std::forward<ValueType>(rhs)),
2059 allocator_(rhs.allocator_),
2060 ownAllocator_(rhs.ownAllocator_),
2061 stack_(std::move(rhs.stack_)),
2062 parseResult_(rhs.parseResult_)
2065 rhs.ownAllocator_ = 0;
2070 ~GenericDocument() {
2074#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2076 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2080 ValueType::operator=(std::forward<ValueType>(rhs));
2085 allocator_ = rhs.allocator_;
2086 ownAllocator_ = rhs.ownAllocator_;
2087 stack_ = std::move(rhs.stack_);
2088 parseResult_ = rhs.parseResult_;
2091 rhs.ownAllocator_ = 0;
2092 rhs.parseResult_ = ParseResult();
2105 ValueType::Swap(rhs);
2106 stack_.Swap(rhs.stack_);
2107 internal::Swap(allocator_, rhs.allocator_);
2108 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2109 internal::Swap(parseResult_, rhs.parseResult_);
2132 template <
typename Generator>
2134 ClearStackOnExit scope(*
this);
2137 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2152 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2155 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2156 ClearStackOnExit scope(*
this);
2157 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
2160 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2171 template <
unsigned parseFlags,
typename InputStream>
2173 return ParseStream<parseFlags, Encoding, InputStream>(is);
2181 template <
typename InputStream>
2183 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2195 template <
unsigned parseFlags>
2198 return ParseStream<parseFlags | kParseInsituFlag>(s);
2206 return ParseInsitu<kParseDefaultFlags>(str);
2218 template <
unsigned parseFlags,
typename SourceEncoding>
2222 return ParseStream<parseFlags, SourceEncoding>(s);
2229 template <
unsigned parseFlags>
2231 return Parse<parseFlags, Encoding>(str);
2238 return Parse<kParseDefaultFlags>(str);
2241 template <
unsigned parseFlags,
typename SourceEncoding>
2242 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2244 MemoryStream ms(
static_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2246 ParseStream<parseFlags, SourceEncoding>(is);
2250 template <
unsigned parseFlags>
2251 GenericDocument& Parse(
const Ch* str,
size_t length) {
2252 return Parse<parseFlags, Encoding>(str, length);
2255 GenericDocument& Parse(
const Ch* str,
size_t length) {
2256 return Parse<kParseDefaultFlags>(str, length);
2259#if RAPIDJSON_HAS_STDSTRING
2260 template <
unsigned parseFlags,
typename SourceEncoding>
2261 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2263 return Parse<parseFlags, SourceEncoding>(str.c_str());
2266 template <
unsigned parseFlags>
2267 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2268 return Parse<parseFlags, Encoding>(str.c_str());
2271 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2272 return Parse<kParseDefaultFlags>(str);
2316 struct ClearStackOnExit {
2318 ~ClearStackOnExit() { d_.ClearStack(); }
2320 ClearStackOnExit(
const ClearStackOnExit&);
2321 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2322 GenericDocument& d_;
2327 template <
typename,
typename>
friend class GenericValue;
2331 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2332 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2333 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2334 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2335 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2336 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2337 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2339 bool RawNumber(
const Ch* str,
SizeType length,
bool copy) {
2341 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2343 new (stack_.template Push<ValueType>()) ValueType(str, length);
2347 bool String(
const Ch* str,
SizeType length,
bool copy) {
2349 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2351 new (stack_.template Push<ValueType>()) ValueType(str, length);
2355 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(
kObjectType);
return true; }
2357 bool Key(
const Ch* str,
SizeType length,
bool copy) {
return String(str, length, copy); }
2359 bool EndObject(
SizeType memberCount) {
2360 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2361 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2365 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(
kArrayType);
return true; }
2367 bool EndArray(
SizeType elementCount) {
2368 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2369 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2375 GenericDocument(
const GenericDocument&);
2377 GenericDocument& operator=(
const GenericDocument&);
2380 if (Allocator::kNeedFree)
2381 while (stack_.GetSize() > 0)
2382 (stack_.template Pop<ValueType>(1))->~ValueType();
2385 stack_.ShrinkToFit();
2392 static const size_t kDefaultStackCapacity = 1024;
2395 internal::Stack<StackAllocator> stack_;
2396 ParseResult parseResult_;
2403template <
typename Encoding,
typename Allocator>
2404template <
typename SourceAllocator>
2408 switch (rhs.GetType()) {
2413 RawAssign(*d.stack_.template Pop<GenericValue>(1));
2417 if (rhs.data_.f.flags == kConstStringFlag) {
2418 data_.f.flags = rhs.data_.f.flags;
2419 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2425 data_.f.flags = rhs.data_.f.flags;
2426 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2436template <
bool Const,
typename ValueT>
2441 typedef ValueT PlainType;
2443 typedef ValueType* ValueIterator;
2444 typedef const ValueT* ConstValueIterator;
2445 typedef typename ValueType::AllocatorType AllocatorType;
2446 typedef typename ValueType::StringRefType StringRefType;
2448 template <
typename,
typename>
2455 SizeType Size()
const {
return value_.Size(); }
2456 SizeType Capacity()
const {
return value_.Capacity(); }
2457 bool Empty()
const {
return value_.Empty(); }
2458 void Clear()
const { value_.Clear(); }
2459 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2460 ValueIterator Begin()
const {
return value_.Begin(); }
2461 ValueIterator End()
const {
return value_.End(); }
2462 GenericArray Reserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.Reserve(newCapacity, allocator);
return *
this; }
2463 GenericArray PushBack(ValueType& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2464#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2465 GenericArray PushBack(ValueType&& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2467 GenericArray PushBack(StringRefType value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2468 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; }
2469 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2470 ValueIterator Erase(ConstValueIterator pos)
const {
return value_.Erase(pos); }
2471 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
const {
return value_.Erase(first, last); }
2473#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2474 ValueIterator begin()
const {
return value_.Begin(); }
2475 ValueIterator end()
const {
return value_.End(); }
2489template <
bool Const,
typename ValueT>
2494 typedef ValueT PlainType;
2498 typedef typename ValueType::AllocatorType AllocatorType;
2499 typedef typename ValueType::StringRefType StringRefType;
2500 typedef typename ValueType::EncodingType EncodingType;
2501 typedef typename ValueType::Ch Ch;
2503 template <
typename,
typename>
2510 SizeType MemberCount()
const {
return value_.MemberCount(); }
2511 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2512 template <
typename T> ValueType& operator[](T* name)
const {
return value_[name]; }
2514#if RAPIDJSON_HAS_STDSTRING
2515 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2517 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2519 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2520#if RAPIDJSON_HAS_STDSTRING
2521 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2524 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2526#if RAPIDJSON_HAS_STDSTRING
2527 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2529 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2530 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2531#if RAPIDJSON_HAS_STDSTRING
2532 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2534 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; }
2535#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2536 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2537 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2538 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2539 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2541 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2542 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2543 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; }
2544 void RemoveAllMembers() {
return value_.RemoveAllMembers(); }
2545 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
2546#if RAPIDJSON_HAS_STDSTRING
2547 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
2553 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
2554#if RAPIDJSON_HAS_STDSTRING
2555 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
2559#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2570RAPIDJSON_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:2437
A document for parsing JSON text as DOM.
Definition: document.h:2022
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition: document.h:2133
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2306
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:2205
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2125
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:2312
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:2172
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2025
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:2026
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:2153
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition: document.h:2282
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2048
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:2024
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:2182
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2035
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2219
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:2285
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2104
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:2196
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:2237
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:2288
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:2230
(Constant) member iterator for a JSON object value
Definition: document.h:103
BaseType::pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:121
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:118
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:114
BaseType::difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:125
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:116
BaseType::reference Reference
Reference to (const) GenericMember.
Definition: document.h:123
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:149
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:187
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:131
Helper class for accessing Value of object type.
Definition: document.h:2490
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: document.h:538
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:541
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:542
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1719
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:548
ConstValueIterator Begin() const
Constant element iterator.
Definition: document.h:1509
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:772
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition: document.h:1415
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition: document.h:1402
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:1011
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:1684
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:659
bool ObjectEmpty() const
Check whether the object is empty.
Definition: document.h:1017
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition: document.h:1701
MemberIterator FindMember(const std::basic_string< Ch > &name)
Find member by string object name.
Definition: document.h:1170
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition: document.h:1076
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:753
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics.
Definition: document.h:839
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition: document.h:1539
~GenericValue()
Destructor.
Definition: document.h:717
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1184
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:638
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Deep-copy assignment from Value.
Definition: document.h:803
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:1520
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:1466
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:1594
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:674
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:545
float GetFloat() const
Get the value as float type.
Definition: document.h:1663
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:835
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:543
GenericValue & SetBool(bool b)
Definition: document.h:1002
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition: document.h:815
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1302
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Explicit copy constructor (with allocator)
Definition: document.h:2406
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition: document.h:913
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:590
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:677
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition: document.h:1608
void RemoveAllMembers()
Remove all members in the object.
Definition: document.h:1335
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1288
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:547
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:671
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition: document.h:698
bool GetBool() const
Set boolean value.
Definition: document.h:999
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition: document.h:1116
SizeType Size() const
Get the number of elements in array.
Definition: document.h:1469
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:1472
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:683
GenericValue(const std::basic_string< Ch > &s, Allocator &allocator)
Constructor for copy-string from a string object (i.e. do make a copy of string)
Definition: document.h:689
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition: document.h:709
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:549
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition: document.h:1046
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition: document.h:1562
SizeType MemberCount() const
Get the number of members in the object.
Definition: document.h:1014
ValueIterator Begin()
Element iterator.
Definition: document.h:1503
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition: document.h:1151
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition: document.h:1620
MemberIterator MemberBegin()
Member iterator.
Definition: document.h:1079
bool HasMember(const std::basic_string< Ch > &name) const
Check whether a member exists in the object with string object.
Definition: document.h:1103
double GetDouble() const
Get the value as double type.
Definition: document.h:1651
GenericValue & operator[](const std::basic_string< Ch > &name)
Get a value from an object associated with name (string object).
Definition: document.h:1067
void Clear()
Remove all elements in the array.
Definition: document.h:1481
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:1350
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:1092
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:923
bool operator==(const T &rhs) const
Equal-to operator with primitive types.
Definition: document.h:904
ValueIterator End()
Past-the-end element iterator
Definition: document.h:1506
GenericValue & AddMember(GenericValue &name, std::basic_string< Ch > &value, Allocator &allocator)
Add a string object as member (name-value pair) to the object.
Definition: document.h:1231
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition: document.h:850
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:1694
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:623
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:632
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition: document.h:1512
bool EraseMember(const Ch *name)
Erase a member in object by its name.
Definition: document.h:1436
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition: document.h:1029
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:1494
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:546
bool Is() const
Templated version for checking whether this value is type T.
Definition: document.h:1742
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:644
bool Empty() const
Check whether the array is empty.
Definition: document.h:1475
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:560
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition: document.h:1130
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:550
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:1766
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition: document.h:910
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1711
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:680
MemberIterator MemberEnd()
Past-the-end member iterator
Definition: document.h:1082
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:544
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:928
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types.
Definition: document.h:918
GenericValue & SetString(const std::basic_string< Ch > &s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1729
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition: document.h:1073
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1216
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition: document.h:892
bool operator==(const std::basic_string< Ch > &rhs) const
Equal-to operator with string object.
Definition: document.h:898
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition: document.h:1378
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:126
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:380
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:147
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2008
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2400
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
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:382
#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: document.h:71
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:73
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:72
Reference to a constant string (not taking a copy)
Definition: document.h:249
const Ch *const s
plain CharType pointer
Definition: document.h:322
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:302
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string.
Definition: document.h:364
CharType Ch
character type of the string
Definition: document.h:250
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:344
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:278
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:314
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition: document.h:323
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:382
Read-only string stream.
Definition: stream.h:110
Definition: document.h:1889
Definition: document.h:1893
Represents an in-memory input byte stream.
Definition: memorystream.h:40