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> {
109 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
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) {}
303 : s(str), length(NotNullStrLen(str)) {}
320 operator const Ch *()
const {
return s; }
328 return internal::StrLen(str);
332 static const Ch emptyString[];
341template<
typename CharType>
342const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
356template<
typename CharType>
376template<
typename CharType>
381#if RAPIDJSON_HAS_STDSTRING
394template<
typename CharType>
404template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
405struct IsGenericValueImpl : FalseType {};
408template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
409 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
412template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>::Type {};
421template <
typename ValueType,
typename T>
424template<
typename ValueType>
425struct TypeHelper<ValueType, bool> {
426 static bool Is(
const ValueType& v) {
return v.IsBool(); }
427 static bool Get(
const ValueType& v) {
return v.GetBool(); }
428 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
429 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
432template<
typename ValueType>
433struct TypeHelper<ValueType, int> {
434 static bool Is(
const ValueType& v) {
return v.IsInt(); }
435 static int Get(
const ValueType& v) {
return v.GetInt(); }
436 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
437 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
440template<
typename ValueType>
441struct TypeHelper<ValueType, unsigned> {
442 static bool Is(
const ValueType& v) {
return v.IsUint(); }
443 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
444 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
445 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
448template<
typename ValueType>
449struct TypeHelper<ValueType, int64_t> {
450 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
451 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
452 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
453 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
456template<
typename ValueType>
457struct TypeHelper<ValueType, uint64_t> {
458 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
459 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
460 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
461 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
464template<
typename ValueType>
465struct TypeHelper<ValueType, double> {
466 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
467 static double Get(
const ValueType& v) {
return v.GetDouble(); }
468 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
469 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
472template<
typename ValueType>
473struct TypeHelper<ValueType, float> {
474 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
475 static float Get(
const ValueType& v) {
return v.GetFloat(); }
476 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
477 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
480template<
typename ValueType>
481struct TypeHelper<ValueType, const typename ValueType::Ch*> {
482 typedef const typename ValueType::Ch* StringType;
483 static bool Is(
const ValueType& v) {
return v.IsString(); }
484 static StringType Get(
const ValueType& v) {
return v.GetString(); }
485 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
486 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
489#if RAPIDJSON_HAS_STDSTRING
490template<
typename ValueType>
491struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
492 typedef std::basic_string<typename ValueType::Ch> StringType;
493 static bool Is(
const ValueType& v) {
return v.IsString(); }
494 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
495 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
499template<
typename ValueType>
500struct TypeHelper<ValueType, typename ValueType::Array> {
501 typedef typename ValueType::Array ArrayType;
502 static bool Is(
const ValueType& v) {
return v.IsArray(); }
503 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
504 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
505 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
508template<
typename ValueType>
509struct TypeHelper<ValueType, typename ValueType::ConstArray> {
510 typedef typename ValueType::ConstArray ArrayType;
511 static bool Is(
const ValueType& v) {
return v.IsArray(); }
512 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
515template<
typename ValueType>
516struct TypeHelper<ValueType, typename ValueType::Object> {
517 typedef typename ValueType::Object ObjectType;
518 static bool Is(
const ValueType& v) {
return v.IsObject(); }
519 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
520 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
521 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) {
return v = data; }
524template<
typename ValueType>
525struct TypeHelper<ValueType, typename ValueType::ConstObject> {
526 typedef typename ValueType::ConstObject ObjectType;
527 static bool Is(
const ValueType& v) {
return v.IsObject(); }
528 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
534template <
bool,
typename>
class GenericArray;
535template <
bool,
typename>
class GenericObject;
550template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
557 typedef typename Encoding::Ch
Ch;
575#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
578 rhs.data_.f.flags = kNullFlag;
584 GenericValue(
const GenericValue& rhs);
586#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
588 template <
typename StackAllocator>
589 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
592 template <
typename StackAllocator>
593 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
605 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
613 data_.ss.SetLength(0);
624 template <
typename SourceAllocator>
626 switch (
rhs.GetType()) {
631 for (
SizeType i = 0; i < count; i++) {
635 data_.f.flags = kObjectFlag;
636 data_.o.size = data_.o.capacity = count;
637 SetMembersPointer(
lm);
644 for (
SizeType i = 0; i < count; i++)
646 data_.f.flags = kArrayFlag;
647 data_.a.size = data_.a.capacity = count;
648 SetElementsPointer(
le);
653 data_.f.flags =
rhs.data_.f.flags;
654 data_ = *
reinterpret_cast<const Data*
>(&
rhs.data_);
660 data_.f.flags =
rhs.data_.f.flags;
661 data_ = *
reinterpret_cast<const Data*
>(&
rhs.data_);
672#ifndef RAPIDJSON_DOXYGEN_RUNNING
673 template <
typename T>
681 data_.f.flags =
b ? kTrueFlag : kFalseFlag;
687 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
693 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
699 data_.f.flags = kNumberInt64Flag;
701 data_.f.flags |= kNumberUint64Flag;
703 data_.f.flags |= kUintFlag;
705 data_.f.flags |= kIntFlag;
708 data_.f.flags |= kIntFlag;
714 data_.f.flags = kNumberUint64Flag;
716 data_.f.flags |= kInt64Flag;
718 data_.f.flags |= kUintFlag;
720 data_.f.flags |= kIntFlag;
741#if RAPIDJSON_HAS_STDSTRING
755 a.value_.data_ = Data();
756 a.value_.data_.f.flags = kArrayFlag;
766 o.value_.data_ = Data();
767 o.value_.data_.f.flags = kObjectFlag;
774 if (Allocator::kNeedFree) {
775 switch(data_.f.flags) {
788 Allocator::Free(GetMembersPointer());
791 case kCopyStringFlag:
792 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
816#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
819 return *
this =
rhs.Move();
845 template <
typename T>
859 template <
typename SourceAllocator>
874 temp.RawAssign(*
this);
906 template <
typename SourceAllocator>
909 if (GetType() !=
rhs.GetType())
914 if (data_.o.size !=
rhs.data_.o.size)
924 if (data_.a.size !=
rhs.data_.a.size)
926 for (
SizeType i = 0; i < data_.a.size; i++)
927 if ((*
this)[i] !=
rhs[i])
932 return StringEqual(
rhs);
935 if (IsDouble() ||
rhs.IsDouble()) {
936 double a = GetDouble();
937 double b =
rhs.GetDouble();
938 return a >=
b && a <=
b;
941 return data_.n.u64 ==
rhs.data_.n.u64;
951#if RAPIDJSON_HAS_STDSTRING
966 template <
typename SourceAllocator>
991 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
992 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
993 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
994 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
995 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
996 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
997 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
998 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
999 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
1000 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
1001 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
1002 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
1003 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
1004 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
1007 bool IsLosslessDouble()
const {
1008 if (!IsNumber())
return false;
1010 uint64_t u = GetUint64();
1011 volatile double d =
static_cast<double>(u);
1013 && (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
1014 && (u ==
static_cast<uint64_t
>(d));
1017 int64_t i = GetInt64();
1018 volatile double d =
static_cast<double>(i);
1019 return (d >=
static_cast<double>((std::numeric_limits<int64_t>::min)()))
1020 && (d <
static_cast<double>((std::numeric_limits<int64_t>::max)()))
1021 && (i ==
static_cast<int64_t
>(d));
1027 bool IsFloat()
const {
1028 if ((data_.f.flags & kDoubleFlag) == 0)
1030 double d = GetDouble();
1031 return d >= -3.4028234e38 && d <= 3.4028234e38;
1034 bool IsLosslessFloat()
const {
1035 if (!IsNumber())
return false;
1036 double a = GetDouble();
1037 if (a <
static_cast<double>(-(std::numeric_limits<float>::max)())
1038 || a >
static_cast<double>((std::numeric_limits<float>::max)()))
1040 double b =
static_cast<double>(
static_cast<float>(a));
1041 return a >= b && a <= b;
1049 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1085 template <
typename T>
1090 template <
typename T>
1102 template <
typename SourceAllocator>
1105 if (
member != MemberEnd())
1119 template <
typename SourceAllocator>
1122#if RAPIDJSON_HAS_STDSTRING
1124 GenericValue& operator[](
const std::basic_string<Ch>& name) {
return (*
this)[GenericValue(StringRef(name))]; }
1125 const GenericValue& operator[](
const std::basic_string<Ch>& name)
const {
return (*
this)[GenericValue(
StringRef(name))]; }
1149 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
1151#if RAPIDJSON_HAS_STDSTRING
1160 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1172 template <
typename SourceAllocator>
1189 return FindMember(n);
1192 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1207 template <
typename SourceAllocator>
1213 if (name.StringEqual(
member->name))
1219#if RAPIDJSON_HAS_STDSTRING
1227 MemberIterator FindMember(
const std::basic_string<Ch>& name) {
return FindMember(GenericValue(StringRef(name))); }
1228 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(GenericValue(
StringRef(name))); }
1245 ObjectData& o = data_.o;
1246 if (o.size >= o.capacity) {
1247 if (o.capacity == 0) {
1248 o.capacity = kDefaultObjectCapacity;
1257 Member* members = GetMembersPointer();
1258 members[o.size].name.RawAssign(name);
1259 members[o.size].value.RawAssign(value);
1278#if RAPIDJSON_HAS_STDSTRING
1311 template <
typename T>
1312 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1318#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1320 return AddMember(name, value,
allocator);
1322 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1323 return AddMember(name, value, allocator);
1325 GenericValue& AddMember(GenericValue& name, GenericValue&& value,
Allocator& allocator) {
1326 return AddMember(name, value, allocator);
1328 GenericValue& AddMember(StringRefType name, GenericValue&& value,
Allocator& allocator) {
1329 GenericValue n(name);
1330 return AddMember(n, value, allocator);
1381 template <
typename T>
1409 return RemoveMember(n);
1412#if RAPIDJSON_HAS_STDSTRING
1413 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1416 template <
typename SourceAllocator>
1417 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1418 MemberIterator m = FindMember(name);
1419 if (m != MemberEnd()) {
1442 if (data_.o.size > 1 &&
m !=
last)
1460 return EraseMember(
pos,
pos +1);
1483 std::memmove(&*
pos, &*
last,
static_cast<size_t>(MemberEnd() -
last) *
sizeof(
Member));
1495 return EraseMember(n);
1498#if RAPIDJSON_HAS_STDSTRING
1499 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1502 template <
typename SourceAllocator>
1503 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1504 MemberIterator m = FindMember(name);
1505 if (m != MemberEnd()) {
1514 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1554 return GetElementsPointer()[index];
1598 if (data_.a.size >= data_.a.capacity)
1599 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2),
allocator);
1600 GetElementsPointer()[data_.a.size++].RawAssign(value);
1604#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1640 template <
typename T>
1654 GetElementsPointer()[--data_.a.size].~GenericValue();
1666 return Erase(
pos,
pos + 1);
1686 itr->~GenericValue();
1693 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1700 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1701 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1702 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1703 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1710 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1711 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1712 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1713 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1714 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1721 return static_cast<float>(GetDouble());
1725 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1726 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1727 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1728 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1729 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(
static_cast<double>(f));
return *
this; }
1736 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1786#if RAPIDJSON_HAS_STDSTRING
1806 template <
typename T>
1807 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1809 template <
typename T>
1810 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1812 template <
typename T>
1813 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1815 template<
typename T>
1816 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1818 template<
typename T>
1819 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1830 template <
typename Handler>
1847 return handler.EndObject(data_.o.size);
1855 return handler.EndArray(data_.a.size);
1858 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1862 if (IsDouble())
return handler.Double(data_.n.d);
1863 else if (IsInt())
return handler.Int(data_.n.i.i);
1864 else if (IsUint())
return handler.Uint(data_.n.u.u);
1865 else if (IsInt64())
return handler.Int64(data_.n.i64);
1866 else return handler.Uint64(data_.n.u64);
1871 template <
typename,
typename>
friend class GenericValue;
1876 kNumberFlag = 0x0010,
1879 kInt64Flag = 0x0080,
1880 kUint64Flag = 0x0100,
1881 kDoubleFlag = 0x0200,
1882 kStringFlag = 0x0400,
1884 kInlineStrFlag = 0x1000,
1890 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1891 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1892 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1893 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1894 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1895 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1897 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1898 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1905 static const SizeType kDefaultArrayCapacity = 16;
1906 static const SizeType kDefaultObjectCapacity = 16;
1909#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1910 char payload[
sizeof(SizeType) * 2 + 6];
1911#elif RAPIDJSON_64BIT
1912 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 6];
1914 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 2];
1933 struct ShortString {
1934 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1937 inline static bool Usable(SizeType len) {
return (MaxSize >= len); }
1938 inline void SetLength(SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
1939 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
1944#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1977 GenericValue* elements;
1989 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
1990 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
1991 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
1992 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
1993 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
1994 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
1997 void SetArrayRaw(GenericValue* values, SizeType count,
Allocator& allocator) {
1998 data_.f.flags = kArrayFlag;
2000 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
2001 SetElementsPointer(e);
2002 std::memcpy(e, values, count *
sizeof(GenericValue));
2005 SetElementsPointer(0);
2006 data_.a.size = data_.a.capacity = count;
2010 void SetObjectRaw(Member* members, SizeType count,
Allocator& allocator) {
2011 data_.f.flags = kObjectFlag;
2013 Member* m =
static_cast<Member*
>(allocator.Malloc(count *
sizeof(Member)));
2014 SetMembersPointer(m);
2015 std::memcpy(m, members, count *
sizeof(Member));
2018 SetMembersPointer(0);
2019 data_.o.size = data_.o.capacity = count;
2023 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2024 data_.f.flags = kConstStringFlag;
2025 SetStringPointer(s);
2026 data_.s.length = s.length;
2030 void SetStringRaw(StringRefType s,
Allocator& allocator) {
2032 if (ShortString::Usable(s.length)) {
2033 data_.f.flags = kShortStringFlag;
2034 data_.ss.SetLength(s.length);
2037 data_.f.flags = kCopyStringFlag;
2038 data_.s.length = s.length;
2039 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
2040 SetStringPointer(str);
2042 std::memcpy(str, s, s.length *
sizeof(Ch));
2043 str[s.length] =
'\0';
2047 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2050 rhs.data_.f.flags = kNullFlag;
2053 template <
typename SourceAllocator>
2054 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
2058 const SizeType len1 = GetStringLength();
2059 const SizeType len2 = rhs.GetStringLength();
2060 if(len1 != len2) {
return false; }
2062 const Ch*
const str1 = GetString();
2063 const Ch*
const str2 = rhs.GetString();
2064 if(str1 == str2) {
return true; }
2066 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2086template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
2089 typedef typename Encoding::Ch
Ch;
2120#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2123 : ValueType(std::forward<ValueType>(
rhs)),
2124 allocator_(
rhs.allocator_),
2125 ownAllocator_(
rhs.ownAllocator_),
2126 stack_(std::move(
rhs.stack_)),
2127 parseResult_(
rhs.parseResult_)
2130 rhs.ownAllocator_ = 0;
2135 ~GenericDocument() {
2139#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2141 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2145 ValueType::operator=(std::forward<ValueType>(rhs));
2150 allocator_ = rhs.allocator_;
2151 ownAllocator_ = rhs.ownAllocator_;
2152 stack_ = std::move(rhs.stack_);
2153 parseResult_ = rhs.parseResult_;
2156 rhs.ownAllocator_ = 0;
2157 rhs.parseResult_ = ParseResult();
2170 ValueType::Swap(
rhs);
2171 stack_.Swap(
rhs.stack_);
2172 internal::Swap(allocator_,
rhs.allocator_);
2173 internal::Swap(ownAllocator_,
rhs.ownAllocator_);
2174 internal::Swap(parseResult_,
rhs.parseResult_);
2180 using ValueType::Swap;
2201 template <
typename Generator>
2203 ClearStackOnExit
scope(*
this);
2221 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2224 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2225 ClearStackOnExit
scope(*
this);
2240 template <
unsigned parseFlags,
typename InputStream>
2250 template <
typename InputStream>
2264 template <
unsigned parseFlags>
2287 template <
unsigned parseFlags,
typename SourceEncoding>
2298 template <
unsigned parseFlags>
2310 template <
unsigned parseFlags,
typename SourceEncoding>
2311 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2313 MemoryStream ms(
reinterpret_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2319 template <
unsigned parseFlags>
2320 GenericDocument& Parse(
const Ch* str,
size_t length) {
2321 return Parse<parseFlags, Encoding>(str, length);
2324 GenericDocument& Parse(
const Ch* str,
size_t length) {
2325 return Parse<kParseDefaultFlags>(str, length);
2328#if RAPIDJSON_HAS_STDSTRING
2329 template <
unsigned parseFlags,
typename SourceEncoding>
2330 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2332 return Parse<parseFlags, SourceEncoding>(str.c_str());
2335 template <
unsigned parseFlags>
2336 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2337 return Parse<parseFlags, Encoding>(str.c_str());
2340 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2341 return Parse<kParseDefaultFlags>(str);
2385 struct ClearStackOnExit {
2387 ~ClearStackOnExit() { d_.ClearStack(); }
2389 ClearStackOnExit(
const ClearStackOnExit&);
2390 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2391 GenericDocument& d_;
2396 template <
typename,
typename>
friend class GenericValue;
2400 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2401 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2402 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2403 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2404 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2405 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2406 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2408 bool RawNumber(
const Ch* str, SizeType length,
bool copy) {
2410 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2412 new (stack_.template Push<ValueType>()) ValueType(str, length);
2416 bool String(
const Ch* str, SizeType length,
bool copy) {
2418 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2420 new (stack_.template Push<ValueType>()) ValueType(str, length);
2424 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(kObjectType);
return true; }
2426 bool Key(
const Ch* str, SizeType length,
bool copy) {
return String(str, length, copy); }
2428 bool EndObject(SizeType memberCount) {
2429 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2430 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2434 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(kArrayType);
return true; }
2436 bool EndArray(SizeType elementCount) {
2437 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2438 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2444 GenericDocument(
const GenericDocument&);
2446 GenericDocument& operator=(
const GenericDocument&);
2449 if (Allocator::kNeedFree)
2450 while (stack_.GetSize() > 0)
2451 (stack_.template Pop<ValueType>(1))->~ValueType();
2454 stack_.ShrinkToFit();
2461 static const size_t kDefaultStackCapacity = 1024;
2464 internal::Stack<StackAllocator> stack_;
2465 ParseResult parseResult_;
2476template <
bool Const,
typename ValueT>
2482 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2483 typedef ValueType* ValueIterator;
2485 typedef typename ValueType::AllocatorType AllocatorType;
2486 typedef typename ValueType::StringRefType StringRefType;
2488 template <
typename,
typename>
2495 SizeType Size()
const {
return value_.Size(); }
2496 SizeType Capacity()
const {
return value_.Capacity(); }
2497 bool Empty()
const {
return value_.Empty(); }
2498 void Clear()
const { value_.Clear(); }
2499 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2500 ValueIterator Begin()
const {
return value_.Begin(); }
2501 ValueIterator End()
const {
return value_.End(); }
2504#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2509 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2513#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2514 ValueIterator begin()
const {
return value_.Begin(); }
2515 ValueIterator end()
const {
return value_.End(); }
2529template <
bool Const,
typename ValueT>
2535 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2538 typedef typename ValueType::AllocatorType AllocatorType;
2539 typedef typename ValueType::StringRefType StringRefType;
2540 typedef typename ValueType::EncodingType EncodingType;
2541 typedef typename ValueType::Ch Ch;
2543 template <
typename,
typename>
2550 SizeType MemberCount()
const {
return value_.MemberCount(); }
2551 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2552 template <
typename T> ValueType& operator[](
T* name)
const {
return value_[name]; }
2554#if RAPIDJSON_HAS_STDSTRING
2555 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2557 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2559 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2560#if RAPIDJSON_HAS_STDSTRING
2561 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2564 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2566#if RAPIDJSON_HAS_STDSTRING
2567 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2569 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2570 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2571#if RAPIDJSON_HAS_STDSTRING
2572 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2574 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; }
2575#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2576 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2577 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2578 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2579 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2581 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2582 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType&
allocator)
const { value_.AddMember(name, value,
allocator);
return *
this; }
2584 void RemoveAllMembers() { value_.RemoveAllMembers(); }
2585 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
2586#if RAPIDJSON_HAS_STDSTRING
2587 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
2593 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
2594#if RAPIDJSON_HAS_STDSTRING
2595 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
2599#if RAPIDJSON_HAS_CXX11_RANGE_FOR
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:2477
A document for parsing JSON text as DOM.
Definition document.h:2087
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition document.h:2202
Allocator & GetAllocator()
Get the allocator of this document.
Definition document.h:2375
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition document.h:2274
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:2194
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition document.h:2381
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition document.h:2241
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition document.h:2090
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:2091
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition document.h:2222
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition document.h:2351
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition document.h:2113
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:2089
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition document.h:2251
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition document.h:2100
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2288
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition document.h:2354
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition document.h:2169
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition document.h:2265
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition document.h:2306
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition document.h:2357
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition document.h:2299
(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:2530
A Stream Wrapper.
Definition stream.h:119
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition document.h:551
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition document.h:554
Encoding EncodingType
Encoding type from template parameter.
Definition document.h:555
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1776
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition document.h:561
ConstValueIterator Begin() const
Constant element iterator.
Definition document.h:1566
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition document.h:828
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition document.h:1472
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition document.h:1459
GenericValue & SetObject()
Set this value as an empty object.
Definition document.h:1068
SizeType GetStringLength() const
Get the length of string.
Definition document.h:1741
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition document.h:712
bool ObjectEmpty() const
Check whether the object is empty.
Definition document.h:1074
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition document.h:1758
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition document.h:1133
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition document.h:809
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics.
Definition document.h:896
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition document.h:1596
~GenericValue()
Destructor.
Definition document.h:773
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition document.h:1241
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition document.h:691
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition document.h:1577
GenericValue & SetArray()
Set this value as an empty array.
Definition document.h:1523
GenericValue & PopBack()
Remove the last element in the array.
Definition document.h:1651
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:730
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition document.h:558
float GetFloat() const
Get the value as float type.
Definition document.h:1720
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:892
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:556
GenericValue & SetBool(bool b)
Definition document.h:1059
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition document.h:872
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition document.h:1359
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition document.h:970
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition document.h:603
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:733
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition document.h:1665
void RemoveAllMembers()
Remove all members in the object.
Definition document.h:1392
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition document.h:1345
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition document.h:560
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition document.h:724
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition document.h:754
bool GetBool() const
Set boolean value.
Definition document.h:1056
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition document.h:1173
SizeType Size() const
Get the number of elements in array.
Definition document.h:1526
SizeType Capacity() const
Get the capacity of array.
Definition document.h:1529
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:739
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition document.h:765
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition document.h:562
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition document.h:1103
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition document.h:1619
SizeType MemberCount() const
Get the number of members in the object.
Definition document.h:1071
ValueIterator Begin()
Element iterator.
Definition document.h:1560
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition document.h:1208
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition document.h:1677
MemberIterator MemberBegin()
Member iterator.
Definition document.h:1136
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Deep-copy assignment from Value.
Definition document.h:860
double GetDouble() const
Get the value as double type.
Definition document.h:1708
void Clear()
Remove all elements in the array.
Definition document.h:1538
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition document.h:1407
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition document.h:1149
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition document.h:980
bool operator==(const T &rhs) const
Equal-to operator with primitive types.
Definition document.h:961
ValueIterator End()
Past-the-end element iterator
Definition document.h:1563
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition document.h:907
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition document.h:1751
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition document.h:676
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition document.h:685
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition document.h:1569
bool EraseMember(const Ch *name)
Erase a member in object by its name.
Definition document.h:1493
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition document.h:1086
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition document.h:1551
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition document.h:559
bool Is() const
Templated version for checking whether this value is type T.
Definition document.h:1807
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition document.h:697
bool Empty() const
Check whether the array is empty.
Definition document.h:1532
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition document.h:573
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition document.h:1187
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition document.h:563
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition document.h:1831
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition document.h:967
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1768
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:736
MemberIterator MemberEnd()
Past-the-end member iterator
Definition document.h:1139
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition document.h:625
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:557
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition document.h:985
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types.
Definition document.h:975
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition document.h:1130
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition document.h:1273
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition document.h:949
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition document.h:1435
GenericValue & SetString(StringRefType s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1784
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition document.h:727
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition rapidjson.h:468
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:481
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:411
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:389
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition reader.h:149
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition document.h:357
Type
Type of JSON value.
Definition rapidjson.h:616
@ kArrayType
array
Definition rapidjson.h:621
@ kTrueType
true
Definition rapidjson.h:619
@ kNullType
null
Definition rapidjson.h:617
@ kFalseType
false
Definition rapidjson.h:618
@ kNumberType
number
Definition rapidjson.h:623
@ kObjectType
object
Definition rapidjson.h:620
@ kStringType
string
Definition rapidjson.h:622
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition rapidjson.h:603
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:294
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition rapidjson.h:599
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition rapidjson.h:450
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:377
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:357
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
Definition document.h:1945
Definition document.h:1949
Represents an in-memory input byte stream.
Definition memorystream.h:40