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"
30 RAPIDJSON_DIAG_OFF(4127)
31 RAPIDJSON_DIAG_OFF(4244)
35 RAPIDJSON_DIAG_OFF(padded)
36 RAPIDJSON_DIAG_OFF(
switch-
enum)
37 RAPIDJSON_DIAG_OFF(c++98-compat)
41 RAPIDJSON_DIAG_OFF(effc++)
43 RAPIDJSON_DIAG_OFF(terminate)
47 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
51 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
55 RAPIDJSON_NAMESPACE_BEGIN
58 template <
typename Encoding,
typename Allocator>
61 template <
typename Encoding,
typename Allocator,
typename StackAllocator>
62 class GenericDocument;
70 template <
typename Encoding,
typename Allocator>
79 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
100 template <
bool Const,
typename Encoding,
typename Allocator>
102 :
public std::iterator<std::random_access_iterator_tag
103 , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
110 typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
150 Iterator& operator=(
const NonConstIterator & it) { ptr_ = it.ptr_;
return *
this; }
154 Iterator& operator++(){ ++ptr_;
return *
this; }
155 Iterator& operator--(){ --ptr_;
return *
this; }
156 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
157 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
162 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
163 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
165 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
166 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
171 bool operator==(ConstIterator that)
const {
return ptr_ == that.ptr_; }
172 bool operator!=(ConstIterator that)
const {
return ptr_ != that.ptr_; }
173 bool operator<=(ConstIterator that)
const {
return ptr_ <= that.ptr_; }
174 bool operator>=(ConstIterator that)
const {
return ptr_ >= that.ptr_; }
175 bool operator< (ConstIterator that)
const {
return ptr_ < that.ptr_; }
176 bool operator> (ConstIterator that)
const {
return ptr_ > that.ptr_; }
181 Reference operator*()
const {
return *ptr_; }
182 Pointer operator->()
const {
return ptr_; }
183 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
200 template <
bool Const,
typename Encoding,
typename Allocator>
201 struct GenericMemberIterator;
204 template <
typename Encoding,
typename Allocator>
207 typedef GenericMember<Encoding,Allocator>* Iterator;
210 template <
typename Encoding,
typename Allocator>
213 typedef const GenericMember<Encoding,Allocator>* Iterator;
248 template<
typename CharType>
279 : s(str), length(N-1) {}
319 GenericStringRef& operator=(
const GenericStringRef& rhs) { s = rhs.s; length = rhs.length; }
322 operator const Ch *()
const {
return s; }
345 template<
typename CharType>
365 template<
typename CharType>
370 #if RAPIDJSON_HAS_STDSTRING
383 template<
typename CharType>
393 template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
394 struct IsGenericValueImpl : FalseType {};
397 template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>
::Type, typename Void<typename T::AllocatorType>
::Type>
398 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>
::Type {};
401 template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>
::Type {};
410 template <
typename ValueType,
typename T>
411 struct TypeHelper {};
413 template<
typename ValueType>
414 struct TypeHelper<ValueType, bool> {
415 static bool Is(
const ValueType& v) {
return v.IsBool(); }
416 static bool Get(
const ValueType& v) {
return v.GetBool(); }
417 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
418 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
421 template<
typename ValueType>
422 struct TypeHelper<ValueType, int> {
423 static bool Is(
const ValueType& v) {
return v.IsInt(); }
424 static int Get(
const ValueType& v) {
return v.GetInt(); }
425 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
426 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
429 template<
typename ValueType>
430 struct TypeHelper<ValueType, unsigned> {
431 static bool Is(
const ValueType& v) {
return v.IsUint(); }
432 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
433 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
434 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
437 template<
typename ValueType>
438 struct TypeHelper<ValueType, int64_t> {
439 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
440 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
441 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
442 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
445 template<
typename ValueType>
446 struct TypeHelper<ValueType, uint64_t> {
447 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
448 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
449 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
450 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
453 template<
typename ValueType>
454 struct TypeHelper<ValueType, double> {
455 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
456 static double Get(
const ValueType& v) {
return v.GetDouble(); }
457 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
458 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
461 template<
typename ValueType>
462 struct TypeHelper<ValueType, float> {
463 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
464 static float Get(
const ValueType& v) {
return v.GetFloat(); }
465 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
466 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
469 template<
typename ValueType>
470 struct TypeHelper<ValueType, const typename ValueType::Ch*> {
471 typedef const typename ValueType::Ch* StringType;
472 static bool Is(
const ValueType& v) {
return v.IsString(); }
473 static StringType Get(
const ValueType& v) {
return v.GetString(); }
474 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
475 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
478 #if RAPIDJSON_HAS_STDSTRING
479 template<
typename ValueType>
480 struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
481 typedef std::basic_string<typename ValueType::Ch> StringType;
482 static bool Is(
const ValueType& v) {
return v.IsString(); }
483 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
484 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
488 template<
typename ValueType>
489 struct TypeHelper<ValueType, typename ValueType::Array> {
490 typedef typename ValueType::Array ArrayType;
491 static bool Is(
const ValueType& v) {
return v.IsArray(); }
492 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
493 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
494 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
497 template<
typename ValueType>
498 struct TypeHelper<ValueType, typename ValueType::ConstArray> {
499 typedef typename ValueType::ConstArray ArrayType;
500 static bool Is(
const ValueType& v) {
return v.IsArray(); }
501 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
504 template<
typename ValueType>
505 struct TypeHelper<ValueType, typename ValueType::Object> {
506 typedef typename ValueType::Object ObjectType;
507 static bool Is(
const ValueType& v) {
return v.IsObject(); }
508 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
509 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
510 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) { v = data; }
513 template<
typename ValueType>
514 struct TypeHelper<ValueType, typename ValueType::ConstObject> {
515 typedef typename ValueType::ConstObject ObjectType;
516 static bool Is(
const ValueType& v) {
return v.IsObject(); }
517 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
523 template <
bool,
typename>
class GenericArray;
524 template <
bool,
typename>
class GenericObject;
539 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
546 typedef typename Encoding::Ch
Ch;
562 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
564 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
567 rhs.data_.f.flags = kNullFlag;
573 GenericValue(
const GenericValue& rhs);
575 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
577 template <
typename StackAllocator>
578 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
581 template <
typename StackAllocator>
582 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
593 static const uint16_t defaultFlags[7] = {
594 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
598 data_.f.flags = defaultFlags[type];
602 data_.ss.SetLength(0);
612 template<
typename SourceAllocator >
621 #ifndef RAPIDJSON_DOXYGEN_RUNNING
622 template <
typename T>
623 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT
630 data_.f.flags = b ? kTrueFlag : kFalseFlag;
636 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
642 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
648 data_.f.flags = kNumberInt64Flag;
650 data_.f.flags |= kNumberUint64Flag;
652 data_.f.flags |= kUintFlag;
654 data_.f.flags |= kIntFlag;
657 data_.f.flags |= kIntFlag;
663 data_.f.flags = kNumberUint64Flag;
665 data_.f.flags |= kInt64Flag;
667 data_.f.flags |= kUintFlag;
669 data_.f.flags |= kIntFlag;
673 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
687 #if RAPIDJSON_HAS_STDSTRING
701 a.value_.data_ = Data();
702 a.value_.data_.f.flags = kArrayFlag;
712 o.value_.data_ = Data();
713 o.value_.data_.f.flags = kObjectFlag;
720 if (Allocator::kNeedFree) {
721 switch(data_.f.flags) {
734 Allocator::Free(GetMembersPointer());
737 case kCopyStringFlag:
738 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
762 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
765 return *
this = rhs.
Move();
791 template <
typename T>
792 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
804 template <
typename SourceAllocator>
806 RAPIDJSON_ASSERT(
static_cast<void*
>(
this) !=
static_cast<void const*
>(&rhs));
819 temp.RawAssign(*
this);
821 other.RawAssign(temp);
851 template <
typename SourceAllocator>
854 if (GetType() != rhs.GetType())
859 if (data_.o.size != rhs.data_.o.size)
861 for (
ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
862 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.
FindMember(lhsMemberItr->name);
863 if (rhsMemberItr == rhs.
MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
869 if (data_.a.size != rhs.data_.a.size)
871 for (
SizeType i = 0; i < data_.a.size; i++)
872 if ((*
this)[i] != rhs[i])
877 return StringEqual(rhs);
880 if (IsDouble() || rhs.IsDouble()) {
881 double a = GetDouble();
883 return a >= b && a <= b;
886 return data_.n.u64 == rhs.data_.n.u64;
896 #if RAPIDJSON_HAS_STDSTRING
906 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
911 template <
typename SourceAllocator>
920 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
925 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
930 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
936 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
937 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
938 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
939 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
940 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
941 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
942 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
943 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
944 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
945 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
946 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
947 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
948 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
949 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
952 bool IsLosslessDouble()
const {
953 if (!IsNumber())
return false;
955 uint64_t u = GetUint64();
956 volatile double d =
static_cast<double>(u);
958 && (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
959 && (u ==
static_cast<uint64_t
>(d));
962 int64_t i = GetInt64();
963 volatile double d =
static_cast<double>(i);
964 return (d >=
static_cast<double>(std::numeric_limits<int64_t>::min()))
965 && (d <
static_cast<double>(std::numeric_limits<int64_t>::max()))
966 && (i ==
static_cast<int64_t
>(d));
972 bool IsFloat()
const {
973 if ((data_.f.flags & kDoubleFlag) == 0)
975 double d = GetDouble();
976 return d >= -3.4028234e38 && d <= 3.4028234e38;
979 bool IsLosslessFloat()
const {
980 if (!IsNumber())
return false;
981 double a = GetDouble();
982 if (a <
static_cast<double>(-std::numeric_limits<float>::max())
983 || a >
static_cast<double>(std::numeric_limits<float>::max()))
985 double b =
static_cast<double>(
static_cast<float>(a));
986 return a >= b && a <= b;
994 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1030 template <
typename T>
1035 template <
typename T>
1047 template <
typename SourceAllocator>
1050 if (member != MemberEnd())
1051 return member->value;
1064 template <
typename SourceAllocator>
1067 #if RAPIDJSON_HAS_STDSTRING
1094 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
1096 #if RAPIDJSON_HAS_STDSTRING
1105 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1117 template <
typename SourceAllocator>
1134 return FindMember(n);
1137 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1152 template <
typename SourceAllocator>
1157 for ( ; member != MemberEnd(); ++member)
1158 if (name.StringEqual(member->name))
1164 #if RAPIDJSON_HAS_STDSTRING
1173 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(
GenericValue(
StringRef(name))); }
1190 ObjectData& o = data_.o;
1191 if (o.size >= o.capacity) {
1192 if (o.capacity == 0) {
1193 o.capacity = kDefaultObjectCapacity;
1194 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Malloc(o.capacity *
sizeof(
Member))));
1198 o.capacity += (oldCapacity + 1) / 2;
1199 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Realloc(GetMembersPointer(), oldCapacity *
sizeof(
Member), o.capacity *
sizeof(
Member))));
1202 Member* members = GetMembersPointer();
1203 members[o.size].
name.RawAssign(name);
1204 members[o.size].
value.RawAssign(value);
1220 return AddMember(name, v, allocator);
1223 #if RAPIDJSON_HAS_STDSTRING
1235 return AddMember(name, v, allocator);
1256 template <
typename T>
1257 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1260 return AddMember(name, v, allocator);
1263 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1265 return AddMember(name, value, allocator);
1267 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1268 return AddMember(name, value, allocator);
1270 GenericValue& AddMember(GenericValue& name, GenericValue&& value,
Allocator& allocator) {
1271 return AddMember(name, value, allocator);
1273 GenericValue& AddMember(StringRefType name, GenericValue&& value,
Allocator& allocator) {
1274 GenericValue n(name);
1275 return AddMember(n, value, allocator);
1292 return AddMember(n, value, allocator);
1306 return AddMember(name, v, allocator);
1326 template <
typename T>
1327 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1330 return AddMember(n, value, allocator);
1354 return RemoveMember(n);
1357 #if RAPIDJSON_HAS_STDSTRING
1358 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1361 template <
typename SourceAllocator>
1362 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1363 MemberIterator m = FindMember(name);
1364 if (m != MemberEnd()) {
1387 if (data_.o.size > 1 && m != last)
1405 return EraseMember(pos, pos +1);
1428 std::memmove(&*pos, &*last,
static_cast<size_t>(MemberEnd() - last) *
sizeof(
Member));
1429 data_.o.size -=
static_cast<SizeType>(last - first);
1440 return EraseMember(n);
1443 #if RAPIDJSON_HAS_STDSTRING
1444 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1447 template <
typename SourceAllocator>
1448 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1449 MemberIterator m = FindMember(name);
1450 if (m != MemberEnd()) {
1459 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1499 return GetElementsPointer()[index];
1524 if (newCapacity > data_.a.capacity) {
1526 data_.a.capacity = newCapacity;
1543 if (data_.a.size >= data_.a.capacity)
1544 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1545 GetElementsPointer()[data_.a.size++].RawAssign(value);
1549 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1551 return PushBack(value, allocator);
1565 return (*this).template PushBack<StringRefType>(value, allocator);
1585 template <
typename T>
1586 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1589 return PushBack(v, allocator);
1599 GetElementsPointer()[--data_.a.size].~GenericValue();
1611 return Erase(pos, pos + 1);
1632 std::memmove(pos, last,
static_cast<size_t>(End() - last) *
sizeof(
GenericValue));
1633 data_.a.size -=
static_cast<SizeType>(last - first);
1638 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1645 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1646 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1647 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1648 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1655 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1656 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1657 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1658 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1659 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1666 return static_cast<float>(GetDouble());
1670 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1671 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1672 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1673 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1674 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(f);
return *
this; }
1681 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1723 #if RAPIDJSON_HAS_STDSTRING
1743 template <
typename T>
1744 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1746 template <
typename T>
1747 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1749 template <
typename T>
1750 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1752 template<
typename T>
1753 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1755 template<
typename T>
1756 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1767 template <
typename Handler>
1772 case kTrueType:
return handler.Bool(
true);
1779 if (
RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1784 return handler.EndObject(data_.o.size);
1792 return handler.EndArray(data_.a.size);
1795 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1799 if (IsDouble())
return handler.Double(data_.n.d);
1800 else if (IsInt())
return handler.Int(data_.n.i.i);
1801 else if (IsUint())
return handler.Uint(data_.n.u.u);
1802 else if (IsInt64())
return handler.Int64(data_.n.i64);
1803 else return handler.Uint64(data_.n.u64);
1808 template <
typename,
typename>
friend class GenericValue;
1813 kNumberFlag = 0x0010,
1816 kInt64Flag = 0x0080,
1817 kUint64Flag = 0x0100,
1818 kDoubleFlag = 0x0200,
1819 kStringFlag = 0x0400,
1821 kInlineStrFlag = 0x1000,
1827 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1828 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1829 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1830 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1831 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1832 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1834 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1835 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1842 static const SizeType kDefaultArrayCapacity = 16;
1843 static const SizeType kDefaultObjectCapacity = 16;
1846 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1847 char payload[
sizeof(
SizeType) * 2 + 6];
1848 #elif RAPIDJSON_64BIT
1849 char payload[
sizeof(
SizeType) * 2 +
sizeof(
void*) + 6];
1851 char payload[
sizeof(
SizeType) * 2 +
sizeof(
void*) + 2];
1870 struct ShortString {
1871 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1874 inline static bool Usable(
SizeType len) {
return (MaxSize >= len); }
1875 inline void SetLength(
SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
1876 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
1881 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1926 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
1927 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
1928 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
1929 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
1930 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
1931 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
1935 data_.f.flags = kArrayFlag;
1937 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
1938 SetElementsPointer(e);
1939 std::memcpy(e, values, count *
sizeof(GenericValue));
1942 SetElementsPointer(0);
1943 data_.a.size = data_.a.capacity = count;
1948 data_.f.flags = kObjectFlag;
1950 Member* m =
static_cast<Member*
>(allocator.Malloc(count *
sizeof(Member)));
1951 SetMembersPointer(m);
1952 std::memcpy(m, members, count *
sizeof(Member));
1955 SetMembersPointer(0);
1956 data_.o.size = data_.o.capacity = count;
1960 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
1961 data_.f.flags = kConstStringFlag;
1962 SetStringPointer(s);
1963 data_.s.length = s.length;
1967 void SetStringRaw(StringRefType s,
Allocator& allocator) {
1969 if (ShortString::Usable(s.length)) {
1970 data_.f.flags = kShortStringFlag;
1971 data_.ss.SetLength(s.length);
1974 data_.f.flags = kCopyStringFlag;
1975 data_.s.length = s.length;
1976 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
1977 SetStringPointer(str);
1979 std::memcpy(str, s, s.length *
sizeof(Ch));
1980 str[s.length] =
'\0';
1984 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
1987 rhs.data_.f.flags = kNullFlag;
1990 template <
typename SourceAllocator>
1991 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
1995 const SizeType len1 = GetStringLength();
1996 const SizeType len2 = rhs.GetStringLength();
1997 if(len1 != len2) {
return false; }
1999 const Ch*
const str1 = GetString();
2000 const Ch*
const str2 = rhs.GetString();
2001 if(str1 == str2) {
return true; }
2003 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2023 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
2026 typedef typename Encoding::Ch
Ch;
2051 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2057 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2060 : ValueType(std::forward<ValueType>(rhs)),
2061 allocator_(rhs.allocator_),
2062 ownAllocator_(rhs.ownAllocator_),
2063 stack_(std::move(rhs.stack_)),
2064 parseResult_(rhs.parseResult_)
2067 rhs.ownAllocator_ = 0;
2072 ~GenericDocument() {
2076 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2078 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2082 ValueType::operator=(std::forward<ValueType>(rhs));
2087 allocator_ = rhs.allocator_;
2088 ownAllocator_ = rhs.ownAllocator_;
2089 stack_ = std::move(rhs.stack_);
2090 parseResult_ = rhs.parseResult_;
2093 rhs.ownAllocator_ = 0;
2094 rhs.parseResult_ = ParseResult();
2107 ValueType::Swap(rhs);
2108 stack_.Swap(rhs.stack_);
2109 internal::Swap(allocator_, rhs.allocator_);
2110 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2111 internal::Swap(parseResult_, rhs.parseResult_);
2134 template <
typename Generator>
2136 ClearStackOnExit scope(*
this);
2139 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2154 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2157 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2158 ClearStackOnExit scope(*
this);
2159 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
2162 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2173 template <
unsigned parseFlags,
typename InputStream>
2175 return ParseStream<parseFlags, Encoding, InputStream>(is);
2183 template <
typename InputStream>
2185 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2197 template <
unsigned parseFlags>
2200 return ParseStream<parseFlags | kParseInsituFlag>(s);
2208 return ParseInsitu<kParseDefaultFlags>(str);
2220 template <
unsigned parseFlags,
typename SourceEncoding>
2224 return ParseStream<parseFlags, SourceEncoding>(s);
2231 template <
unsigned parseFlags>
2233 return Parse<parseFlags, Encoding>(str);
2240 return Parse<kParseDefaultFlags>(str);
2243 template <
unsigned parseFlags,
typename SourceEncoding>
2244 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2246 MemoryStream ms(
static_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2248 ParseStream<parseFlags, SourceEncoding>(is);
2252 template <
unsigned parseFlags>
2253 GenericDocument& Parse(
const Ch* str,
size_t length) {
2254 return Parse<parseFlags, Encoding>(str, length);
2257 GenericDocument& Parse(
const Ch* str,
size_t length) {
2258 return Parse<kParseDefaultFlags>(str, length);
2261 #if RAPIDJSON_HAS_STDSTRING
2262 template <
unsigned parseFlags,
typename SourceEncoding>
2263 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2265 return Parse<parseFlags, SourceEncoding>(str.c_str());
2268 template <
unsigned parseFlags>
2269 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2270 return Parse<parseFlags, Encoding>(str.c_str());
2273 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2274 return Parse<kParseDefaultFlags>(str);
2318 struct ClearStackOnExit {
2320 ~ClearStackOnExit() { d_.ClearStack(); }
2322 ClearStackOnExit(
const ClearStackOnExit&);
2323 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2324 GenericDocument& d_;
2329 template <
typename,
typename>
friend class GenericValue;
2333 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2334 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2335 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2336 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2337 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2338 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2339 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2341 bool RawNumber(
const Ch* str,
SizeType length,
bool copy) {
2343 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2345 new (stack_.template Push<ValueType>()) ValueType(str, length);
2349 bool String(
const Ch* str,
SizeType length,
bool copy) {
2351 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2353 new (stack_.template Push<ValueType>()) ValueType(str, length);
2357 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(
kObjectType);
return true; }
2359 bool Key(
const Ch* str,
SizeType length,
bool copy) {
return String(str, length, copy); }
2361 bool EndObject(
SizeType memberCount) {
2362 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2363 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2367 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(
kArrayType);
return true; }
2369 bool EndArray(
SizeType elementCount) {
2370 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2371 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2377 GenericDocument(
const GenericDocument&);
2379 GenericDocument& operator=(
const GenericDocument&);
2382 if (Allocator::kNeedFree)
2383 while (stack_.GetSize() > 0)
2384 (stack_.template Pop<ValueType>(1))->~ValueType();
2387 stack_.ShrinkToFit();
2394 static const size_t kDefaultStackCapacity = 1024;
2397 internal::Stack<StackAllocator> stack_;
2398 ParseResult parseResult_;
2405 template <
typename Encoding,
typename Allocator>
2406 template <
typename SourceAllocator>
2410 switch (rhs.GetType()) {
2415 RawAssign(*d.stack_.template Pop<GenericValue>(1));
2419 if (rhs.data_.f.flags == kConstStringFlag) {
2420 data_.f.flags = rhs.data_.f.flags;
2421 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2427 data_.f.flags = rhs.data_.f.flags;
2428 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2438 template <
bool Const,
typename ValueT>
2443 typedef ValueT PlainType;
2445 typedef ValueType* ValueIterator;
2446 typedef const ValueT* ConstValueIterator;
2447 typedef typename ValueType::AllocatorType AllocatorType;
2448 typedef typename ValueType::StringRefType StringRefType;
2450 template <
typename,
typename>
2457 SizeType Size()
const {
return value_.Size(); }
2458 SizeType Capacity()
const {
return value_.Capacity(); }
2459 bool Empty()
const {
return value_.Empty(); }
2460 void Clear()
const { value_.Clear(); }
2461 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2462 ValueIterator Begin()
const {
return value_.Begin(); }
2463 ValueIterator End()
const {
return value_.End(); }
2464 GenericArray Reserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.Reserve(newCapacity, allocator);
return *
this; }
2465 GenericArray PushBack(ValueType& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2466 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2467 GenericArray PushBack(ValueType&& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2469 GenericArray PushBack(StringRefType value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2470 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; }
2471 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2472 ValueIterator Erase(ConstValueIterator pos)
const {
return value_.Erase(pos); }
2473 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
const {
return value_.Erase(first, last); }
2475 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2476 ValueIterator begin()
const {
return value_.Begin(); }
2477 ValueIterator end()
const {
return value_.End(); }
2491 template <
bool Const,
typename ValueT>
2496 typedef ValueT PlainType;
2500 typedef typename ValueType::AllocatorType AllocatorType;
2501 typedef typename ValueType::StringRefType StringRefType;
2502 typedef typename ValueType::EncodingType EncodingType;
2503 typedef typename ValueType::Ch Ch;
2505 template <
typename,
typename>
2512 SizeType MemberCount()
const {
return value_.MemberCount(); }
2513 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2514 template <
typename T> ValueType& operator[](T* name)
const {
return value_[name]; }
2516 #if RAPIDJSON_HAS_STDSTRING
2517 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2519 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2521 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2522 #if RAPIDJSON_HAS_STDSTRING
2523 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2526 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2528 #if RAPIDJSON_HAS_STDSTRING
2529 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2531 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2532 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2533 #if RAPIDJSON_HAS_STDSTRING
2534 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2536 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; }
2537 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2538 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2539 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2540 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2541 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2543 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2544 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2545 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericObject)) AddMember(StringRefType name, T value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2546 void RemoveAllMembers() {
return value_.RemoveAllMembers(); }
2547 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
2548 #if RAPIDJSON_HAS_STDSTRING
2549 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
2555 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
2556 #if RAPIDJSON_HAS_STDSTRING
2557 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
2561 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2572 RAPIDJSON_NAMESPACE_END
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
Helper class for accessing Value of array type.
Definition: document.h:2439
A document for parsing JSON text as DOM.
Definition: document.h:2024
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2127
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:2314
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:2155
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2027
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:2232
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:2028
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition: document.h:2135
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition: document.h:2284
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:2198
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2050
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:2026
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2037
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:2239
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:2287
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2106
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:2184
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2308
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:2174
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2221
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:2207
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:2290
(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:2492
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: pointer.h:81
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:466
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:540
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:543
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:544
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:550
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition: document.h:817
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics.
Definition: document.h:841
ConstValueIterator Begin() const
Constant element iterator.
Definition: document.h:1511
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition: document.h:1541
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition: document.h:1417
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition: document.h:1404
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:1522
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:1686
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:661
bool ObjectEmpty() const
Check whether the object is empty.
Definition: document.h:1019
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:1468
MemberIterator FindMember(const std::basic_string< Ch > &name)
Find member by string object name.
Definition: document.h:1172
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1304
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition: document.h:1078
GenericValue & SetString(const std::basic_string< Ch > &s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1731
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition: document.h:1564
~GenericValue()
Destructor.
Definition: document.h:719
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:640
GenericValue & operator[](const std::basic_string< Ch > &name)
Get a value from an object associated with name (string object).
Definition: document.h:1069
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:676
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:547
GenericValue & SetBool(bool b)
Definition: document.h:1004
float GetFloat() const
Get the value as float type.
Definition: document.h:1665
GenericValue & AddMember(GenericValue &name, std::basic_string< Ch > &value, Allocator &allocator)
Add a string object as member (name-value pair) to the object.
Definition: document.h:1233
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:837
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:545
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Explicit copy constructor (with allocator)
Definition: document.h:2408
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition: document.h:915
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:592
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:679
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition: document.h:1610
void RemoveAllMembers()
Remove all members in the object.
Definition: document.h:1337
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:549
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:673
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition: document.h:700
bool GetBool() const
Set boolean value.
Definition: document.h:1001
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition: document.h:1118
SizeType Size() const
Get the number of elements in array.
Definition: document.h:1471
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:1013
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:1474
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:685
GenericValue(const std::basic_string< Ch > &s, Allocator &allocator)
Constructor for copy-string from a string object (i.e. do make a copy of string)
Definition: document.h:691
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1290
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition: document.h:711
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:551
SizeType MemberCount() const
Get the number of members in the object.
Definition: document.h:1016
ValueIterator Begin()
Element iterator.
Definition: document.h:1505
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition: document.h:1153
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition: document.h:1031
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition: document.h:1622
MemberIterator MemberBegin()
Member iterator.
Definition: document.h:1081
bool HasMember(const std::basic_string< Ch > &name) const
Check whether a member exists in the object with string object.
Definition: document.h:1105
double GetDouble() const
Get the value as double type.
Definition: document.h:1653
void Clear()
Remove all elements in the array.
Definition: document.h:1483
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:1352
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition: document.h:1048
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:1094
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:925
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition: document.h:1703
bool operator==(const T &rhs) const
Equal-to operator with primitive types.
Definition: document.h:906
ValueIterator End()
Past-the-end element iterator
Definition: document.h:1508
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1186
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1721
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition: document.h:852
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:625
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:634
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition: document.h:1514
bool EraseMember(const Ch *name)
Erase a member in object by its name.
Definition: document.h:1438
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:548
bool Is() const
Templated version for checking whether this value is type T.
Definition: document.h:1744
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:646
bool Empty() const
Check whether the array is empty.
Definition: document.h:1477
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:562
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition: document.h:1132
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1218
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:552
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:1768
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition: document.h:912
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:682
MemberIterator MemberEnd()
Past-the-end member iterator
Definition: document.h:1084
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:1496
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:546
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:930
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:1596
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1713
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types.
Definition: document.h:920
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition: document.h:1075
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:755
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:774
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition: document.h:894
bool operator==(const std::basic_string< Ch > &rhs) const
Equal-to operator with string object.
Definition: document.h:900
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition: document.h:1380
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:1696
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Deep-copy assignment from Value.
Definition: document.h:805
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:468
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
ParseErrorCode
Error code of parsing.
Definition: error.h:64
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
GenericPointer< Value, CrtAllocator > Pointer
GenericPointer for Value (UTF-8, default allocator).
Definition: fwd.h:126
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:380
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:147
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2010
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2402
Type
Type of JSON value.
Definition: rapidjson.h:603
@ kArrayType
array
Definition: rapidjson.h:608
@ kTrueType
true
Definition: rapidjson.h:606
@ kNullType
null
Definition: rapidjson.h:604
@ kFalseType
false
Definition: rapidjson.h:605
@ kNumberType
number
Definition: rapidjson.h:610
@ kObjectType
object
Definition: rapidjson.h:607
@ kStringType
string
Definition: rapidjson.h:609
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:384
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:590
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition: rapidjson.h:586
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:437
A read-write string stream.
Definition: stream.h:144
Name-value pair in a JSON object value.
Definition: document.h:71
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:73
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:72
Reference to a constant string (not taking a copy)
Definition: document.h:249
const Ch *const s
plain CharType pointer
Definition: document.h:324
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:366
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:346
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:325
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:384
Read-only string stream.
Definition: stream.h:110
Definition: document.h:1891
Definition: document.h:1895
Represents an in-memory input byte stream.
Definition: memorystream.h:40