15 #ifndef RAPIDJSON_DOCUMENT_H_ 16 #define RAPIDJSON_DOCUMENT_H_ 21 #include "internal/meta.h" 22 #include "internal/strfunc.h" 27 RAPIDJSON_DIAG_OFF(4127)
28 #elif defined(__GNUC__) 30 RAPIDJSON_DIAG_OFF(effc++)
36 #ifndef RAPIDJSON_HAS_STDSTRING 37 #ifdef RAPIDJSON_DOXYGEN_RUNNING 38 #define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation 40 #define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default 52 #endif // !defined(RAPIDJSON_HAS_STDSTRING) 54 #if RAPIDJSON_HAS_STDSTRING 56 #endif // RAPIDJSON_HAS_STDSTRING 58 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS 62 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 66 RAPIDJSON_NAMESPACE_BEGIN
69 template <
typename Encoding,
typename Allocator>
78 template <
typename Encoding,
typename Allocator>
87 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS 108 template <
bool Const,
typename Encoding,
typename Allocator>
110 :
public std::iterator<std::random_access_iterator_tag
111 , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
118 typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
161 Iterator& operator++(){ ++ptr_;
return *
this; }
162 Iterator& operator--(){ --ptr_;
return *
this; }
163 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
164 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
169 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
170 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
172 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
173 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
178 bool operator==(ConstIterator that)
const {
return ptr_ == that.ptr_; }
179 bool operator!=(ConstIterator that)
const {
return ptr_ != that.ptr_; }
180 bool operator<=(ConstIterator that)
const {
return ptr_ <= that.ptr_; }
181 bool operator>=(ConstIterator that)
const {
return ptr_ >= that.ptr_; }
182 bool operator< (ConstIterator that)
const {
return ptr_ < that.ptr_; }
183 bool operator> (ConstIterator that)
const {
return ptr_ > that.ptr_; }
188 Reference operator*()
const {
return *ptr_; }
189 Pointer operator->()
const {
return ptr_; }
190 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
194 DifferenceType
operator-(ConstIterator that)
const {
return ptr_-that.ptr_; }
203 #else // RAPIDJSON_NOMEMBERITERATORCLASS 207 template <
bool Const,
typename Encoding,
typename Allocator>
211 template <
typename Encoding,
typename Allocator>
217 template <
typename Encoding,
typename Allocator>
223 #endif // RAPIDJSON_NOMEMBERITERATORCLASS 255 template<
typename CharType>
284 : s(str), length(N-1) {}
319 operator const Ch *()
const {
return s; }
344 template<
typename CharType>
364 template<
typename CharType>
369 #if RAPIDJSON_HAS_STDSTRING 382 template<
typename CharType>
392 template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
393 struct IsGenericValueImpl : FalseType {};
396 template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>
::Type, typename Void<typename T::AllocatorType>
::Type>
397 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>
::Type {};
400 template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>
::Type {};
417 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
424 typedef typename Encoding::Ch
Ch;
438 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 441 rhs.flags_ = kNullFlag;
457 static const unsigned defaultFlags[7] = {
458 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
462 flags_ = defaultFlags[type];
466 data_.ss.SetLength(0);
476 template<
typename SourceAllocator >
485 #ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen 486 template <
typename T>
487 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<T,bool>))) RAPIDJSON_NOEXCEPT
491 : data_(), flags_(b ? kTrueFlag : kFalseFlag) {
497 explicit GenericValue(
int i) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberIntFlag) {
500 flags_ |= kUintFlag | kUint64Flag;
504 explicit GenericValue(
unsigned u) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberUintFlag) {
506 if (!(u & 0x80000000))
507 flags_ |= kIntFlag | kInt64Flag;
511 explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberInt64Flag) {
514 flags_ |= kNumberUint64Flag;
525 explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberUint64Flag) {
528 flags_ |= kInt64Flag;
536 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
542 explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_(), flags_() { SetStringRaw(s); }
550 #if RAPIDJSON_HAS_STDSTRING 554 GenericValue(
const std::basic_string<Ch>& s, Allocator& allocator) : data_(), flags_() { SetStringRaw(
StringRef(s), allocator); }
561 if (Allocator::kNeedFree) {
564 for (
GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
566 Allocator::Free(data_.a.elements);
570 for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
572 Allocator::Free(data_.o.members);
575 case kCopyStringFlag:
576 Allocator::Free(const_cast<Ch*>(data_.s.str));
600 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 603 return *
this = rhs.
Move();
629 template <
typename T>
630 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
642 template <
typename SourceAllocator>
657 temp.RawAssign(*
this);
659 other.RawAssign(temp);
675 template <
typename SourceAllocator>
678 if (GetType() != rhs.GetType())
683 if (data_.o.size != rhs.data_.o.size)
685 for (
ConstMemberIterator lhsMemberItr = MemberBegin(); lhsMemberItr != MemberEnd(); ++lhsMemberItr) {
686 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.
FindMember(lhsMemberItr->name);
687 if (rhsMemberItr == rhs.
MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
693 if (data_.a.size != rhs.data_.a.size)
695 for (
SizeType i = 0; i < data_.a.size; i++)
696 if ((*
this)[i] != rhs[i])
701 return StringEqual(rhs);
704 if (IsDouble() || rhs.IsDouble()) {
705 double a = GetDouble();
706 double b = rhs.GetDouble();
707 return a >= b && a <= b;
710 return data_.n.u64 == rhs.data_.n.u64;
720 #if RAPIDJSON_HAS_STDSTRING 730 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool))
operator==(
const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
735 template <
typename SourceAllocator>
739 bool operator!=(
const Ch* rhs)
const {
return !(*
this == rhs); }
744 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& rhs)
const {
return !(*
this == rhs); }
749 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator==(
const T& lhs,
const GenericValue& rhs) {
return rhs == lhs; }
754 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool))
operator!=(
const T& lhs,
const GenericValue& rhs) {
return !(rhs == lhs); }
760 Type GetType()
const {
return static_cast<Type>(flags_ & kTypeMask); }
761 bool IsNull()
const {
return flags_ == kNullFlag; }
762 bool IsFalse()
const {
return flags_ == kFalseFlag; }
763 bool IsTrue()
const {
return flags_ == kTrueFlag; }
764 bool IsBool()
const {
return (flags_ & kBoolFlag) != 0; }
765 bool IsObject()
const {
return flags_ == kObjectFlag; }
766 bool IsArray()
const {
return flags_ == kArrayFlag; }
767 bool IsNumber()
const {
return (flags_ & kNumberFlag) != 0; }
768 bool IsInt()
const {
return (flags_ & kIntFlag) != 0; }
769 bool IsUint()
const {
return (flags_ & kUintFlag) != 0; }
770 bool IsInt64()
const {
return (flags_ & kInt64Flag) != 0; }
771 bool IsUint64()
const {
return (flags_ & kUint64Flag) != 0; }
772 bool IsDouble()
const {
return (flags_ & kDoubleFlag) != 0; }
773 bool IsString()
const {
return (flags_ & kStringFlag) != 0; }
816 template <
typename T>
821 template <
typename T>
833 template <
typename SourceAllocator>
836 if (member != MemberEnd())
837 return member->value;
844 template <
typename SourceAllocator>
847 #if RAPIDJSON_HAS_STDSTRING 874 bool HasMember(
const Ch* name)
const {
return FindMember(name) != MemberEnd(); }
876 #if RAPIDJSON_HAS_STDSTRING 885 bool HasMember(
const std::basic_string<Ch>& name)
const {
return FindMember(name) != MemberEnd(); }
897 template <
typename SourceAllocator>
914 return FindMember(n);
932 template <
typename SourceAllocator>
937 for ( ; member != MemberEnd(); ++member)
938 if (name.StringEqual(member->name))
944 #if RAPIDJSON_HAS_STDSTRING 971 if (o.size >= o.capacity) {
972 if (o.capacity == 0) {
973 o.capacity = kDefaultObjectCapacity;
974 o.members =
reinterpret_cast<Member*
>(allocator.Malloc(o.capacity *
sizeof(
Member)));
978 o.capacity += (oldCapacity + 1) / 2;
979 o.members =
reinterpret_cast<Member*
>(allocator.Realloc(o.members, oldCapacity *
sizeof(
Member), o.capacity *
sizeof(
Member)));
982 o.members[o.size].
name.RawAssign(name);
983 o.members[o.size].value.RawAssign(value);
999 return AddMember(name, v, allocator);
1002 #if RAPIDJSON_HAS_STDSTRING 1014 return AddMember(name, v, allocator);
1035 template <
typename T>
1036 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1039 return AddMember(name, v, allocator);
1042 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 1044 return AddMember(name, value, allocator);
1047 return AddMember(name, value, allocator);
1050 return AddMember(name, value, allocator);
1054 return AddMember(n, value, allocator);
1056 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS 1071 return AddMember(n, value, allocator);
1085 return AddMember(name, v, allocator);
1105 template <
typename T>
1106 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1109 return AddMember(n, value, allocator);
1133 return RemoveMember(n);
1136 #if RAPIDJSON_HAS_STDSTRING 1137 bool RemoveMember(
const std::basic_string<Ch>& name) {
return RemoveMember(
GenericValue(
StringRef(name))); }
1140 template <
typename SourceAllocator>
1143 if (m != MemberEnd()) {
1166 if (data_.o.size > 1 && m != last) {
1188 return EraseMember(pos, pos +1);
1211 std::memmove(&*pos, &*last, (MemberEnd() - last) *
sizeof(
Member));
1212 data_.o.size -= (last - first);
1240 for (
SizeType i = 0; i < data_.a.size; ++i)
1241 data_.a.elements[i].~GenericValue();
1253 return data_.a.elements[index];
1278 if (newCapacity > data_.a.capacity) {
1280 data_.a.capacity = newCapacity;
1297 if (data_.a.size >= data_.a.capacity)
1298 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1299 data_.a.elements[data_.a.size++].RawAssign(value);
1303 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 1305 return PushBack(value, allocator);
1307 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS 1319 return (*this).template PushBack<StringRefType>(value, allocator);
1339 template <
typename T>
1340 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1341 PushBack(T value, Allocator& allocator) {
1343 return PushBack(v, allocator);
1353 data_.a.elements[--data_.a.size].~GenericValue();
1365 return Erase(pos, pos + 1);
1386 std::memmove(pos, last, (End() - last) *
sizeof(
GenericValue));
1387 data_.a.size -= (last - first);
1396 int GetInt()
const {
RAPIDJSON_ASSERT(flags_ & kIntFlag);
return data_.n.i.i; }
1397 unsigned GetUint()
const {
RAPIDJSON_ASSERT(flags_ & kUintFlag);
return data_.n.u.u; }
1398 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(flags_ & kInt64Flag);
return data_.n.i64; }
1399 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(flags_ & kUint64Flag);
return data_.n.u64; }
1401 double GetDouble()
const {
1403 if ((flags_ & kDoubleFlag) != 0)
return data_.n.d;
1404 if ((flags_ & kIntFlag) != 0)
return data_.n.i.i;
1405 if ((flags_ & kUintFlag) != 0)
return data_.n.u.u;
1406 if ((flags_ & kInt64Flag) != 0)
return (
double)data_.n.i64;
1421 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return ((flags_ & kInlineStrFlag) ? data_.ss.str : data_.s.str); }
1463 #if RAPIDJSON_HAS_STDSTRING 1483 template <
typename Handler>
1488 case kTrueType:
return handler.Bool(
true);
1491 if (!handler.StartObject())
1495 if (!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.flags_ & kCopyFlag) != 0))
1497 if (!m->value.Accept(handler))
1500 return handler.EndObject(data_.o.size);
1503 if (!handler.StartArray())
1505 for (
GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
1506 if (!v->Accept(handler))
1508 return handler.EndArray(data_.a.size);
1511 return handler.String(GetString(), GetStringLength(), (flags_ & kCopyFlag) != 0);
1515 if (IsInt())
return handler.Int(data_.n.i.i);
1516 else if (IsUint())
return handler.Uint(data_.n.u.u);
1517 else if (IsInt64())
return handler.Int64(data_.n.i64);
1518 else if (IsUint64())
return handler.Uint64(data_.n.u64);
1519 else return handler.Double(data_.n.d);
1524 template <
typename,
typename>
friend class GenericValue;
1529 kNumberFlag = 0x200,
1532 kInt64Flag = 0x1000,
1533 kUint64Flag = 0x2000,
1534 kDoubleFlag = 0x4000,
1535 kStringFlag = 0x100000,
1536 kCopyFlag = 0x200000,
1537 kInlineStrFlag = 0x400000,
1543 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1544 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1545 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1546 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1547 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1548 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1550 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1551 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1558 static const SizeType kDefaultArrayCapacity = 16;
1559 static const SizeType kDefaultObjectCapacity = 16;
1575 struct ShortString {
1576 enum { MaxChars =
sizeof(String) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1579 inline static bool Usable(
SizeType len) {
return (MaxSize >= len); }
1580 inline void SetLength(
SizeType len) { str[LenPos] = (Ch)(MaxSize - len); }
1581 inline SizeType GetLength()
const {
return (
SizeType)(MaxSize - str[LenPos]); }
1586 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN 1632 flags_ = kArrayFlag;
1635 std::memcpy(data_.a.elements, values, count *
sizeof(
GenericValue));
1638 data_.a.elements = NULL;
1639 data_.a.size = data_.a.capacity = count;
1643 void SetObjectRaw(
Member* members,
SizeType count, Allocator& allocator) {
1644 flags_ = kObjectFlag;
1646 data_.o.members = (
Member*)allocator.Malloc(count *
sizeof(
Member));
1647 std::memcpy(data_.o.members, members, count *
sizeof(
Member));
1650 data_.o.members = NULL;
1651 data_.o.size = data_.o.capacity = count;
1656 flags_ = kConstStringFlag;
1664 if(ShortString::Usable(s.
length)) {
1665 flags_ = kShortStringFlag;
1666 data_.ss.SetLength(s.
length);
1669 flags_ = kCopyStringFlag;
1670 data_.s.length = s.
length;
1671 str = (Ch *)allocator.Malloc((s.
length + 1) *
sizeof(Ch));
1674 std::memcpy(str, s, s.
length *
sizeof(Ch));
1681 flags_ = rhs.flags_;
1682 rhs.flags_ = kNullFlag;
1685 template <
typename SourceAllocator>
1690 const SizeType len1 = GetStringLength();
1692 if(len1 != len2) {
return false; }
1694 const Ch*
const str1 = GetString();
1695 const Ch*
const str2 = rhs.GetString();
1696 if(str1 == str2) {
return true; }
1698 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
1719 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
1722 typedef typename Encoding::Ch
Ch;
1731 GenericDocument(Allocator* allocator = 0,
size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
1732 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
1738 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 1741 : ValueType(std::move(rhs)),
1742 allocator_(rhs.allocator_),
1743 ownAllocator_(rhs.ownAllocator_),
1744 stack_(std::move(rhs.stack_)),
1745 parseResult_(rhs.parseResult_)
1748 rhs.ownAllocator_ = 0;
1757 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 1763 ValueType::operator=(std::forward<ValueType>(rhs));
1768 allocator_ = rhs.allocator_;
1769 ownAllocator_ = rhs.ownAllocator_;
1770 stack_ = std::move(rhs.stack_);
1771 parseResult_ = rhs.parseResult_;
1774 rhs.ownAllocator_ = 0;
1791 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
1793 ValueType::SetNull();
1795 ClearStackOnExit scope(*
this);
1796 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
1799 this->RawAssign(*stack_.template Pop<ValueType>(1));
1810 template <
unsigned parseFlags,
typename InputStream>
1812 return ParseStream<parseFlags, Encoding, InputStream>(is);
1820 template <
typename InputStream>
1822 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
1834 template <
unsigned parseFlags>
1837 return ParseStream<parseFlags | kParseInsituFlag>(s);
1845 return ParseInsitu<kParseDefaultFlags>(str);
1857 template <
unsigned parseFlags,
typename SourceEncoding>
1861 return ParseStream<parseFlags, SourceEncoding>(s);
1868 template <
unsigned parseFlags>
1870 return Parse<parseFlags, Encoding>(str);
1877 return Parse<kParseDefaultFlags>(str);
1903 struct ClearStackOnExit {
1905 ~ClearStackOnExit() { d_.ClearStack(); }
1907 ClearStackOnExit(
const ClearStackOnExit&);
1908 ClearStackOnExit& operator=(
const ClearStackOnExit&);
1913 template <
typename,
typename,
typename>
friend class GenericReader;
1914 template <
typename,
typename>
friend class GenericValue;
1917 bool Null() {
new (stack_.template Push<ValueType>()) ValueType();
return true; }
1918 bool Bool(
bool b) {
new (stack_.template Push<ValueType>()) ValueType(b);
return true; }
1919 bool Int(
int i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
1920 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
1921 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
1922 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>()) ValueType(i);
return true; }
1923 bool Double(
double d) {
new (stack_.template Push<ValueType>()) ValueType(d);
return true; }
1925 bool String(
const Ch* str,
SizeType length,
bool copy) {
1927 new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
1929 new (stack_.template Push<ValueType>()) ValueType(str, length);
1933 bool StartObject() {
new (stack_.template Push<ValueType>()) ValueType(
kObjectType);
return true; }
1935 bool Key(
const Ch* str,
SizeType length,
bool copy) {
return String(str, length, copy); }
1937 bool EndObject(
SizeType memberCount) {
1938 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
1939 stack_.template Top<ValueType>()->SetObjectRaw(members, (
SizeType)memberCount, GetAllocator());
1943 bool StartArray() {
new (stack_.template Push<ValueType>()) ValueType(
kArrayType);
return true; }
1945 bool EndArray(
SizeType elementCount) {
1946 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
1947 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
1958 if (Allocator::kNeedFree)
1959 while (stack_.GetSize() > 0)
1960 (stack_.template Pop<ValueType>(1))->~ValueType();
1963 stack_.ShrinkToFit();
1970 static const size_t kDefaultStackCapacity = 1024;
1971 Allocator* allocator_;
1972 Allocator* ownAllocator_;
1973 internal::Stack<StackAllocator> stack_;
1981 template <
typename Encoding,
typename Allocator>
1982 template <
typename SourceAllocator>
1986 switch (rhs.GetType()) {
1991 RawAssign(*d.stack_.template Pop<GenericValue>(1));
1995 if (rhs.flags_ == kConstStringFlag) {
1996 flags_ = rhs.flags_;
1997 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2003 flags_ = rhs.flags_;
2004 data_ = *
reinterpret_cast<const Data*
>(&rhs.data_);
2008 RAPIDJSON_NAMESPACE_END
2010 #if defined(_MSC_VER) || defined(__GNUC__) 2014 #endif // RAPIDJSON_DOCUMENT_H_ BaseType::difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:133
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:1723
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:504
true
Definition: rapidjson.h:645
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition: document.h:1376
Definition: document.h:1587
Read-only string stream.
Definition: rapidjson.h:571
Concept for receiving events from GenericReader upon parsing. The functions return true if no error o...
GenericValue & Move() RAPIDJSON_NOEXCEPT
Prepare Value for move semantics.
Definition: document.h:665
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition: document.h:676
ValueIterator Begin()
Element iterator.
Definition: document.h:1259
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:124
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:545
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:511
bool operator==(const std::basic_string< Ch > &rhs) const
Equal-to operator with string object.
Definition: document.h:724
~GenericValue()
Destructor.
Definition: document.h:560
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:261
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:374
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:1821
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:542
GenericValue & SetString(const std::basic_string< Ch > &s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1471
bool HasMember(const std::basic_string< Ch > &name) const
Check whether a member exists in the object with string object.
Definition: document.h:885
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:799
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:425
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:122
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:593
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition: document.h:718
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:322
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:126
SizeType Size() const
Get the number of elements in array.
Definition: document.h:1226
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:1724
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition: document.h:933
false
Definition: rapidjson.h:644
ParseErrorCode
Error code of parsing.
Definition: error.h:59
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition: document.h:858
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:375
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:548
friend bool operator!=(const T &lhs, const GenericValue &rhs)
Not-Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:754
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:1131
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)
Mark a string object as constant string.
Definition: document.h:383
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:1350
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:1276
ValueIterator End()
Past-the-end element iterator
Definition: document.h:1262
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition: document.h:739
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:1876
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition: document.h:1159
MemberIterator MemberBegin()
Member iterator.
Definition: document.h:861
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:423
bool Empty() const
Check whether the array is empty.
Definition: document.h:1232
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:1083
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition: document.h:855
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:1012
GenericValue & operator[](const std::basic_string< Ch > &name)
Get a value from an object associated with name (string object).
Definition: document.h:849
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:539
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition: document.h:834
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1453
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition: document.h:1187
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:315
Name-value pair in a JSON object value.
Definition: document.h:79
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:1436
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:1844
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition: document.h:322
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:1891
BaseType::reference Reference
Reference to (const) GenericMember.
Definition: document.h:131
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:429
MemberIterator FindMember(const std::basic_string< Ch > &name)
Find member by string object name.
Definition: document.h:952
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:966
Result of parsing (wraps ParseErrorCode)
Definition: error.h:101
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:1792
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition: document.h:912
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition: document.h:898
void Clear()
Remove all elements in the array.
Definition: document.h:1238
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:1869
friend bool operator==(const T &lhs, const GenericValue &rhs)
Equal-to operator with arbitrary types (symmetric version)
Definition: document.h:749
Type
Type of JSON value.
Definition: rapidjson.h:642
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:1722
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:1250
BaseType::pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:129
object
Definition: rapidjson.h:646
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition: document.h:1295
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition: document.h:817
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition: document.h:655
MemberIterator MemberEnd()
Past-the-end member iterator
Definition: document.h:864
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:283
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:554
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition: rapidjson.h:480
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:456
A document for parsing JSON text as DOM.
Definition: document.h:1720
array
Definition: rapidjson.h:647
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:428
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:484
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:424
Definition: document.h:1591
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:426
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:489
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:497
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:81
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:436
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:305
SizeType MemberCount() const
Get the number of members in the object.
Definition: document.h:802
null
Definition: rapidjson.h:643
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:1731
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:1888
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:194
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:80
string
Definition: rapidjson.h:648
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:1896
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:421
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:1811
CharType Ch
character type of the string
Definition: document.h:257
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:422
bool ObjectEmpty() const
Check whether the object is empty.
Definition: document.h:805
bool GetBool() const
Set boolean value.
Definition: document.h:787
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition: document.h:1443
void RemoveAllMembers()
Remove all members in the object.
Definition: document.h:1116
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:157
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:612
In-situ(destructive) parsing.
Definition: reader.h:138
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition: document.h:1885
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:1229
Reference to a constant string (not taking a copy)
Definition: document.h:256
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:536
GenericValue & SetBool(bool b)
Definition: document.h:790
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition: document.h:1268
bool operator==(const T &rhs) const
Equal-to operator with primitive types.
Definition: document.h:730
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:70
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1706
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Deep-copy assignment from Value.
Definition: document.h:643
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:1223
(Constant) member iterator for a JSON object value
Definition: document.h:109
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1461
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:1484
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition: document.h:1200
const Ch *const s
plain CharType pointer
Definition: document.h:321
ConstValueIterator Begin() const
Constant element iterator.
Definition: document.h:1265
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:427
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:139
GenericValue & AddMember(GenericValue &name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:997
GenericValue< Encoding, Allocator > ValueType
Value type of itself.
Definition: document.h:430
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition: document.h:1318
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:1069
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:874
bool operator!=(const T &rhs) const
Not-equal-to operator with arbitrary types.
Definition: document.h:744
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:1978
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:525
number
Definition: rapidjson.h:649
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:1426
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition: document.h:736
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:1835
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:1899
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition: document.h:1364
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:1858
A read-write string stream.
Definition: rapidjson.h:605