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(padded)
31 RAPIDJSON_DIAG_OFF(
switch-
enum)
32 RAPIDJSON_DIAG_OFF(c++98-compat)
33 #elif defined(_MSC_VER)
34 RAPIDJSON_DIAG_OFF(4127)
35 RAPIDJSON_DIAG_OFF(4244)
39 RAPIDJSON_DIAG_OFF(effc++)
42 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
46 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
50 RAPIDJSON_NAMESPACE_BEGIN
53 template <
typename Encoding,
typename Allocator>
56 template <
typename Encoding,
typename Allocator,
typename StackAllocator>
57 class GenericDocument;
65 template <
typename Encoding,
typename Allocator>
71 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
74 : name(std::move(rhs.name)),
75 value(std::move(rhs.value))
99 a.value.
Swap(b.value);
104 GenericMember(
const GenericMember& rhs);
110 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
131 template <
bool Const,
typename Encoding,
typename Allocator>
150 typedef ValueType value_type;
151 typedef ValueType * pointer;
152 typedef ValueType & reference;
153 typedef std::ptrdiff_t difference_type;
154 typedef std::random_access_iterator_tag iterator_category;
187 Iterator& operator=(
const NonConstIterator & it) { ptr_ = it.ptr_;
return *
this; }
191 Iterator& operator++(){ ++ptr_;
return *
this; }
192 Iterator& operator--(){ --ptr_;
return *
this; }
193 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
194 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
199 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
200 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
202 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
203 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
208 bool operator==(ConstIterator that)
const {
return ptr_ == that.ptr_; }
209 bool operator!=(ConstIterator that)
const {
return ptr_ != that.ptr_; }
210 bool operator<=(ConstIterator that)
const {
return ptr_ <= that.ptr_; }
211 bool operator>=(ConstIterator that)
const {
return ptr_ >= that.ptr_; }
212 bool operator< (ConstIterator that)
const {
return ptr_ < that.ptr_; }
213 bool operator> (ConstIterator that)
const {
return ptr_ > that.ptr_; }
218 Reference operator*()
const {
return *ptr_; }
219 Pointer operator->()
const {
return ptr_; }
220 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
237 template <
bool Const,
typename Encoding,
typename Allocator>
238 class GenericMemberIterator;
241 template <
typename Encoding,
typename Allocator>
244 typedef GenericMember<Encoding,Allocator>* Iterator;
247 template <
typename Encoding,
typename Allocator>
250 typedef const GenericMember<Encoding,Allocator>* Iterator;
285 template<
typename CharType>
316 : s(str), length(N-1) {}
340 : s(str), length(NotNullStrLen(str)) {}
357 operator const Ch *()
const {
return s; }
363 SizeType NotNullStrLen(
const CharType* str) {
365 return internal::StrLen(str);
369 static const Ch emptyString[];
378 template<
typename CharType>
379 const CharType GenericStringRef<CharType>::emptyString[] = { CharType() };
393 template<
typename CharType>
413 template<
typename CharType>
418 #if RAPIDJSON_HAS_STDSTRING
431 template<
typename CharType>
441 template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
442 struct IsGenericValueImpl : FalseType {};
445 template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>
::Type, typename Void<typename T::AllocatorType>
::Type>
446 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>
::Type {};
449 template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>
::Type {};
458 template <
typename ValueType,
typename T>
459 struct TypeHelper {};
461 template<
typename ValueType>
462 struct TypeHelper<ValueType, bool> {
463 static bool Is(
const ValueType& v) {
return v.IsBool(); }
464 static bool Get(
const ValueType& v) {
return v.GetBool(); }
465 static ValueType& Set(ValueType& v,
bool data) {
return v.SetBool(data); }
466 static ValueType& Set(ValueType& v,
bool data,
typename ValueType::AllocatorType&) {
return v.SetBool(data); }
469 template<
typename ValueType>
470 struct TypeHelper<ValueType, int> {
471 static bool Is(
const ValueType& v) {
return v.IsInt(); }
472 static int Get(
const ValueType& v) {
return v.GetInt(); }
473 static ValueType& Set(ValueType& v,
int data) {
return v.SetInt(data); }
474 static ValueType& Set(ValueType& v,
int data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
477 template<
typename ValueType>
478 struct TypeHelper<ValueType, unsigned> {
479 static bool Is(
const ValueType& v) {
return v.IsUint(); }
480 static unsigned Get(
const ValueType& v) {
return v.GetUint(); }
481 static ValueType& Set(ValueType& v,
unsigned data) {
return v.SetUint(data); }
482 static ValueType& Set(ValueType& v,
unsigned data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
487 template<
typename ValueType>
488 struct TypeHelper<ValueType, long> {
489 static bool Is(
const ValueType& v) {
return v.IsInt(); }
490 static long Get(
const ValueType& v) {
return v.GetInt(); }
491 static ValueType& Set(ValueType& v,
long data) {
return v.SetInt(data); }
492 static ValueType& Set(ValueType& v,
long data,
typename ValueType::AllocatorType&) {
return v.SetInt(data); }
496 template<
typename ValueType>
497 struct TypeHelper<ValueType, unsigned long> {
498 static bool Is(
const ValueType& v) {
return v.IsUint(); }
499 static unsigned long Get(
const ValueType& v) {
return v.GetUint(); }
500 static ValueType& Set(ValueType& v,
unsigned long data) {
return v.SetUint(data); }
501 static ValueType& Set(ValueType& v,
unsigned long data,
typename ValueType::AllocatorType&) {
return v.SetUint(data); }
505 template<
typename ValueType>
506 struct TypeHelper<ValueType, int64_t> {
507 static bool Is(
const ValueType& v) {
return v.IsInt64(); }
508 static int64_t Get(
const ValueType& v) {
return v.GetInt64(); }
509 static ValueType& Set(ValueType& v, int64_t data) {
return v.SetInt64(data); }
510 static ValueType& Set(ValueType& v, int64_t data,
typename ValueType::AllocatorType&) {
return v.SetInt64(data); }
513 template<
typename ValueType>
514 struct TypeHelper<ValueType, uint64_t> {
515 static bool Is(
const ValueType& v) {
return v.IsUint64(); }
516 static uint64_t Get(
const ValueType& v) {
return v.GetUint64(); }
517 static ValueType& Set(ValueType& v, uint64_t data) {
return v.SetUint64(data); }
518 static ValueType& Set(ValueType& v, uint64_t data,
typename ValueType::AllocatorType&) {
return v.SetUint64(data); }
521 template<
typename ValueType>
522 struct TypeHelper<ValueType, double> {
523 static bool Is(
const ValueType& v) {
return v.IsDouble(); }
524 static double Get(
const ValueType& v) {
return v.GetDouble(); }
525 static ValueType& Set(ValueType& v,
double data) {
return v.SetDouble(data); }
526 static ValueType& Set(ValueType& v,
double data,
typename ValueType::AllocatorType&) {
return v.SetDouble(data); }
529 template<
typename ValueType>
530 struct TypeHelper<ValueType, float> {
531 static bool Is(
const ValueType& v) {
return v.IsFloat(); }
532 static float Get(
const ValueType& v) {
return v.GetFloat(); }
533 static ValueType& Set(ValueType& v,
float data) {
return v.SetFloat(data); }
534 static ValueType& Set(ValueType& v,
float data,
typename ValueType::AllocatorType&) {
return v.SetFloat(data); }
537 template<
typename ValueType>
538 struct TypeHelper<ValueType, const typename ValueType::Ch*> {
539 typedef const typename ValueType::Ch* StringType;
540 static bool Is(
const ValueType& v) {
return v.IsString(); }
541 static StringType Get(
const ValueType& v) {
return v.GetString(); }
542 static ValueType& Set(ValueType& v,
const StringType data) {
return v.SetString(
typename ValueType::StringRefType(data)); }
543 static ValueType& Set(ValueType& v,
const StringType data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
546 #if RAPIDJSON_HAS_STDSTRING
547 template<
typename ValueType>
548 struct TypeHelper<ValueType, std::basic_string<typename ValueType::Ch> > {
549 typedef std::basic_string<typename ValueType::Ch> StringType;
550 static bool Is(
const ValueType& v) {
return v.IsString(); }
551 static StringType Get(
const ValueType& v) {
return StringType(v.GetString(), v.GetStringLength()); }
552 static ValueType& Set(ValueType& v,
const StringType& data,
typename ValueType::AllocatorType& a) {
return v.SetString(data, a); }
556 template<
typename ValueType>
557 struct TypeHelper<ValueType, typename ValueType::Array> {
558 typedef typename ValueType::Array ArrayType;
559 static bool Is(
const ValueType& v) {
return v.IsArray(); }
560 static ArrayType Get(ValueType& v) {
return v.GetArray(); }
561 static ValueType& Set(ValueType& v, ArrayType data) {
return v = data; }
562 static ValueType& Set(ValueType& v, ArrayType data,
typename ValueType::AllocatorType&) {
return v = data; }
565 template<
typename ValueType>
566 struct TypeHelper<ValueType, typename ValueType::ConstArray> {
567 typedef typename ValueType::ConstArray ArrayType;
568 static bool Is(
const ValueType& v) {
return v.IsArray(); }
569 static ArrayType Get(
const ValueType& v) {
return v.GetArray(); }
572 template<
typename ValueType>
573 struct TypeHelper<ValueType, typename ValueType::Object> {
574 typedef typename ValueType::Object ObjectType;
575 static bool Is(
const ValueType& v) {
return v.IsObject(); }
576 static ObjectType Get(ValueType& v) {
return v.GetObject(); }
577 static ValueType& Set(ValueType& v, ObjectType data) {
return v = data; }
578 static ValueType& Set(ValueType& v, ObjectType data,
typename ValueType::AllocatorType&) {
return v = data; }
581 template<
typename ValueType>
582 struct TypeHelper<ValueType, typename ValueType::ConstObject> {
583 typedef typename ValueType::ConstObject ObjectType;
584 static bool Is(
const ValueType& v) {
return v.IsObject(); }
585 static ObjectType Get(
const ValueType& v) {
return v.GetObject(); }
591 template <
bool,
typename>
class GenericArray;
592 template <
bool,
typename>
class GenericObject;
607 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
614 typedef typename Encoding::Ch
Ch;
630 GenericValue() RAPIDJSON_NOEXCEPT : data_() { data_.f.flags = kNullFlag; }
632 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
635 rhs.data_.f.flags = kNullFlag;
641 GenericValue(
const GenericValue& rhs);
643 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
645 template <
typename StackAllocator>
646 GenericValue(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
649 template <
typename StackAllocator>
650 GenericValue& operator=(GenericDocument<Encoding,Allocator,StackAllocator>&& rhs);
661 static const uint16_t defaultFlags[] = {
662 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
666 data_.f.flags = defaultFlags[type];
670 data_.ss.SetLength(0);
681 template <
typename SourceAllocator>
683 switch (rhs.GetType()) {
688 for (
SizeType i = 0; i < count; i++) {
692 data_.f.flags = kObjectFlag;
693 data_.o.size = data_.o.capacity = count;
694 SetMembersPointer(lm);
701 for (
SizeType i = 0; i < count; i++)
702 new (&le[i])
GenericValue(re[i], allocator, copyConstStrings);
703 data_.f.flags = kArrayFlag;
704 data_.a.size = data_.a.capacity = count;
705 SetElementsPointer(le);
709 if (rhs.data_.f.flags == kConstStringFlag && !copyConstStrings) {
710 data_.f.flags = rhs.data_.f.flags;
711 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
717 data_.f.flags = rhs.data_.f.flags;
718 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
729 #ifndef RAPIDJSON_DOXYGEN_RUNNING
730 template <
typename T>
731 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<bool, T>))) RAPIDJSON_NOEXCEPT
738 data_.f.flags = b ? kTrueFlag : kFalseFlag;
744 data_.f.flags = (i >= 0) ? (kNumberIntFlag | kUintFlag | kUint64Flag) : kNumberIntFlag;
750 data_.f.flags = (u & 0x80000000) ? kNumberUintFlag : (kNumberUintFlag | kIntFlag | kInt64Flag);
756 data_.f.flags = kNumberInt64Flag;
758 data_.f.flags |= kNumberUint64Flag;
760 data_.f.flags |= kUintFlag;
762 data_.f.flags |= kIntFlag;
765 data_.f.flags |= kIntFlag;
771 data_.f.flags = kNumberUint64Flag;
773 data_.f.flags |= kInt64Flag;
775 data_.f.flags |= kUintFlag;
777 data_.f.flags |= kIntFlag;
781 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_() { data_.n.d = d; data_.f.flags = kNumberDoubleFlag; }
784 explicit GenericValue(
float f) RAPIDJSON_NOEXCEPT : data_() { data_.n.d =
static_cast<double>(f); data_.f.flags = kNumberDoubleFlag; }
798 #if RAPIDJSON_HAS_STDSTRING
812 a.value_.data_ = Data();
813 a.value_.data_.f.flags = kArrayFlag;
823 o.value_.data_ = Data();
824 o.value_.data_.f.flags = kObjectFlag;
831 if (Allocator::kNeedFree) {
832 switch(data_.f.flags) {
845 Allocator::Free(GetMembersPointer());
848 case kCopyStringFlag:
849 Allocator::Free(
const_cast<Ch*
>(GetStringPointer()));
874 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
877 return *
this = rhs.
Move();
903 template <
typename T>
904 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
917 template <
typename SourceAllocator>
919 RAPIDJSON_ASSERT(
static_cast<void*
>(
this) !=
static_cast<void const*
>(&rhs));
921 new (
this)
GenericValue(rhs, allocator, copyConstStrings);
932 temp.RawAssign(*
this);
934 other.RawAssign(temp);
964 template <
typename SourceAllocator>
967 if (GetType() != rhs.GetType())
972 if (data_.o.size != rhs.data_.o.size)
974 for (
ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
975 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.
FindMember(lhsMemberItr->name);
976 if (rhsMemberItr == rhs.
MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
982 if (data_.a.size != rhs.data_.a.size)
984 for (
SizeType i = 0; i < data_.a.size; i++)
985 if ((*
this)[i] != rhs[i])
990 return StringEqual(rhs);
993 if (IsDouble() || rhs.IsDouble()) {
994 double a = GetDouble();
996 return a >= b && a <= b;
999 return data_.n.u64 == rhs.data_.n.u64;
1009 #if RAPIDJSON_HAS_STDSTRING
1019 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
1024 template <
typename SourceAllocator>
1033 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
1038 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
1043 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
1049 Type GetType()
const {
return static_cast<Type>(data_.f.flags & kTypeMask); }
1050 bool IsNull()
const {
return data_.f.flags == kNullFlag; }
1051 bool IsFalse()
const {
return data_.f.flags == kFalseFlag; }
1052 bool IsTrue()
const {
return data_.f.flags == kTrueFlag; }
1053 bool IsBool()
const {
return (data_.f.flags & kBoolFlag) != 0; }
1054 bool IsObject()
const {
return data_.f.flags == kObjectFlag; }
1055 bool IsArray()
const {
return data_.f.flags == kArrayFlag; }
1056 bool IsNumber()
const {
return (data_.f.flags & kNumberFlag) != 0; }
1057 bool IsInt()
const {
return (data_.f.flags & kIntFlag) != 0; }
1058 bool IsUint()
const {
return (data_.f.flags & kUintFlag) != 0; }
1059 bool IsInt64()
const {
return (data_.f.flags & kInt64Flag) != 0; }
1060 bool IsUint64()
const {
return (data_.f.flags & kUint64Flag) != 0; }
1061 bool IsDouble()
const {
return (data_.f.flags & kDoubleFlag) != 0; }
1062 bool IsString()
const {
return (data_.f.flags & kStringFlag) != 0; }
1065 bool IsLosslessDouble()
const {
1066 if (!IsNumber())
return false;
1068 uint64_t u = GetUint64();
1069 volatile double d =
static_cast<double>(u);
1071 && (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
1072 && (u ==
static_cast<uint64_t
>(d));
1075 int64_t i = GetInt64();
1076 volatile double d =
static_cast<double>(i);
1077 return (d >=
static_cast<double>((std::numeric_limits<int64_t>::min)()))
1078 && (d <
static_cast<double>((std::numeric_limits<int64_t>::max)()))
1079 && (i ==
static_cast<int64_t
>(d));
1085 bool IsFloat()
const {
1086 if ((data_.f.flags & kDoubleFlag) == 0)
1088 double d = GetDouble();
1089 return d >= -3.4028234e38 && d <= 3.4028234e38;
1092 bool IsLosslessFloat()
const {
1093 if (!IsNumber())
return false;
1094 double a = GetDouble();
1095 if (a <
static_cast<double>(-(std::numeric_limits<float>::max)())
1096 || a >
static_cast<double>((std::numeric_limits<float>::max)()))
1098 double b =
static_cast<double>(
static_cast<float>(a));
1099 return a >= b && a <= b;
1107 GenericValue& SetNull() { this->~GenericValue();
new (
this) GenericValue();
return *
this; }
1146 template <
typename T>
1151 template <
typename T>
1163 template <
typename SourceAllocator>
1166 if (member != MemberEnd())
1167 return member->value;
1180 template <
typename SourceAllocator>
1183 #if RAPIDJSON_HAS_STDSTRING
1210 if (newCapacity > data_.o.capacity) {
1211 SetMembersPointer(
reinterpret_cast<Member*
>(allocator.Realloc(GetMembersPointer(), data_.o.capacity *
sizeof(
Member), newCapacity *
sizeof(
Member))));
1212 data_.o.capacity = newCapacity;
1225 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
1227 #if RAPIDJSON_HAS_STDSTRING
1236 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
1248 template <
typename SourceAllocator>
1265 return FindMember(n);
1268 ConstMemberIterator FindMember(
const Ch* name)
const {
return const_cast<GenericValue&
>(*this).
FindMember(name); }
1283 template <
typename SourceAllocator>
1288 for ( ; member != MemberEnd(); ++member)
1289 if (name.StringEqual(member->name))
1295 #if RAPIDJSON_HAS_STDSTRING
1304 ConstMemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return FindMember(
GenericValue(
StringRef(name))); }
1321 ObjectData& o = data_.o;
1322 if (o.size >= o.capacity)
1323 MemberReserve(o.capacity == 0 ? kDefaultObjectCapacity : (o.capacity + (o.capacity + 1) / 2), allocator);
1324 Member* members = GetMembersPointer();
1325 members[o.size].
name.RawAssign(name);
1326 members[o.size].
value.RawAssign(value);
1342 return AddMember(name, v, allocator);
1345 #if RAPIDJSON_HAS_STDSTRING
1357 return AddMember(name, v, allocator);
1378 template <
typename T>
1379 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1382 return AddMember(name, v, allocator);
1385 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1387 return AddMember(name, value, allocator);
1389 GenericValue& AddMember(GenericValue&& name, GenericValue& value,
Allocator& allocator) {
1390 return AddMember(name, value, allocator);
1392 GenericValue& AddMember(GenericValue& name, GenericValue&& value,
Allocator& allocator) {
1393 return AddMember(name, value, allocator);
1395 GenericValue& AddMember(StringRefType name, GenericValue&& value,
Allocator& allocator) {
1396 GenericValue n(name);
1397 return AddMember(n, value, allocator);
1414 return AddMember(n, value, allocator);
1428 return AddMember(name, v, allocator);
1448 template <
typename T>
1449 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1452 return AddMember(n, value, allocator);
1476 return RemoveMember(n);
1479 #if RAPIDJSON_HAS_STDSTRING
1480 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1483 template <
typename SourceAllocator>
1484 bool RemoveMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1485 MemberIterator m = FindMember(name);
1486 if (m != MemberEnd()) {
1509 if (data_.o.size > 1 && m != last)
1527 return EraseMember(pos, pos +1);
1550 std::memmove(
static_cast<void*
>(&*pos), &*last,
static_cast<size_t>(MemberEnd() - last) *
sizeof(
Member));
1551 data_.o.size -=
static_cast<SizeType>(last - first);
1562 return EraseMember(n);
1565 #if RAPIDJSON_HAS_STDSTRING
1566 bool EraseMember(
const std::basic_string<Ch>& name) {
return EraseMember(
GenericValue(
StringRef(name))); }
1569 template <
typename SourceAllocator>
1570 bool EraseMember(
const GenericValue<Encoding, SourceAllocator>& name) {
1571 MemberIterator m = FindMember(name);
1572 if (m != MemberEnd()) {
1581 ConstObject GetObject()
const {
RAPIDJSON_ASSERT(IsObject());
return ConstObject(*
this); }
1621 return GetElementsPointer()[index];
1646 if (newCapacity > data_.a.capacity) {
1648 data_.a.capacity = newCapacity;
1665 if (data_.a.size >= data_.a.capacity)
1666 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1667 GetElementsPointer()[data_.a.size++].RawAssign(value);
1671 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1673 return PushBack(value, allocator);
1687 return (*this).template PushBack<StringRefType>(value, allocator);
1707 template <
typename T>
1708 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1711 return PushBack(v, allocator);
1721 GetElementsPointer()[--data_.a.size].~GenericValue();
1733 return Erase(pos, pos + 1);
1754 std::memmove(
static_cast<void*
>(pos), last,
static_cast<size_t>(End() - last) *
sizeof(
GenericValue));
1755 data_.a.size -=
static_cast<SizeType>(last - first);
1760 ConstArray GetArray()
const {
RAPIDJSON_ASSERT(IsArray());
return ConstArray(*
this); }
1767 int GetInt()
const {
RAPIDJSON_ASSERT(data_.f.flags & kIntFlag);
return data_.n.i.i; }
1768 unsigned GetUint()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUintFlag);
return data_.n.u.u; }
1769 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kInt64Flag);
return data_.n.i64; }
1770 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(data_.f.flags & kUint64Flag);
return data_.n.u64; }
1777 if ((data_.f.flags & kDoubleFlag) != 0)
return data_.n.d;
1778 if ((data_.f.flags & kIntFlag) != 0)
return data_.n.i.i;
1779 if ((data_.f.flags & kUintFlag) != 0)
return data_.n.u.u;
1780 if ((data_.f.flags & kInt64Flag) != 0)
return static_cast<double>(data_.n.i64);
1781 RAPIDJSON_ASSERT((data_.f.flags & kUint64Flag) != 0);
return static_cast<double>(data_.n.u64);
1788 return static_cast<float>(GetDouble());
1792 GenericValue& SetUint(
unsigned u) { this->~GenericValue();
new (
this) GenericValue(u);
return *
this; }
1793 GenericValue& SetInt64(int64_t i64) { this->~GenericValue();
new (
this) GenericValue(i64);
return *
this; }
1794 GenericValue& SetUint64(uint64_t u64) { this->~GenericValue();
new (
this) GenericValue(u64);
return *
this; }
1795 GenericValue& SetDouble(
double d) { this->~GenericValue();
new (
this) GenericValue(d);
return *
this; }
1796 GenericValue& SetFloat(
float f) { this->~GenericValue();
new (
this) GenericValue(
static_cast<double>(f));
return *
this; }
1803 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return (data_.f.flags & kInlineStrFlag) ? data_.ss.str : GetStringPointer(); }
1853 #if RAPIDJSON_HAS_STDSTRING
1873 template <
typename T>
1874 bool Is()
const {
return internal::TypeHelper<ValueType, T>::Is(*
this); }
1876 template <
typename T>
1877 T Get()
const {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1879 template <
typename T>
1880 T Get() {
return internal::TypeHelper<ValueType, T>::Get(*
this); }
1882 template<
typename T>
1883 ValueType& Set(
const T& data) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data); }
1885 template<
typename T>
1886 ValueType& Set(
const T& data, AllocatorType& allocator) {
return internal::TypeHelper<ValueType, T>::Set(*
this, data, allocator); }
1897 template <
typename Handler>
1902 case kTrueType:
return handler.Bool(
true);
1909 if (
RAPIDJSON_UNLIKELY(!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.data_.f.flags & kCopyFlag) != 0)))
1914 return handler.EndObject(data_.o.size);
1922 return handler.EndArray(data_.a.size);
1925 return handler.String(GetString(), GetStringLength(), (data_.f.flags & kCopyFlag) != 0);
1929 if (IsDouble())
return handler.Double(data_.n.d);
1930 else if (IsInt())
return handler.Int(data_.n.i.i);
1931 else if (IsUint())
return handler.Uint(data_.n.u.u);
1932 else if (IsInt64())
return handler.Int64(data_.n.i64);
1933 else return handler.Uint64(data_.n.u64);
1938 template <
typename,
typename>
friend class GenericValue;
1943 kNumberFlag = 0x0010,
1946 kInt64Flag = 0x0080,
1947 kUint64Flag = 0x0100,
1948 kDoubleFlag = 0x0200,
1949 kStringFlag = 0x0400,
1951 kInlineStrFlag = 0x1000,
1957 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1958 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1959 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1960 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1961 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1962 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1964 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1965 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1972 static const SizeType kDefaultArrayCapacity = 16;
1973 static const SizeType kDefaultObjectCapacity = 16;
1976 #if RAPIDJSON_48BITPOINTER_OPTIMIZATION
1977 char payload[
sizeof(
SizeType) * 2 + 6];
1978 #elif RAPIDJSON_64BIT
1979 char payload[
sizeof(
SizeType) * 2 +
sizeof(
void*) + 6];
1981 char payload[
sizeof(
SizeType) * 2 +
sizeof(
void*) + 2];
2000 struct ShortString {
2001 enum { MaxChars =
sizeof(
static_cast<Flag*
>(0)->payload) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
2004 inline static bool Usable(
SizeType len) {
return (MaxSize >= len); }
2005 inline void SetLength(
SizeType len) { str[LenPos] =
static_cast<Ch
>(MaxSize - len); }
2006 inline SizeType GetLength()
const {
return static_cast<SizeType>(MaxSize - str[LenPos]); }
2011 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
2056 RAPIDJSON_FORCEINLINE
const Ch* GetStringPointer()
const {
return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
2057 RAPIDJSON_FORCEINLINE
const Ch* SetStringPointer(
const Ch* str) {
return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
2058 RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer()
const {
return RAPIDJSON_GETPOINTER(GenericValue, data_.a.elements); }
2059 RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer(GenericValue* elements) {
return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
2060 RAPIDJSON_FORCEINLINE Member* GetMembersPointer()
const {
return RAPIDJSON_GETPOINTER(Member, data_.o.members); }
2061 RAPIDJSON_FORCEINLINE Member* SetMembersPointer(Member* members) {
return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
2065 data_.f.flags = kArrayFlag;
2067 GenericValue* e =
static_cast<GenericValue*
>(allocator.Malloc(count *
sizeof(GenericValue)));
2068 SetElementsPointer(e);
2069 std::memcpy(
static_cast<void*
>(e), values, count *
sizeof(GenericValue));
2072 SetElementsPointer(0);
2073 data_.a.size = data_.a.capacity = count;
2078 data_.f.flags = kObjectFlag;
2080 Member* m =
static_cast<Member*
>(allocator.Malloc(count *
sizeof(Member)));
2081 SetMembersPointer(m);
2082 std::memcpy(
static_cast<void*
>(m), members, count *
sizeof(Member));
2085 SetMembersPointer(0);
2086 data_.o.size = data_.o.capacity = count;
2090 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
2091 data_.f.flags = kConstStringFlag;
2092 SetStringPointer(s);
2093 data_.s.length = s.length;
2097 void SetStringRaw(StringRefType s,
Allocator& allocator) {
2099 if (ShortString::Usable(s.length)) {
2100 data_.f.flags = kShortStringFlag;
2101 data_.ss.SetLength(s.length);
2104 data_.f.flags = kCopyStringFlag;
2105 data_.s.length = s.length;
2106 str =
static_cast<Ch *
>(allocator.Malloc((s.length + 1) *
sizeof(Ch)));
2107 SetStringPointer(str);
2109 std::memcpy(str, s, s.length *
sizeof(Ch));
2110 str[s.length] =
'\0';
2114 void RawAssign(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
2117 rhs.data_.f.flags = kNullFlag;
2120 template <
typename SourceAllocator>
2121 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
2125 const SizeType len1 = GetStringLength();
2126 const SizeType len2 = rhs.GetStringLength();
2127 if(len1 != len2) {
return false; }
2129 const Ch*
const str1 = GetString();
2130 const Ch*
const str2 = rhs.GetString();
2131 if(str1 == str2) {
return true; }
2133 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
2153 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
2156 typedef typename Encoding::Ch
Ch;
2181 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2187 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2190 : ValueType(std::forward<ValueType>(rhs)),
2191 allocator_(rhs.allocator_),
2192 ownAllocator_(rhs.ownAllocator_),
2193 stack_(std::move(rhs.stack_)),
2194 parseResult_(rhs.parseResult_)
2197 rhs.ownAllocator_ = 0;
2202 ~GenericDocument() {
2206 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2208 GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
2212 ValueType::operator=(std::forward<ValueType>(rhs));
2217 allocator_ = rhs.allocator_;
2218 ownAllocator_ = rhs.ownAllocator_;
2219 stack_ = std::move(rhs.stack_);
2220 parseResult_ = rhs.parseResult_;
2223 rhs.ownAllocator_ = 0;
2224 rhs.parseResult_ = ParseResult();
2237 ValueType::Swap(rhs);
2238 stack_.Swap(rhs.stack_);
2239 internal::Swap(allocator_, rhs.allocator_);
2240 internal::Swap(ownAllocator_, rhs.ownAllocator_);
2241 internal::Swap(parseResult_, rhs.parseResult_);
2247 using ValueType::Swap;
2268 template <
typename Generator>
2270 ClearStackOnExit scope(*
this);
2273 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2288 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
2291 stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2292 ClearStackOnExit scope(*
this);
2293 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
2296 ValueType::operator=(*stack_.template Pop<ValueType>(1));
2307 template <
unsigned parseFlags,
typename InputStream>
2309 return ParseStream<parseFlags, Encoding, InputStream>(is);
2317 template <
typename InputStream>
2319 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2331 template <
unsigned parseFlags>
2334 return ParseStream<parseFlags | kParseInsituFlag>(s);
2342 return ParseInsitu<kParseDefaultFlags>(str);
2354 template <
unsigned parseFlags,
typename SourceEncoding>
2358 return ParseStream<parseFlags, SourceEncoding>(s);
2365 template <
unsigned parseFlags>
2367 return Parse<parseFlags, Encoding>(str);
2374 return Parse<kParseDefaultFlags>(str);
2377 template <
unsigned parseFlags,
typename SourceEncoding>
2378 GenericDocument& Parse(
const typename SourceEncoding::Ch* str,
size_t length) {
2380 MemoryStream ms(
reinterpret_cast<const char*
>(str), length *
sizeof(
typename SourceEncoding::Ch));
2382 ParseStream<parseFlags, SourceEncoding>(is);
2386 template <
unsigned parseFlags>
2387 GenericDocument& Parse(
const Ch* str,
size_t length) {
2388 return Parse<parseFlags, Encoding>(str, length);
2391 GenericDocument& Parse(
const Ch* str,
size_t length) {
2392 return Parse<kParseDefaultFlags>(str, length);
2395 #if RAPIDJSON_HAS_STDSTRING
2396 template <
unsigned parseFlags,
typename SourceEncoding>
2397 GenericDocument& Parse(
const std::basic_string<typename SourceEncoding::Ch>& str) {
2399 return Parse<parseFlags, SourceEncoding>(str.c_str());
2402 template <
unsigned parseFlags>
2403 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2404 return Parse<parseFlags, Encoding>(str.c_str());
2407 GenericDocument& Parse(
const std::basic_string<Ch>& str) {
2408 return Parse<kParseDefaultFlags>(str);
2452 struct ClearStackOnExit {
2454 ~ClearStackOnExit() { d_.ClearStack(); }
2456 ClearStackOnExit(
const ClearStackOnExit&);
2457 ClearStackOnExit& operator=(
const ClearStackOnExit&);
2458 GenericDocument& d_;
2463 template <
typename,
typename>
friend class GenericValue;
2467 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
2468 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
2469 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2470 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2471 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2472 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
2473 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
2475 bool RawNumber(
const Ch* str,
SizeType length,
bool copy) {
2477 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2479 new (stack_.template Push<ValueType>()) ValueType(str, length);
2483 bool String(
const Ch* str,
SizeType length,
bool copy) {
2485 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2487 new (stack_.template Push<ValueType>()) ValueType(str, length);
2491 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(
kObjectType);
return true; }
2493 bool Key(
const Ch* str,
SizeType length,
bool copy) {
return String(str, length, copy); }
2495 bool EndObject(
SizeType memberCount) {
2496 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2497 stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2501 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(
kArrayType);
return true; }
2503 bool EndArray(
SizeType elementCount) {
2504 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2505 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2511 GenericDocument(
const GenericDocument&);
2513 GenericDocument& operator=(
const GenericDocument&);
2516 if (Allocator::kNeedFree)
2517 while (stack_.GetSize() > 0)
2518 (stack_.template Pop<ValueType>(1))->~ValueType();
2521 stack_.ShrinkToFit();
2528 static const size_t kDefaultStackCapacity = 1024;
2531 internal::Stack<StackAllocator> stack_;
2532 ParseResult parseResult_;
2543 template <
bool Const,
typename ValueT>
2548 typedef ValueT PlainType;
2550 typedef ValueType* ValueIterator;
2551 typedef const ValueT* ConstValueIterator;
2552 typedef typename ValueType::AllocatorType AllocatorType;
2553 typedef typename ValueType::StringRefType StringRefType;
2555 template <
typename,
typename>
2562 SizeType Size()
const {
return value_.Size(); }
2563 SizeType Capacity()
const {
return value_.Capacity(); }
2564 bool Empty()
const {
return value_.Empty(); }
2565 void Clear()
const { value_.Clear(); }
2566 ValueType& operator[](
SizeType index)
const {
return value_[index]; }
2567 ValueIterator Begin()
const {
return value_.Begin(); }
2568 ValueIterator End()
const {
return value_.End(); }
2569 GenericArray Reserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.Reserve(newCapacity, allocator);
return *
this; }
2570 GenericArray PushBack(ValueType& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2571 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2572 GenericArray PushBack(ValueType&& value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2574 GenericArray PushBack(StringRefType value, AllocatorType& allocator)
const { value_.PushBack(value, allocator);
return *
this; }
2575 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; }
2576 GenericArray PopBack()
const { value_.PopBack();
return *
this; }
2577 ValueIterator Erase(ConstValueIterator pos)
const {
return value_.Erase(pos); }
2578 ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
const {
return value_.Erase(first, last); }
2580 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2581 ValueIterator begin()
const {
return value_.Begin(); }
2582 ValueIterator end()
const {
return value_.End(); }
2596 template <
bool Const,
typename ValueT>
2601 typedef ValueT PlainType;
2605 typedef typename ValueType::AllocatorType AllocatorType;
2606 typedef typename ValueType::StringRefType StringRefType;
2607 typedef typename ValueType::EncodingType EncodingType;
2608 typedef typename ValueType::Ch Ch;
2610 template <
typename,
typename>
2617 SizeType MemberCount()
const {
return value_.MemberCount(); }
2618 SizeType MemberCapacity()
const {
return value_.MemberCapacity(); }
2619 bool ObjectEmpty()
const {
return value_.ObjectEmpty(); }
2620 template <
typename T> ValueType& operator[](T* name)
const {
return value_[name]; }
2622 #if RAPIDJSON_HAS_STDSTRING
2623 ValueType& operator[](
const std::basic_string<Ch>& name)
const {
return value_[name]; }
2625 MemberIterator MemberBegin()
const {
return value_.MemberBegin(); }
2627 GenericObject MemberReserve(
SizeType newCapacity, AllocatorType &allocator)
const { value_.MemberReserve(newCapacity, allocator);
return *
this; }
2628 bool HasMember(
const Ch* name)
const {
return value_.HasMember(name); }
2629 #if RAPIDJSON_HAS_STDSTRING
2630 bool HasMember(
const std::basic_string<Ch>& name)
const {
return value_.HasMember(name); }
2633 MemberIterator FindMember(
const Ch* name)
const {
return value_.FindMember(name); }
2635 #if RAPIDJSON_HAS_STDSTRING
2636 MemberIterator FindMember(
const std::basic_string<Ch>& name)
const {
return value_.FindMember(name); }
2638 GenericObject AddMember(ValueType& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2639 GenericObject AddMember(ValueType& name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2640 #if RAPIDJSON_HAS_STDSTRING
2641 GenericObject AddMember(ValueType& name, std::basic_string<Ch>& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2643 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; }
2644 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2645 GenericObject AddMember(ValueType&& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2646 GenericObject AddMember(ValueType&& name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2647 GenericObject AddMember(ValueType& name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2648 GenericObject AddMember(StringRefType name, ValueType&& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2650 GenericObject AddMember(StringRefType name, ValueType& value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2651 GenericObject AddMember(StringRefType name, StringRefType value, AllocatorType& allocator)
const { value_.AddMember(name, value, allocator);
return *
this; }
2652 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; }
2653 void RemoveAllMembers() { value_.RemoveAllMembers(); }
2654 bool RemoveMember(
const Ch* name)
const {
return value_.RemoveMember(name); }
2655 #if RAPIDJSON_HAS_STDSTRING
2656 bool RemoveMember(
const std::basic_string<Ch>& name)
const {
return value_.RemoveMember(name); }
2662 bool EraseMember(
const Ch* name)
const {
return value_.EraseMember(name); }
2663 #if RAPIDJSON_HAS_STDSTRING
2664 bool EraseMember(
const std::basic_string<Ch>& name)
const {
return EraseMember(ValueType(
StringRef(name))); }
2668 #if RAPIDJSON_HAS_CXX11_RANGE_FOR
2679 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:2544
A document for parsing JSON text as DOM.
Definition: document.h:2154
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2261
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:2448
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:2289
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2157
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:2366
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:2158
GenericDocument & Populate(Generator &g)
Populate this document by a generator which produces SAX events.
Definition: document.h:2269
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: document.h:2418
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:2332
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2180
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:2156
GenericDocument(Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:2167
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:2373
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:2421
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2236
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:2318
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2442
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:2308
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2355
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:2341
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:2424
Name-value pair in a JSON object value.
Definition: document.h:66
GenericMember & operator=(GenericMember &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:88
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:69
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:68
(Constant) member iterator for a JSON object value
Definition: document.h:132
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:146
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:142
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:144
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:186
pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:158
reference Reference
Reference to (const) GenericMember.
Definition: document.h:160
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:224
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:168
difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:162
Helper class for accessing Value of object type.
Definition: document.h:2597
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: pointer.h:79
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:538
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:608
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:611
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:612
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:618
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition: document.h:930
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics.
Definition: document.h:954
ConstValueIterator Begin() const
Constant element iterator.
Definition: document.h:1633
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition: document.h:1663
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition: document.h:1539
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition: document.h:1526
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:1644
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:1808
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:769
bool ObjectEmpty() const
Check whether the object is empty.
Definition: document.h:1135
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:1590
MemberIterator FindMember(const std::basic_string< Ch > &name)
Find member by string object name.
Definition: document.h:1303
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1426
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition: document.h:1194
GenericValue & SetString(const std::basic_string< Ch > &s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1861
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition: document.h:1686
~GenericValue()
Destructor.
Definition: document.h:830
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:748
GenericValue & operator[](const std::basic_string< Ch > &name)
Get a value from an object associated with name (string object).
Definition: document.h:1185
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:787
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:615
GenericValue & SetBool(bool b)
Definition: document.h:1117
float GetFloat() const
Get the value as float type.
Definition: document.h:1787
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:1355
friend void swap(GenericValue &a, GenericValue &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:950
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:613
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition: document.h:1028
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:660
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:790
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition: document.h:1732
void RemoveAllMembers()
Remove all members in the object.
Definition: document.h:1459
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:617
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:781
GenericValue(Array a) RAPIDJSON_NOEXCEPT
Constructor for Array.
Definition: document.h:811
bool GetBool() const
Set boolean value.
Definition: document.h:1114
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition: document.h:1249
SizeType Size() const
Get the number of elements in array.
Definition: document.h:1593
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:1126
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:1596
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:796
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:802
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1412
GenericValue(Object o) RAPIDJSON_NOEXCEPT
Constructor for Object.
Definition: document.h:822
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:619
SizeType MemberCount() const
Get the number of members in the object.
Definition: document.h:1129
ValueIterator Begin()
Element iterator.
Definition: document.h:1627
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition: document.h:1284
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition: document.h:1147
GenericValue & MemberReserve(SizeType newCapacity, Allocator &allocator)
Request the object to have enough capacity to store members.
Definition: document.h:1208
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition: document.h:1744
MemberIterator MemberBegin()
Member iterator.
Definition: document.h:1197
bool HasMember(const std::basic_string< Ch > &name) const
Check whether a member exists in the object with string object.
Definition: document.h:1236
GenericValue & SetString(StringRefType s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1851
double GetDouble() const
Get the value as double type.
Definition: document.h:1775
void Clear()
Remove all elements in the array.
Definition: document.h:1605
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:1474
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition: document.h:1164
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:1225
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:1038
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition: document.h:1825
bool operator==(const T &rhs) const
Equal-to operator with primitive types.
Definition: document.h:1019
ValueIterator End()
Past-the-end element iterator
Definition: document.h:1630
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1317
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1843
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition: document.h:965
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:733
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:742
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition: document.h:1636
bool EraseMember(const Ch *name)
Erase a member in object by its name.
Definition: document.h:1560
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:616
bool Is() const
Templated version for checking whether this value is type T.
Definition: document.h:1874
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:754
bool Empty() const
Check whether the array is empty.
Definition: document.h:1599
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:630
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition: document.h:1263
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1340
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:620
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:1898
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition: document.h:1025
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Deep-copy assignment from Value.
Definition: document.h:918
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:793
MemberIterator MemberEnd()
Past-the-end member iterator
Definition: document.h:1200
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:1618
GenericValue(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
Explicit copy constructor (with allocator)
Definition: document.h:682
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:614
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:1043
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:1718
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1835
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types.
Definition: document.h:1033
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition: document.h:1191
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:866
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:886
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition: document.h:1007
bool operator==(const std::basic_string< Ch > &rhs) const
Equal-to operator with string object.
Definition: document.h:1013
SizeType MemberCapacity() const
Get the capacity of object.
Definition: document.h:1132
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition: document.h:1502
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:1818
GenericValue(float f) RAPIDJSON_NOEXCEPT
Constructor for float value.
Definition: document.h:784
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
Assertion (in non-throwing contexts).
Definition: rapidjson.h:637
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:463
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:476
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
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:384
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:148
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2140
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2536
Type
Type of JSON value.
Definition: rapidjson.h:663
@ kArrayType
array
Definition: rapidjson.h:668
@ kTrueType
true
Definition: rapidjson.h:666
@ kNullType
null
Definition: rapidjson.h:664
@ kFalseType
false
Definition: rapidjson.h:665
@ kNumberType
number
Definition: rapidjson.h:670
@ kObjectType
object
Definition: rapidjson.h:667
@ kStringType
string
Definition: rapidjson.h:669
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:432
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:650
#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(TypeName)
! customization point for global new
Definition: rapidjson.h:646
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:445
A read-write string stream.
Definition: stream.h:188
Reference to a constant string (not taking a copy)
Definition: document.h:286
const Ch *const s
plain CharType pointer
Definition: document.h:359
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:339
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)
Mark a character pointer as constant string.
Definition: document.h:414
CharType Ch
character type of the string
Definition: document.h:287
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:394
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:315
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:351
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition: document.h:360
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:432
Read-only string stream.
Definition: stream.h:154
Definition: document.h:2021
Definition: document.h:2025
Represents an in-memory input byte stream.
Definition: memorystream.h:40