15#ifndef RAPIDJSON_DOCUMENT_H_
16#define RAPIDJSON_DOCUMENT_H_
21#include "internal/meta.h"
22#include "internal/strfunc.h"
23#include "memorystream.h"
24#include "encodedstream.h"
27#ifdef __cpp_lib_three_way_comparison
33RAPIDJSON_DIAG_OFF(padded)
34RAPIDJSON_DIAG_OFF(
switch-
enum)
35RAPIDJSON_DIAG_OFF(c++98-compat)
36#elif defined(_MSC_VER)
37RAPIDJSON_DIAG_OFF(4127)
38RAPIDJSON_DIAG_OFF(4244)
42RAPIDJSON_DIAG_OFF(effc++)
49#pragma push_macro("GetObject")
50#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
54#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
58#if RAPIDJSON_USE_MEMBERSMAP
62RAPIDJSON_NAMESPACE_BEGIN
65template <
typename Encoding,
typename Allocator>
68template <
typename Encoding,
typename Allocator,
typename StackAllocator>
77#ifndef RAPIDJSON_DEFAULT_ALLOCATOR
78#define RAPIDJSON_DEFAULT_ALLOCATOR ::RAPIDJSON_NAMESPACE::MemoryPoolAllocator<::RAPIDJSON_NAMESPACE::CrtAllocator>
87#ifndef RAPIDJSON_DEFAULT_STACK_ALLOCATOR
88#define RAPIDJSON_DEFAULT_STACK_ALLOCATOR ::RAPIDJSON_NAMESPACE::CrtAllocator
97#ifndef RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY
99#define RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY 16
108#ifndef RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY
110#define RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY 16
119template <
typename Encoding,
typename Allocator>
125#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
128 : name(std::move(rhs.name)),
129 value(std::move(rhs.value))
153 a.value.
Swap(b.value);
158 GenericMember(
const GenericMember& rhs);
164#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
185template <
bool Const,
typename Encoding,
typename Allocator>
192 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
204 typedef ValueType value_type;
205 typedef ValueType * pointer;
206 typedef ValueType & reference;
207 typedef std::ptrdiff_t difference_type;
208 typedef std::random_access_iterator_tag iterator_category;
241 Iterator& operator=(
const NonConstIterator & it) { ptr_ = it.ptr_;
return *
this; }
245 Iterator& operator++(){ ++ptr_;
return *
this; }
246 Iterator& operator--(){ --ptr_;
return *
this; }
247 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
248 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
253 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
254 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
256 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
257 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
262 template <
bool Const_>
bool operator==(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ == that.ptr_; }
263 template <
bool Const_>
bool operator!=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ != that.ptr_; }
264 template <
bool Const_>
bool operator<=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ <= that.ptr_; }
265 template <
bool Const_>
bool operator>=(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ >= that.ptr_; }
266 template <
bool Const_>
bool operator< (
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ < that.ptr_; }
267 template <
bool Const_>
bool operator> (
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ > that.ptr_; }
269#ifdef __cpp_lib_three_way_comparison
270 template <
bool Const_> std::strong_ordering operator<=>(
const GenericMemberIterator<Const_, Encoding, Allocator>& that)
const {
return ptr_ <=> that.ptr_; }
276 Reference operator*()
const {
return *ptr_; }
277 Pointer operator->()
const {
return ptr_; }
278 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
295template <
bool Const,
typename Encoding,
typename Allocator>
296class GenericMemberIterator;
299template <
typename Encoding,
typename Allocator>
303 typedef GenericMember<Encoding,Allocator>* Iterator;
306template <
typename Encoding,
typename Allocator>
310 typedef const GenericMember<Encoding,Allocator>* Iterator;
345template<
typename CharType>
376 : s(str), length(N-1) {}
400 : s(str), length(NotNullStrLen(str)) {}
417 operator const Ch *()
const {
return s; }
423 SizeType NotNullStrLen(
const CharType* str) {
425 return internal::StrLen(str);
429 static const Ch emptyString[];
438template<
typename CharType>
439const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
453template<
typename CharType>
473template<
typename CharType>
478#if RAPIDJSON_HAS_STDSTRING
491template<
typename CharType>
501template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
502struct IsGenericValueImpl : FalseType {};
505template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>::Type, typename Void<typename T::AllocatorType>::Type>
506 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>::Type {};
509template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>::Type {};
518template <
typename ValueType,
typename T>
521template<
typename ValueType>
522struct TypeHelper<ValueType, bool> {
523 static bool Is(
const ValueType& v) {
return v.IsBool(); }
524 static bool Get(
const ValueType& v) {
return v.GetBool(); }
525 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
526 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
529template<
typename ValueType>
530struct TypeHelper<ValueType, int> {
531 static bool Is(
const ValueType& v) {
return v.IsInt(); }
532 static int Get(
const ValueType& v) {
return v.GetInt(); }
533 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
534 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
537template<
typename ValueType>
538struct TypeHelper<ValueType, unsigned> {
539 static bool Is(
const ValueType& v) {
return v.IsUint(); }
540 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
541 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
542 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
547template<
typename ValueType>
548struct TypeHelper<ValueType, long> {
549 static bool Is(
const ValueType& v) {
return v.IsInt(); }
550 static long Get(
const ValueType& v) {
return v.GetInt(); }
551 static ValueType& Set(ValueType& v,
long data) {
return v.SetInt(data); }
552 static ValueType& Set(ValueType& v,
long data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
556template<
typename ValueType>
557struct TypeHelper<ValueType, unsigned long> {
558 static bool Is(
const ValueType& v) {
return v.IsUint(); }
559 static unsigned long Get(
const ValueType& v) {
return v.GetUint(); }
560 static ValueType& Set(ValueType& v,
unsigned long data) {
return v.SetUint(data); }
561 static ValueType& Set(ValueType& v,
unsigned long data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
565template<
typename ValueType>
566struct TypeHelper<ValueType, int64_t> {
567 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
568 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
569 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
570 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
573template<
typename ValueType>
574struct TypeHelper<ValueType, uint64_t> {
575 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
576 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
577 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
578 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
581template<
typename ValueType>
582struct TypeHelper<ValueType, double> {
583 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
584 static double Get(
const ValueType& v) {
return v.GetDouble(); }
585 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
586 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
589template<
typename ValueType>
590struct TypeHelper<ValueType, float> {
591 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
592 static float Get(
const ValueType& v) {
return v.GetFloat(); }
593 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
594 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
597template<
typename ValueType>
598struct TypeHelper<ValueType, const typename ValueType::Ch*> {
599 typedef const typename ValueType::Ch* StringType;
600 static bool Is(
const ValueType& v) {
return v.IsString(); }
601 static StringType Get(
const ValueType& v) {
return v.GetString(); }
602 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
603 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
606#if RAPIDJSON_HAS_STDSTRING
607template<
typename ValueType>
608struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
609 typedef std::basic_string<typename ValueType::Ch> StringType;
610 static bool Is(
const ValueType& v) {
return v.IsString(); }
611 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
612 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
616template<
typename ValueType>
617struct TypeHelper<ValueType, typename ValueType::Array> {
618 typedef typename ValueType::Array ArrayType;
619 static bool Is(
const ValueType& v) {
return v.IsArray(); }
620 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
621 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
622 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
625template<
typename ValueType>
626struct TypeHelper<ValueType, typename ValueType::ConstArray> {
627 typedef typename ValueType::ConstArray ArrayType;
628 static bool Is(
const ValueType& v) {
return v.IsArray(); }
629 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
632template<
typename ValueType>
633struct TypeHelper<ValueType, typename ValueType::Object> {
634 typedef typename ValueType::Object ObjectType;
635 static bool Is(
const ValueType& v) {
return v.IsObject(); }
636 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
637 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
638 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) {
return v = data; }
641template<
typename ValueType>
642struct TypeHelper<ValueType, typename ValueType::ConstObject> {
643 typedef typename ValueType::ConstObject ObjectType;
644 static bool Is(
const ValueType& v) {
return v.IsObject(); }
645 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
651template <
bool,
typename>
class GenericArray;
652template <
bool,
typename>
class GenericObject;
667template <
typename Encoding,
typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR >
674 typedef typename Encoding::Ch
Ch;
690 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
692#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
695 rhs.data_.f.flags = kNullFlag;
701 GenericValue(
const GenericValue& rhs);
703#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
705 template <
typename StackAllocator>
706 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
709 template <
typename StackAllocator>
710 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
721 static const uint16_t defaultFlags[] = {
722 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
726 data_.f.flags = defaultFlags[type];
730 data_.ss.SetLength(0);
741 template <
typename SourceAllocator>
743 switch (rhs.GetType()) {
745 DoCopyMembers(rhs, allocator, copyConstStrings);
751 for (
SizeType i = 0; i < count; i++)
752 new (&le[i])
GenericValue(re[i], allocator, copyConstStrings);
753 data_.f.flags = kArrayFlag;
754 data_.a.size = data_.a.capacity = count;
755 SetElementsPointer(le);
759 if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
760 data_.f.flags = rhs.data_.f.flags;
761 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
767 data_.f.flags = rhs.data_.f.flags;
768 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
779#ifndef RAPIDJSON_DOXYGEN_RUNNING
780 template <
typename T>
781 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT
788 data_.f.flags = b ? kTrueFlag : kFalseFlag;
794 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
800 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
806 data_.f.flags = kNumberInt64Flag;
808 data_.f.flags |= kNumberUint64Flag;
810 data_.f.flags |= kUintFlag;
812 data_.f.flags |= kIntFlag;
815 data_.f.flags |= kIntFlag;
821 data_.f.flags = kNumberUint64Flag;
823 data_.f.flags |= kInt64Flag;
825 data_.f.flags |= kUintFlag;
827 data_.f.flags |= kIntFlag;
831 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
834 explicit GenericValue(
float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d =
static_cast<double>(f); data_.f.flags = kNumberDoubleFlag; }
848#if RAPIDJSON_HAS_STDSTRING
862 a.value_.data_ = Data();
863 a.value_.data_.f.flags = kArrayFlag;
873 o.value_.data_ = Data();
874 o.value_.data_.f.flags = kObjectFlag;
884 internal::IsRefCounted<Allocator>::Value)) {
885 switch(data_.f.flags) {
891 if (Allocator::kNeedFree) {
901 case kCopyStringFlag:
902 if (Allocator::kNeedFree) {
903 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
934#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
937 return *
this = rhs.
Move();
963 template <
typename T>
964 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
977 template <
typename SourceAllocator>
979 RAPIDJSON_ASSERT(
static_cast<void*
>(
this) !=
static_cast<void const*
>(&rhs));
981 new (
this)
GenericValue(rhs, allocator, copyConstStrings);
992 temp.RawAssign(*
this);
994 other.RawAssign(temp);
1024 template <
typename SourceAllocator>
1027 if (GetType() != rhs.GetType())
1030 switch (GetType()) {
1032 if (data_.o.size != rhs.data_.o.size)
1034 for (
ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
1035 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.
FindMember(lhsMemberItr->name);
1036 if (rhsMemberItr == rhs.
MemberEnd() || (!(lhsMemberItr->value == rhsMemberItr->value)))
1042 if (data_.a.size != rhs.data_.a.size)
1044 for (
SizeType i = 0; i < data_.a.size; i++)
1045 if (!((*
this)[i] == rhs[i]))
1050 return StringEqual(rhs);
1053 if (IsDouble() || rhs.IsDouble()) {
1054 double a = GetDouble();
1056 return a >= b && a <= b;
1059 return data_.n.u64 == rhs.data_.n.u64;
1069#if RAPIDJSON_HAS_STDSTRING
1073 bool operator==(
const std::basic_string<Ch>& rhs)
const {
return *
this ==
GenericValue(
StringRef(rhs)); }
1079 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
1081#ifndef __cpp_impl_three_way_comparison
1085 template <
typename SourceAllocator>
1094 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
1099 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
1104 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
1111 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
1112 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
1113 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
1114 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
1115 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
1116 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
1117 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
1118 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
1119 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
1120 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
1121 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
1122 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
1123 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
1124 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
1127 bool IsLosslessDouble()
const {
1128 if (!IsNumber())
return false;
1130 uint64_t u = GetUint64();
1131 volatile double d =
static_cast<double>(u);
1133 && (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
1134 && (u ==
static_cast<uint64_t
>(d));
1137 int64_t i = GetInt64();
1138 volatile double d =
static_cast<double>(i);
1139 return (d >=
static_cast<double>((std::numeric_limits<int64_t>::min)()))
1140 && (d <
static_cast<double>((std::numeric_limits<int64_t>::max)()))
1141 && (i ==
static_cast<int64_t
>(d));
1147 bool IsFloat()
const {
1148 if ((data_.f.flags & kDoubleFlag) == 0)
1150 double d = GetDouble();
1151 return d >= -3.4028234e38 && d <= 3.4028234e38;
1154 bool IsLosslessFloat()
const {
1155 if (!IsNumber())
return false;
1156 double a = GetDouble();
1157 if (a <
static_cast<double>(-(std::numeric_limits<float>::max)())
1158 || a >
static_cast<double>((std::numeric_limits<float>::max)()))
1160 double b =
static_cast<double>(
static_cast<float>(a));
1161 return a >= b && a <= b;
1169 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1208 template <
typename T>
1209 RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<
typename internal::RemoveConst<T>::Type,
Ch> >),(
GenericValue&))
operator[](T* name) {
1213 template <
typename T>
1214 RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<
typename internal::RemoveConst<T>::Type, Ch> >),(
const GenericValue&)) operator[](T* name)
const {
return const_cast<GenericValue&
>(*this)[name]; }
1225 template <
typename SourceAllocator>
1228 if (member != MemberEnd())
1229 return member->value;
1233#if RAPIDJSON_HAS_CXX11
1239#elif defined(_MSC_VER) && _MSC_VER < 1900
1242 __declspec(thread)
static char buffer[
sizeof(
GenericValue)];
1244#elif defined(__GNUC__) || defined(__clang__)
1257 template <
typename SourceAllocator>
1260#if RAPIDJSON_HAS_STDSTRING
1262 GenericValue& operator[](
const std::basic_string<Ch>& name) {
return (*
this)[GenericValue(StringRef(name))]; }
1263 const GenericValue& operator[](
const std::basic_string<Ch>& name)
const {
return (*
this)[GenericValue(
StringRef(name))]; }
1287 DoReserveMembers(newCapacity, allocator);
1299 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
1301#if RAPIDJSON_HAS_STDSTRING
1310 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1322 template <
typename SourceAllocator>
1339 return FindMember(n);
1342 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1357 template <
typename SourceAllocator>
1361 return DoFindMember(name);
1365#if RAPIDJSON_HAS_STDSTRING
1373 MemberIterator FindMember(
const std::basic_string<Ch>& name) {
return FindMember(GenericValue(StringRef(name))); }
1374 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(GenericValue(
StringRef(name))); }
1390 DoAddMember(name, value, allocator);
1405 return AddMember(name, v, allocator);
1408#if RAPIDJSON_HAS_STDSTRING
1420 return AddMember(name, v, allocator);
1441 template <
typename T>
1442 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (GenericValue&))
1445 return AddMember(name, v, allocator);
1448#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1450 return AddMember(name, value, allocator);
1452 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1453 return AddMember(name, value, allocator);
1455 GenericValue& AddMember(GenericValue& name, GenericValue&& value,
Allocator& allocator) {
1456 return AddMember(name, value, allocator);
1458 GenericValue& AddMember(StringRefType name, GenericValue&& value,
Allocator& allocator) {
1459 GenericValue n(name);
1460 return AddMember(n, value, allocator);
1477 return AddMember(n, value, allocator);
1491 return AddMember(name, v, allocator);
1511 template <
typename T>
1512 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1515 return AddMember(n, value, allocator);
1537 return RemoveMember(n);
1540#if RAPIDJSON_HAS_STDSTRING
1541 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1544 template <
typename SourceAllocator>
1545 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1546 MemberIterator m = FindMember(name);
1547 if (m != MemberEnd()) {
1568 return DoRemoveMember(m);
1581 return EraseMember(pos, pos +1);
1600 return DoEraseMembers(first, last);
1610 return EraseMember(n);
1613#if RAPIDJSON_HAS_STDSTRING
1614 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1617 template <
typename SourceAllocator>
1618 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1619 MemberIterator m = FindMember(name);
1620 if (m != MemberEnd()) {
1630 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1631 ConstObject GetObj()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1671 return GetElementsPointer()[index];
1696 if (newCapacity > data_.a.capacity) {
1698 data_.a.capacity = newCapacity;
1715 if (data_.a.size >= data_.a.capacity)
1716 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1717 GetElementsPointer()[data_.a.size++].RawAssign(value);
1721#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1723 return PushBack(value, allocator);
1737 return (*this).template PushBack<StringRefType>(value, allocator);
1757 template <
typename T>
1758 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1761 return PushBack(v, allocator);
1771 GetElementsPointer()[--data_.a.size].~GenericValue();
1783 return Erase(pos, pos + 1);
1804 std::memmove(
static_cast<void*
>(pos), last,
static_cast<size_t>(End() - last) *
sizeof(
GenericValue));
1805 data_.a.size -=
static_cast<SizeType>(last - first);
1810 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1817 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1818 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1819 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1820 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1827 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1828 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1829 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1830 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1831 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1838 return static_cast<float>(GetDouble());
1842 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1843 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1844 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1845 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1846 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(
static_cast<double>(f));
return *
this; }
1853 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return DataString(data_); }
1903#if RAPIDJSON_HAS_STDSTRING
1923 template <
typename T>
1924 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1926 template <
typename T>
1927 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1929 template <
typename T>
1930 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1932 template<
typename T>
1933 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1935 template<
typename T>
1936 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1947 template <
typename Handler>
1952 case kTrueType:
return handler.Bool(
true);
1959 if (
RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1964 return handler.EndObject(data_.o.size);
1972 return handler.EndArray(data_.a.size);
1975 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1979 if (IsDouble())
return handler.Double(data_.n.d);
1980 else if (IsInt())
return handler.Int(data_.n.i.i);
1981 else if (IsUint())
return handler.Uint(data_.n.u.u);
1982 else if (IsInt64())
return handler.Int64(data_.n.i64);
1983 else return handler.Uint64(data_.n.u64);
1988 template <
typename,
typename>
friend class GenericValue;
1993 kNumberFlag = 0x0010,
1996 kInt64Flag = 0x0080,
1997 kUint64Flag = 0x0100,
1998 kDoubleFlag = 0x0200,
1999 kStringFlag = 0x0400,
2001 kInlineStrFlag = 0x1000,
2006 kTrueFlag =
static_cast<int>(
kTrueType) |
static_cast<int>(kBoolFlag),
2007 kFalseFlag =
static_cast<int>(
kFalseType) |
static_cast<int>(kBoolFlag),
2008 kNumberIntFlag =
static_cast<int>(
kNumberType) |
static_cast<int>(kNumberFlag | kIntFlag | kInt64Flag),
2009 kNumberUintFlag =
static_cast<int>(
kNumberType) |
static_cast<int>(kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag),
2010 kNumberInt64Flag =
static_cast<int>(
kNumberType) |
static_cast<int>(kNumberFlag | kInt64Flag),
2011 kNumberUint64Flag =
static_cast<int>(
kNumberType) |
static_cast<int>(kNumberFlag | kUint64Flag),
2012 kNumberDoubleFlag =
static_cast<int>(
kNumberType) |
static_cast<int>(kNumberFlag | kDoubleFlag),
2013 kNumberAnyFlag =
static_cast<int>(
kNumberType) |
static_cast<int>(kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag),
2014 kConstStringFlag =
static_cast<int>(
kStringType) |
static_cast<int>(kStringFlag),
2015 kCopyStringFlag =
static_cast<int>(
kStringType) |
static_cast<int>(kStringFlag | kCopyFlag),
2016 kShortStringFlag =
static_cast<int>(
kStringType) |
static_cast<int>(kStringFlag | kCopyFlag | kInlineStrFlag),
2027#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
2028 char payload[
sizeof(SizeType) * 2 + 6];
2029#elif RAPIDJSON_64BIT
2030 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 6];
2032 char payload[
sizeof(SizeType) * 2 +
sizeof(
void*) + 2];
2051 struct ShortString {
2052 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
2055 inline static bool Usable(SizeType len) {
return (MaxSize >= len); }
2056 inline void SetLength(SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
2057 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
2062#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
2095 GenericValue* elements;
2107 static RAPIDJSON_FORCEINLINE
const Ch* DataString(
const Data& data) {
2108 return (data.f.flags & kInlineStrFlag) ? data.ss.str : RAPIDJSON_GETPOINTER(Ch, data.s.str);
2110 static RAPIDJSON_FORCEINLINE
SizeType DataStringLength(
const Data& data) {
2111 return (data.f.flags & kInlineStrFlag) ? data.ss.GetLength() : data.s.length;
2114 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
2115 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
2116 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
2117 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
2118 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
2119 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
2121#if RAPIDJSON_USE_MEMBERSMAP
2125 bool operator()(
const Data& s1,
const Data& s2)
const {
2126 SizeType n1 = DataStringLength(s1), n2 = DataStringLength(s2);
2127 int cmp = std::memcmp(DataString(s1), DataString(s2),
sizeof(Ch) * (n1 < n2 ? n1 : n2));
2128 return cmp < 0 || (cmp == 0 && n1 < n2);
2131 typedef std::pair<const Data, SizeType> Pair;
2132 typedef std::multimap<Data, SizeType, Less, StdAllocator<Pair, Allocator> > Map;
2133 typedef typename Map::iterator Iterator;
2135 typedef typename MapTraits::Map Map;
2136 typedef typename MapTraits::Less MapLess;
2137 typedef typename MapTraits::Pair MapPair;
2138 typedef typename MapTraits::Iterator MapIterator;
2148 static RAPIDJSON_FORCEINLINE
size_t GetMapLayoutSize(SizeType capacity) {
2152 capacity *
sizeof(MapIterator);
2155 static RAPIDJSON_FORCEINLINE
SizeType &GetMapCapacity(Map* &map) {
2156 return *
reinterpret_cast<SizeType*
>(
reinterpret_cast<uintptr_t
>(&map) +
2160 static RAPIDJSON_FORCEINLINE Member* GetMapMembers(Map* &map) {
2161 return reinterpret_cast<Member*
>(
reinterpret_cast<uintptr_t
>(&map) +
2166 static RAPIDJSON_FORCEINLINE MapIterator* GetMapIterators(Map* &map) {
2167 return reinterpret_cast<MapIterator*
>(
reinterpret_cast<uintptr_t
>(&map) +
2173 static RAPIDJSON_FORCEINLINE Map* &GetMap(Member* members) {
2175 return *
reinterpret_cast<Map**
>(
reinterpret_cast<uintptr_t
>(members) -
2181 RAPIDJSON_FORCEINLINE MapIterator DropMapIterator(MapIterator& rhs) {
2182#if RAPIDJSON_HAS_CXX11
2183 MapIterator ret = std::move(rhs);
2185 MapIterator ret = rhs;
2191 Map* &DoReallocMap(Map** oldMap, SizeType newCapacity,
Allocator& allocator) {
2192 Map **newMap =
static_cast<Map**
>(allocator.Malloc(GetMapLayoutSize(newCapacity)));
2193 GetMapCapacity(*newMap) = newCapacity;
2195 *newMap =
new (allocator.Malloc(
sizeof(Map))) Map(MapLess(), allocator);
2199 size_t count = (*oldMap)->size();
2200 std::memcpy(
static_cast<void*
>(GetMapMembers(*newMap)),
2201 static_cast<void*
>(GetMapMembers(*oldMap)),
2202 count *
sizeof(Member));
2203 MapIterator *oldIt = GetMapIterators(*oldMap),
2204 *newIt = GetMapIterators(*newMap);
2206 new (&newIt[count]) MapIterator(DropMapIterator(oldIt[count]));
2208 Allocator::Free(oldMap);
2213 RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity,
Allocator& allocator) {
2214 return GetMapMembers(DoReallocMap(0, capacity, allocator));
2217 void DoReserveMembers(SizeType newCapacity,
Allocator& allocator) {
2218 ObjectData& o = data_.o;
2219 if (newCapacity > o.capacity) {
2220 Member* oldMembers = GetMembersPointer();
2221 Map **oldMap = oldMembers ? &GetMap(oldMembers) : 0,
2222 *&newMap = DoReallocMap(oldMap, newCapacity, allocator);
2223 RAPIDJSON_SETPOINTER(Member, o.members, GetMapMembers(newMap));
2224 o.capacity = newCapacity;
2228 template <
typename SourceAllocator>
2229 MemberIterator DoFindMember(
const GenericValue<Encoding, SourceAllocator>& name) {
2230 if (Member* members = GetMembersPointer()) {
2231 Map* &map = GetMap(members);
2232 MapIterator mit = map->find(
reinterpret_cast<const Data&
>(name.data_));
2233 if (mit != map->end()) {
2234 return MemberIterator(&members[mit->second]);
2240 void DoClearMembers() {
2241 if (Member* members = GetMembersPointer()) {
2242 Map* &map = GetMap(members);
2243 MapIterator* mit = GetMapIterators(map);
2244 for (SizeType i = 0; i < data_.o.size; i++) {
2245 map->erase(DropMapIterator(mit[i]));
2246 members[i].~Member();
2252 void DoFreeMembers() {
2253 if (Member* members = GetMembersPointer()) {
2254 GetMap(members)->~Map();
2255 for (SizeType i = 0; i < data_.o.size; i++) {
2256 members[i].~Member();
2258 if (Allocator::kNeedFree) {
2259 Map** map = &GetMap(members);
2260 Allocator::Free(*map);
2261 Allocator::Free(map);
2268 RAPIDJSON_FORCEINLINE Member* DoAllocMembers(SizeType capacity,
Allocator& allocator) {
2269 return Malloc<Member>(allocator, capacity);
2272 void DoReserveMembers(SizeType newCapacity,
Allocator& allocator) {
2273 ObjectData& o = data_.o;
2274 if (newCapacity > o.capacity) {
2275 Member* newMembers = Realloc<Member>(allocator, GetMembersPointer(), o.capacity, newCapacity);
2276 RAPIDJSON_SETPOINTER(Member, o.members, newMembers);
2277 o.capacity = newCapacity;
2281 template <
typename SourceAllocator>
2282 MemberIterator DoFindMember(
const GenericValue<Encoding, SourceAllocator>& name) {
2283 MemberIterator member = MemberBegin();
2284 for ( ; member != MemberEnd(); ++member)
2285 if (name.StringEqual(member->name))
2290 void DoClearMembers() {
2291 for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
2296 void DoFreeMembers() {
2297 for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
2299 Allocator::Free(GetMembersPointer());
2304 void DoAddMember(GenericValue& name, GenericValue& value,
Allocator& allocator) {
2305 ObjectData& o = data_.o;
2306 if (o.size >= o.capacity)
2307 DoReserveMembers(o.capacity ? (o.capacity + (o.capacity + 1) / 2) : kDefaultObjectCapacity, allocator);
2308 Member* members = GetMembersPointer();
2309 Member* m = members + o.size;
2310 m->name.RawAssign(name);
2311 m->value.RawAssign(value);
2312#if RAPIDJSON_USE_MEMBERSMAP
2313 Map* &map = GetMap(members);
2314 MapIterator* mit = GetMapIterators(map);
2315 new (&mit[o.size]) MapIterator(map->insert(MapPair(m->name.data_, o.size)));
2320 MemberIterator DoRemoveMember(MemberIterator m) {
2321 ObjectData& o = data_.o;
2322 Member* members = GetMembersPointer();
2323#if RAPIDJSON_USE_MEMBERSMAP
2324 Map* &map = GetMap(members);
2325 MapIterator* mit = GetMapIterators(map);
2327 map->erase(DropMapIterator(mit[mpos]));
2329 MemberIterator last(members + (o.size - 1));
2330 if (o.size > 1 && m != last) {
2331#if RAPIDJSON_USE_MEMBERSMAP
2332 new (&mit[mpos]) MapIterator(DropMapIterator(mit[&*last - members]));
2333 mit[mpos]->second = mpos;
2344 MemberIterator DoEraseMembers(ConstMemberIterator first, ConstMemberIterator last) {
2345 ObjectData& o = data_.o;
2346 MemberIterator beg = MemberBegin(),
2347 pos = beg + (first - beg),
2349#if RAPIDJSON_USE_MEMBERSMAP
2350 Map* &map = GetMap(GetMembersPointer());
2351 MapIterator* mit = GetMapIterators(map);
2353 for (MemberIterator itr = pos; itr != last; ++itr) {
2354#if RAPIDJSON_USE_MEMBERSMAP
2355 map->erase(DropMapIterator(mit[itr - beg]));
2359#if RAPIDJSON_USE_MEMBERSMAP
2360 if (first != last) {
2362 MemberIterator next = pos + (last - first);
2363 for (MemberIterator itr = pos; next != end; ++itr, ++next) {
2364 std::memcpy(
static_cast<void*
>(&*itr), &*next,
sizeof(Member));
2366 new (&mit[mpos]) MapIterator(DropMapIterator(mit[next - beg]));
2367 mit[mpos]->second = mpos;
2371 std::memmove(
static_cast<void*
>(&*pos), &*last,
2372 static_cast<size_t>(end - last) *
sizeof(Member));
2374 o.size -=
static_cast<SizeType>(last - first);
2378 template <
typename SourceAllocator>
2379 void DoCopyMembers(
const GenericValue<Encoding,SourceAllocator>& rhs,
Allocator& allocator,
bool copyConstStrings) {
2382 data_.f.flags = kObjectFlag;
2384 Member* lm = DoAllocMembers(count, allocator);
2385 const typename GenericValue<Encoding,SourceAllocator>::Member* rm = rhs.GetMembersPointer();
2386#if RAPIDJSON_USE_MEMBERSMAP
2387 Map* &map = GetMap(lm);
2388 MapIterator* mit = GetMapIterators(map);
2390 for (SizeType i = 0; i < count; i++) {
2391 new (&lm[i].name) GenericValue(rm[i].name, allocator, copyConstStrings);
2392 new (&lm[i].value) GenericValue(rm[i].value, allocator, copyConstStrings);
2393#if RAPIDJSON_USE_MEMBERSMAP
2394 new (&mit[i]) MapIterator(map->insert(MapPair(lm[i].name.data_, i)));
2397 data_.o.size = data_.o.capacity = count;
2398 SetMembersPointer(lm);
2402 void SetArrayRaw(GenericValue* values, SizeType count,
Allocator& allocator) {
2403 data_.f.flags = kArrayFlag;
2405 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
2406 SetElementsPointer(e);
2407 std::memcpy(
static_cast<void*
>(e), values, count *
sizeof(GenericValue));
2410 SetElementsPointer(0);
2411 data_.a.size = data_.a.capacity = count;
2415 void SetObjectRaw(Member* members, SizeType count,
Allocator& allocator) {
2416 data_.f.flags = kObjectFlag;
2418 Member* m = DoAllocMembers(count, allocator);
2419 SetMembersPointer(m);
2420 std::memcpy(
static_cast<void*
>(m), members, count *
sizeof(Member));
2421#if RAPIDJSON_USE_MEMBERSMAP
2422 Map* &map = GetMap(m);
2423 MapIterator* mit = GetMapIterators(map);
2424 for (SizeType i = 0; i < count; i++) {
2425 new (&mit[i]) MapIterator(map->insert(MapPair(m[i].name.data_, i)));
2430 SetMembersPointer(0);
2431 data_.o.size = data_.o.capacity = count;
2435 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2436 data_.f.flags = kConstStringFlag;
2437 SetStringPointer(s);
2438 data_.s.length = s.length;
2442 void SetStringRaw(StringRefType s,
Allocator& allocator) {
2444 if (ShortString::Usable(s.length)) {
2445 data_.f.flags = kShortStringFlag;
2446 data_.ss.SetLength(s.length);
2449 data_.f.flags = kCopyStringFlag;
2450 data_.s.length = s.length;
2451 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
2452 SetStringPointer(str);
2454 std::memcpy(str, s, s.length *
sizeof(Ch));
2455 str[s.length] =
'\0';
2459 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2462 rhs.data_.f.flags = kNullFlag;
2465 template <
typename SourceAllocator>
2466 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
2470 const SizeType len1 = GetStringLength();
2471 const SizeType len2 = rhs.GetStringLength();
2472 if(len1 != len2) {
return false; }
2474 const Ch*
const str1 = GetString();
2475 const Ch*
const str2 = rhs.GetString();
2476 if(str1 == str2) {
return true; }
2478 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2498template <
typename Encoding,
typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR,
typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR >
2501 typedef typename Encoding::Ch
Ch;
2527 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2533#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2536 : ValueType(std::forward<ValueType>(rhs)),
2537 allocator_(rhs.allocator_),
2538 ownAllocator_(rhs.ownAllocator_),
2539 stack_(std::move(rhs.stack_)),
2540 parseResult_(rhs.parseResult_)
2543 rhs.ownAllocator_ = 0;
2548 ~GenericDocument() {
2553 if (ownAllocator_) {
2554 ValueType::SetNull();
2559#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2561 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2565 ValueType::operator=(std::forward<ValueType>(rhs));
2570 allocator_ = rhs.allocator_;
2571 ownAllocator_ = rhs.ownAllocator_;
2572 stack_ = std::move(rhs.stack_);
2573 parseResult_ = rhs.parseResult_;
2576 rhs.ownAllocator_ = 0;
2577 rhs.parseResult_ = ParseResult();
2590 ValueType::Swap(rhs);
2591 stack_.Swap(rhs.stack_);
2592 internal::Swap(allocator_, rhs.allocator_);
2593 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2594 internal::Swap(parseResult_, rhs.parseResult_);
2600 using ValueType::Swap;
2621 template <
typename Generator>
2623 ClearStackOnExit scope(*
this);
2626 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2641 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2644 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2645 ClearStackOnExit scope(*
this);
2646 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
2649 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2660 template <
unsigned parseFlags,
typename InputStream>
2662 return ParseStream<parseFlags, Encoding, InputStream>(is);
2670 template <
typename InputStream>
2672 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2684 template <
unsigned parseFlags>
2687 return ParseStream<parseFlags | kParseInsituFlag>(s);
2695 return ParseInsitu<kParseDefaultFlags>(str);
2707 template <
unsigned parseFlags,
typename SourceEncoding>
2711 return ParseStream<parseFlags, SourceEncoding>(s);
2718 template <
unsigned parseFlags>
2720 return Parse<parseFlags, Encoding>(str);
2727 return Parse<kParseDefaultFlags>(str);
2730 template <
unsigned parseFlags,
typename SourceEncoding>
2731 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2733 MemoryStream ms(
reinterpret_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2735 ParseStream<parseFlags, SourceEncoding>(is);
2739 template <
unsigned parseFlags>
2740 GenericDocument& Parse(
const Ch* str,
size_t length) {
2741 return Parse<parseFlags, Encoding>(str, length);
2744 GenericDocument& Parse(
const Ch* str,
size_t length) {
2745 return Parse<kParseDefaultFlags>(str, length);
2748#if RAPIDJSON_HAS_STDSTRING
2749 template <
unsigned parseFlags,
typename SourceEncoding>
2750 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2752 return Parse<parseFlags, SourceEncoding>(str.c_str());
2755 template <
unsigned parseFlags>
2756 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2757 return Parse<parseFlags, Encoding>(str.c_str());
2760 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2761 return Parse<kParseDefaultFlags>(str);
2805 struct ClearStackOnExit {
2807 ~ClearStackOnExit() { d_.ClearStack(); }
2809 ClearStackOnExit(
const ClearStackOnExit&);
2810 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2811 GenericDocument& d_;
2816 template <
typename,
typename>
friend class GenericValue;
2820 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2821 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2822 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2823 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2824 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2825 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2826 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2828 bool RawNumber(
const Ch* str, SizeType length,
bool copy) {
2830 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2832 new (stack_.template Push<ValueType>()) ValueType(str, length);
2836 bool String(
const Ch* str, SizeType length,
bool copy) {
2838 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2840 new (stack_.template Push<ValueType>()) ValueType(str, length);
2844 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(kObjectType);
return true; }
2846 bool Key(
const Ch* str, SizeType length,
bool copy) {
return String(str, length, copy); }
2848 bool EndObject(SizeType memberCount) {
2849 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2850 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2854 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(kArrayType);
return true; }
2856 bool EndArray(SizeType elementCount) {
2857 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2858 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2864 GenericDocument(
const GenericDocument&);
2866 GenericDocument& operator=(
const GenericDocument&);
2869 if (Allocator::kNeedFree)
2870 while (stack_.GetSize() > 0)
2871 (stack_.template Pop<ValueType>(1))->~ValueType();
2874 stack_.ShrinkToFit();
2881 static const size_t kDefaultStackCapacity = 1024;
2884 internal::Stack<StackAllocator> stack_;
2885 ParseResult parseResult_;
2897template <
bool Const,
typename ValueT>
2902 typedef ValueT PlainType;
2903 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2904 typedef ValueType* ValueIterator;
2905 typedef const ValueT* ConstValueIterator;
2906 typedef typename ValueType::AllocatorType AllocatorType;
2907 typedef typename ValueType::StringRefType StringRefType;
2909 template <
typename,
typename>
2916 operator ValueType&()
const {
return value_; }
2917 SizeType Size()
const {
return value_.Size(); }
2918 SizeType Capacity()
const {
return value_.Capacity(); }
2919 bool Empty()
const {
return value_.Empty(); }
2920 void Clear()
const { value_.Clear(); }
2921 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2922 ValueIterator Begin()
const {
return value_.Begin(); }
2923 ValueIterator End()
const {
return value_.End(); }
2924 GenericArray Reserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.Reserve(newCapacity, allocator);
return *
this; }
2925 GenericArray PushBack(ValueType& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2926#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2927 GenericArray PushBack(ValueType&& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2929 GenericArray PushBack(StringRefType value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2930 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; }
2931 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2932 ValueIterator Erase(ConstValueIterator pos)
const {
return value_.Erase(pos); }
2933 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
const {
return value_.Erase(first, last); }
2935#if RAPIDJSON_HAS_CXX11_RANGE_FOR
2936 ValueIterator begin()
const {
return value_.Begin(); }
2937 ValueIterator end()
const {
return value_.End(); }
2951template <
bool Const,
typename ValueT>
2956 typedef ValueT PlainType;
2957 typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
2960 typedef typename ValueType::AllocatorType AllocatorType;
2961 typedef typename ValueType::StringRefType StringRefType;
2962 typedef typename ValueType::EncodingType EncodingType;
2963 typedef typename ValueType::Ch Ch;
2965 template <
typename,
typename>
2972 operator ValueType&()
const {
return value_; }
2973 SizeType MemberCount()
const {
return value_.MemberCount(); }
2974 SizeType MemberCapacity()
const {
return value_.MemberCapacity(); }
2975 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2976 template <
typename T> ValueType& operator[](T* name)
const {
return value_[name]; }
2978#if RAPIDJSON_HAS_STDSTRING
2979 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2981 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2983 GenericObject MemberReserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.MemberReserve(newCapacity, allocator);
return *
this; }
2984 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2985#if RAPIDJSON_HAS_STDSTRING
2986 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2989 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2991#if RAPIDJSON_HAS_STDSTRING
2992 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2994 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2995 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2996#if RAPIDJSON_HAS_STDSTRING
2997 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2999 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; }
3000#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
3001 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
3002 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
3003 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
3004 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
3006 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
3007 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
3008 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; }
3009 void RemoveAllMembers() { value_.RemoveAllMembers(); }
3010 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
3011#if RAPIDJSON_HAS_STDSTRING
3012 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
3018 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
3019#if RAPIDJSON_HAS_STDSTRING
3020 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
3024#if RAPIDJSON_HAS_CXX11_RANGE_FOR
3035RAPIDJSON_NAMESPACE_END
3038#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
3039#pragma pop_macro("GetObject")
3040#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
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:2898
A document for parsing JSON text as DOM.
Definition document.h:2499
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition document.h:2622
Allocator & GetAllocator()
Get the allocator of this document.
Definition document.h:2795
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition document.h:2694
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:2614
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition document.h:2801
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream
Definition document.h:2661
StackAllocator StackAllocatorType
StackAllocator type from template parameter.
Definition document.h:2504
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition document.h:2502
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:2503
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition document.h:2642
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition document.h:2771
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor
Definition document.h:2526
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:2501
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition document.h:2671
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor
Definition document.h:2513
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2708
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition document.h:2774
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition document.h:2589
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string
Definition document.h:2685
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition document.h:2726
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition document.h:2777
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string
Definition document.h:2719
Name-value pair in a JSON object value.
Definition document.h:120
GenericMember & operator=(GenericMember &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition document.h:142
GenericValue< Encoding, Allocator > value
value of member.
Definition document.h:123
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition document.h:122
(Constant) member iterator for a JSON object value
Definition document.h:186
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type
Definition document.h:200
GenericMemberIterator Iterator
Iterator type itself
Definition document.h:196
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type
Definition document.h:198
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const
Definition document.h:240
pointer Pointer
Pointer to (const) GenericMember
Definition document.h:212
reference Reference
Reference to (const) GenericMember
Definition document.h:214
DifferenceType operator-(ConstIterator that) const
Distance
Definition document.h:282
GenericMemberIterator()
Default constructor (singular value)
Definition document.h:222
difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition document.h:216
Helper class for accessing Value of object type.
Definition document.h:2952
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition pointer.h:68
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition reader.h:539
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition document.h:668
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition document.h:671
Encoding EncodingType
Encoding type from template parameter.
Definition document.h:672
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1893
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition document.h:678
ConstValueIterator Begin() const
Constant element iterator
Definition document.h:1683
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition document.h:946
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition document.h:1593
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition document.h:1580
GenericValue & SetObject()
Set this value as an empty object.
Definition document.h:1188
SizeType GetStringLength() const
Get the length of string.
Definition document.h:1858
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition document.h:819
bool ObjectEmpty() const
Check whether the object is empty.
Definition document.h:1197
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition document.h:1875
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator
Definition document.h:1271
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition document.h:921
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics
Definition document.h:1014
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition document.h:1713
~GenericValue()
Destructor.
Definition document.h:880
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition document.h:1387
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition document.h:798
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition document.h:1694
GenericValue & SetArray()
Set this value as an empty array.
Definition document.h:1640
GenericValue & PopBack()
Remove the last element in the array.
Definition document.h:1768
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:837
GenericStringRef< Ch > StringRefType
Reference to a constant string
Definition document.h:675
float GetFloat() const
Get the value as float type.
Definition document.h:1837
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:1010
Allocator AllocatorType
Allocator type from template parameter.
Definition document.h:673
GenericValue & SetBool(bool b)
Definition document.h:1179
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition document.h:990
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition document.h:1489
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer
Definition document.h:1089
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition document.h:720
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition document.h:840
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition document.h:1782
void RemoveAllMembers()
Remove all members in the object.
Definition document.h:1522
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition document.h:1475
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition document.h:677
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition document.h:831
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition document.h:861
bool GetBool() const
Set boolean value
Definition document.h:1176
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition document.h:1323
SizeType Size() const
Get the number of elements in array.
Definition document.h:1643
SizeType Capacity() const
Get the capacity of array.
Definition document.h:1646
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:846
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition document.h:872
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition document.h:679
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition document.h:1226
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition document.h:1736
SizeType MemberCount() const
Get the number of members in the object.
Definition document.h:1191
ValueIterator Begin()
Element iterator
Definition document.h:1677
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition document.h:1358
GenericValue & MemberReserve(SizeType newCapacity, Allocator &allocator)
Request the object to have enough capacity to store members.
Definition document.h:1285
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition document.h:1794
MemberIterator MemberBegin()
Member iterator
Definition document.h:1274
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Deep-copy assignment from Value
Definition document.h:978
double GetDouble() const
Get the value as double type.
Definition document.h:1825
void Clear()
Remove all elements in the array.
Definition document.h:1655
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition document.h:1535
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition document.h:1299
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition document.h:1099
bool operator==(const T &rhs) const
Equal-to operator with primitive types
Definition document.h:1079
ValueIterator End()
Past-the-end element iterator
Definition document.h:1680
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator
Definition document.h:1025
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition document.h:1868
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition document.h:783
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition document.h:792
ConstValueIterator End() const
Constant past-the-end element iterator
Definition document.h:1686
bool EraseMember(const Ch *name)
Erase a member in object by its name.
Definition document.h:1608
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition document.h:1209
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition document.h:1668
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition document.h:676
bool Is() const
Templated version for checking whether this value is type T.
Definition document.h:1924
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition document.h:804
bool Empty() const
Check whether the array is empty.
Definition document.h:1649
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition document.h:690
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition document.h:1337
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition document.h:680
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition document.h:1948
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator
Definition document.h:1086
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1885
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition document.h:843
MemberIterator MemberEnd()
Past-the-end member iterator
Definition document.h:1277
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition document.h:742
Encoding::Ch Ch
Character type derived from Encoding.
Definition document.h:674
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition document.h:1104
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types
Definition document.h:1094
ConstMemberIterator MemberBegin() const
Const member iterator
Definition document.h:1268
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition document.h:1403
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer
Definition document.h:1067
SizeType MemberCapacity() const
Get the capacity of object.
Definition document.h:1194
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition document.h:1563
GenericValue & SetString(StringRefType s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition document.h:1901
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition document.h:834
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
#define RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY
User defined kDefaultArrayCapacity value.
Definition document.h:110
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
Assertion (in non-throwing contexts).
Definition rapidjson.h:687
#define RAPIDJSON_ALIGN(x)
Data alignment of the machine.
Definition rapidjson.h:307
#define RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY
User defined kDefaultObjectCapacity value.
Definition document.h:99
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition rapidjson.h:494
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:507
#define RAPIDJSON_USE_MEMBERSMAP
Enable RapidJSON support for object members handling in a std::multimap
Definition rapidjson.h:180
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:437
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:415
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition reader.h:148
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string
Definition document.h:454
Type
Type of JSON value
Definition rapidjson.h:729
@ kArrayType
array
Definition rapidjson.h:734
@ kTrueType
true
Definition rapidjson.h:732
@ kNullType
null
Definition rapidjson.h:730
@ kFalseType
false
Definition rapidjson.h:731
@ kNumberType
number
Definition rapidjson.h:736
@ kObjectType
object
Definition rapidjson.h:733
@ kStringType
string
Definition rapidjson.h:735
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition rapidjson.h:716
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:320
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition rapidjson.h:712
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition rapidjson.h:476
A read-write string stream.
Definition stream.h:188
Reference to a constant string (not taking a copy)
Definition document.h:346
const Ch *const s
plain CharType pointer
Definition document.h:419
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer
Definition document.h:399
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string
Definition document.h:474
CharType Ch
character type of the string
Definition document.h:347
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string
Definition document.h:454
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array
Definition document.h:375
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length
Definition document.h:411
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition document.h:420
Read-only string stream.
Definition stream.h:154
Definition document.h:2063
Definition document.h:2067
Represents an in-memory input byte stream.
Definition memorystream.h:40