21 #ifndef RAPIDJSON_DOCUMENT_H_
22 #define RAPIDJSON_DOCUMENT_H_
27 #include "internal/meta.h"
28 #include "internal/strfunc.h"
33 RAPIDJSON_DIAG_OFF(4127)
34 #elif defined(__GNUC__)
36 RAPIDJSON_DIAG_OFF(effc++)
42 #ifndef RAPIDJSON_HAS_STDSTRING
43 #ifdef RAPIDJSON_DOXYGEN_RUNNING
44 #define RAPIDJSON_HAS_STDSTRING 1 // force generation of documentation
46 #define RAPIDJSON_HAS_STDSTRING 0 // no std::string support by default
59 #endif // RAPIDJSON_HAS_STDSTRING
61 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
65 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
72 template <
typename Encoding,
typename Allocator>
81 template <
typename Encoding,
typename Allocator>
90 #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
111 template <
bool Const,
typename Encoding,
typename Allocator>
113 :
public std::iterator<std::random_access_iterator_tag
114 , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
121 typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
164 Iterator& operator++(){ ++ptr_;
return *
this; }
165 Iterator& operator--(){ --ptr_;
return *
this; }
166 Iterator operator++(
int){ Iterator old(*
this); ++ptr_;
return old; }
167 Iterator operator--(
int){ Iterator old(*
this); --ptr_;
return old; }
172 Iterator operator+(DifferenceType n)
const {
return Iterator(ptr_+n); }
173 Iterator operator-(DifferenceType n)
const {
return Iterator(ptr_-n); }
175 Iterator& operator+=(DifferenceType n) { ptr_+=n;
return *
this; }
176 Iterator& operator-=(DifferenceType n) { ptr_-=n;
return *
this; }
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_; }
184 bool operator>=(ConstIterator that)
const {
return ptr_ >= that.ptr_; }
185 bool operator< (ConstIterator that)
const {
return ptr_ < that.ptr_; }
186 bool operator> (ConstIterator that)
const {
return ptr_ > that.ptr_; }
191 Reference operator*()
const {
return *ptr_; }
192 Pointer operator->()
const {
return ptr_; }
193 Reference operator[](DifferenceType n)
const {
return ptr_[n]; }
197 DifferenceType
operator-(ConstIterator that)
const {
return ptr_-that.ptr_; }
206 #else // RAPIDJSON_NOMEMBERITERATORCLASS
210 template <
bool Const,
typename Encoding,
typename Allocator>
211 struct GenericMemberIterator;
214 template <
typename Encoding,
typename Allocator>
215 struct GenericMemberIterator<false,Encoding,Allocator> {
217 typedef GenericMember<Encoding,Allocator>*
Iterator;
220 template <
typename Encoding,
typename Allocator>
221 struct GenericMemberIterator<true,Encoding,Allocator> {
223 typedef const GenericMember<Encoding,Allocator>*
Iterator;
226 #endif // RAPIDJSON_NOMEMBERITERATORCLASS
258 template<
typename CharType>
322 operator const Ch *()
const {
return s; }
347 template<
typename CharType>
367 template<
typename CharType>
372 #if RAPIDJSON_HAS_STDSTRING
385 template<
typename CharType>
395 template <
typename T,
typename Encoding =
void,
typename Allocator =
void>
396 struct IsGenericValueImpl : FalseType {};
399 template <
typename T>
struct IsGenericValueImpl<T, typename Void<typename T::EncodingType>
::Type, typename Void<typename T::AllocatorType>
::Type>
400 : IsBaseOf<GenericValue<typename T::EncodingType, typename T::AllocatorType>, T>
::Type {};
403 template <
typename T>
struct IsGenericValue : IsGenericValueImpl<T>
::Type {};
420 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<> >
427 typedef typename Encoding::Ch
Ch;
440 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
443 rhs.flags_ = kNullFlag;
459 static const unsigned defaultFlags[7] = {
460 kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
464 flags_ = defaultFlags[type];
474 template<
typename SourceAllocator >
483 #ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
484 template <
typename T>
485 explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<T,bool>))) RAPIDJSON_NOEXCEPT
489 : data_(), flags_(b ? kTrueFlag : kFalseFlag) {
495 explicit GenericValue(
int i) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberIntFlag) {
498 flags_ |= kUintFlag | kUint64Flag;
502 explicit GenericValue(
unsigned u) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberUintFlag) {
504 if (!(u & 0x80000000))
505 flags_ |= kIntFlag | kInt64Flag;
509 explicit GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberInt64Flag) {
512 flags_ |= kNumberUint64Flag;
523 explicit GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberUint64Flag) {
526 flags_ |= kInt64Flag;
534 explicit GenericValue(
double d) RAPIDJSON_NOEXCEPT : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
540 explicit GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT : data_(), flags_() { SetStringRaw(s); }
548 #if RAPIDJSON_HAS_STDSTRING
559 if (Allocator::kNeedFree) {
562 for (
GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
564 Allocator::Free(data_.a.elements);
570 Allocator::Free(data_.o.members);
573 case kCopyStringFlag:
574 Allocator::Free(const_cast<Ch*>(data_.s.str));
598 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
601 return *
this = rhs.
Move();
627 template <
typename T>
628 RAPIDJSON_DISABLEIF_RETURN((internal::IsPointer<T>), (
GenericValue&))
640 template <
typename SourceAllocator>
655 temp.RawAssign(*
this);
657 other.RawAssign(temp);
673 template <
typename SourceAllocator>
676 if (GetType() != rhs.GetType())
681 if (data_.o.size != rhs.data_.o.size)
683 for (ConstMemberIterator lhsMemberItr =
MemberBegin(); lhsMemberItr !=
MemberEnd(); ++lhsMemberItr) {
684 typename RhsType::ConstMemberIterator rhsMemberItr = rhs.FindMember(lhsMemberItr->name);
685 if (rhsMemberItr == rhs.MemberEnd() || lhsMemberItr->value != rhsMemberItr->value)
691 if (data_.a.size != rhs.data_.a.size)
693 for (
SizeType i = 0; i < data_.a.size; i++)
694 if ((*
this)[i] != rhs[i])
699 return StringEqual(rhs);
702 if (IsDouble() || rhs.IsDouble())
703 return GetDouble() == rhs.GetDouble();
705 return data_.n.u64 == rhs.data_.n.u64;
715 #if RAPIDJSON_HAS_STDSTRING
725 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>,internal::IsGenericValue<T> >), (
bool)) operator==(const T& rhs)
const {
return *
this ==
GenericValue(rhs); }
730 template <
typename SourceAllocator>
734 bool operator!=(
const Ch* rhs)
const {
return !(*
this == rhs); }
739 template <
typename T> RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool)) operator!=(const T& rhs)
const {
return !(*
this == rhs); }
744 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool)) operator==(const T& lhs, const
GenericValue& rhs) {
return rhs == lhs; }
749 template <
typename T>
friend RAPIDJSON_DISABLEIF_RETURN((internal::IsGenericValue<T>), (
bool)) operator!=(const T& lhs, const
GenericValue& rhs) {
return !(rhs == lhs); }
755 Type GetType()
const {
return static_cast<Type>(flags_ & kTypeMask); }
756 bool IsNull()
const {
return flags_ == kNullFlag; }
757 bool IsFalse()
const {
return flags_ == kFalseFlag; }
758 bool IsTrue()
const {
return flags_ == kTrueFlag; }
759 bool IsBool()
const {
return (flags_ & kBoolFlag) != 0; }
760 bool IsObject()
const {
return flags_ == kObjectFlag; }
761 bool IsArray()
const {
return flags_ == kArrayFlag; }
762 bool IsNumber()
const {
return (flags_ & kNumberFlag) != 0; }
763 bool IsInt()
const {
return (flags_ & kIntFlag) != 0; }
764 bool IsUint()
const {
return (flags_ & kUintFlag) != 0; }
765 bool IsInt64()
const {
return (flags_ & kInt64Flag) != 0; }
766 bool IsUint64()
const {
return (flags_ & kUint64Flag) != 0; }
767 bool IsDouble()
const {
return (flags_ & kDoubleFlag) != 0; }
768 bool IsString()
const {
return (flags_ & kStringFlag) != 0; }
811 template <
typename T>
816 template <
typename T>
828 template <
typename SourceAllocator>
832 return member->value;
839 template <
typename SourceAllocator>
874 template <
typename SourceAllocator>
909 template <
typename SourceAllocator>
915 if (name.StringEqual(member->name))
936 if (o.size >= o.capacity) {
937 if (o.capacity == 0) {
938 o.capacity = kDefaultObjectCapacity;
939 o.members =
reinterpret_cast<Member*
>(allocator.Malloc(o.capacity *
sizeof(Member)));
943 o.capacity += (oldCapacity + 1) / 2;
944 o.members =
reinterpret_cast<Member*
>(allocator.Realloc(o.members, oldCapacity *
sizeof(Member), o.capacity *
sizeof(Member)));
947 o.members[o.size].name.RawAssign(name);
948 o.members[o.size].value.RawAssign(value);
953 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
955 return AddMember(name, value, allocator);
958 return AddMember(name, value, allocator);
961 return AddMember(name, value, allocator);
967 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1016 template <
typename T>
1017 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1048 template <
typename SourceAllocator>
1073 MemberIterator last(data_.o.members + (data_.o.size - 1));
1074 if (data_.o.size > 1 && m != last) {
1108 MemberIterator
EraseMember(ConstMemberIterator first, ConstMemberIterator last) {
1117 for (MemberIterator itr = pos; itr != last; ++itr)
1119 std::memmove(&*pos, &*last, (
MemberEnd() - last) *
sizeof(Member));
1120 data_.o.size -= (last - first);
1148 for (
SizeType i = 0; i < data_.a.size; ++i)
1149 data_.a.elements[i].~GenericValue();
1161 return data_.a.elements[index];
1186 if (newCapacity > data_.a.capacity) {
1188 data_.a.capacity = newCapacity;
1205 if (data_.a.size >= data_.a.capacity)
1206 Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
1207 data_.a.elements[data_.a.size++].RawAssign(value);
1211 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1215 #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
1227 return (*this).template PushBack<StringRefType>(value, allocator);
1247 template <
typename T>
1248 RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (
GenericValue&))
1261 data_.a.elements[--data_.a.size].~GenericValue();
1272 ValueIterator
Erase(ConstValueIterator pos) {
1273 return Erase(pos, pos + 1);
1284 ValueIterator
Erase(ConstValueIterator first, ConstValueIterator last) {
1291 ValueIterator pos =
Begin() + (first -
Begin());
1292 for (ValueIterator itr = pos; itr != last; ++itr)
1295 data_.a.size -= (last - first);
1304 int GetInt()
const {
RAPIDJSON_ASSERT(flags_ & kIntFlag);
return data_.n.i.i; }
1305 unsigned GetUint()
const {
RAPIDJSON_ASSERT(flags_ & kUintFlag);
return data_.n.u.u; }
1306 int64_t GetInt64()
const {
RAPIDJSON_ASSERT(flags_ & kInt64Flag);
return data_.n.i64; }
1307 uint64_t GetUint64()
const {
RAPIDJSON_ASSERT(flags_ & kUint64Flag);
return data_.n.u64; }
1309 double GetDouble()
const {
1311 if ((flags_ & kDoubleFlag) != 0)
return data_.n.d;
1312 if ((flags_ & kIntFlag) != 0)
return data_.n.i.i;
1313 if ((flags_ & kUintFlag) != 0)
return data_.n.u.u;
1314 if ((flags_ & kInt64Flag) != 0)
return (
double)data_.n.i64;
1329 const Ch* GetString()
const {
RAPIDJSON_ASSERT(IsString());
return ((flags_ & kInlineStrFlag) ? data_.ss.str : data_.s.str); }
1371 #if RAPIDJSON_HAS_STDSTRING
1391 template <
typename Handler>
1396 case kTrueType:
return handler.Bool(
true);
1399 if (!handler.StartObject())
1402 if (!handler.Key(m->name.GetString(), m->name.GetStringLength(), (m->name.flags_ & kCopyFlag) != 0))
1404 if (!m->value.Accept(handler))
1407 return handler.EndObject(data_.o.size);
1410 if (!handler.StartArray())
1412 for (
GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
1413 if (!v->Accept(handler))
1415 return handler.EndArray(data_.a.size);
1418 return handler.String(GetString(),
GetStringLength(), (flags_ & kCopyFlag) != 0);
1421 if (IsInt())
return handler.Int(data_.n.i.i);
1422 else if (IsUint())
return handler.Uint(data_.n.u.u);
1423 else if (IsInt64())
return handler.Int64(data_.n.i64);
1424 else if (IsUint64())
return handler.Uint64(data_.n.u64);
1425 else return handler.Double(data_.n.d);
1434 template <
typename,
typename>
friend class GenericValue;
1439 kNumberFlag = 0x200,
1442 kInt64Flag = 0x1000,
1443 kUint64Flag = 0x2000,
1444 kDoubleFlag = 0x4000,
1445 kStringFlag = 0x100000,
1446 kCopyFlag = 0x200000,
1447 kInlineStrFlag = 0x400000,
1453 kNumberIntFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag,
1454 kNumberUintFlag =
kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag,
1455 kNumberInt64Flag =
kNumberType | kNumberFlag | kInt64Flag,
1456 kNumberUint64Flag =
kNumberType | kNumberFlag | kUint64Flag,
1457 kNumberDoubleFlag =
kNumberType | kNumberFlag | kDoubleFlag,
1458 kNumberAnyFlag =
kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag,
1460 kCopyStringFlag =
kStringType | kStringFlag | kCopyFlag,
1461 kShortStringFlag =
kStringType | kStringFlag | kCopyFlag | kInlineStrFlag,
1468 static const SizeType kDefaultArrayCapacity = 16;
1469 static const SizeType kDefaultObjectCapacity = 16;
1485 struct ShortString {
1486 enum { MaxChars =
sizeof(String) /
sizeof(Ch), MaxSize = MaxChars - 1, LenPos = MaxSize };
1489 inline static bool Usable(
SizeType len) {
return (MaxSize >= len); }
1490 inline void SetLength(
SizeType len) { str[LenPos] = (
Ch)(MaxSize - len); }
1491 inline SizeType GetLength()
const {
return (
SizeType)(MaxSize - str[LenPos]); }
1496 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
1542 flags_ = kArrayFlag;
1544 std::memcpy(data_.a.elements, values, count *
sizeof(
GenericValue));
1545 data_.a.size = data_.a.capacity = count;
1549 void SetObjectRaw(Member* members,
SizeType count, Allocator& allocator) {
1550 flags_ = kObjectFlag;
1551 data_.o.members = (Member*)allocator.Malloc(count *
sizeof(Member));
1552 std::memcpy(data_.o.members, members, count *
sizeof(Member));
1553 data_.o.size = data_.o.capacity = count;
1557 void SetStringRaw(StringRefType s) RAPIDJSON_NOEXCEPT {
1558 flags_ = kConstStringFlag;
1560 data_.s.length = s.length;
1564 void SetStringRaw(StringRefType s, Allocator& allocator) {
1566 if(ShortString::Usable(s.length)) {
1567 flags_ = kShortStringFlag;
1568 data_.ss.SetLength(s.length);
1571 flags_ = kCopyStringFlag;
1572 data_.s.length = s.length;
1573 str = (Ch *)allocator.Malloc((s.length + 1) *
sizeof(Ch));
1576 std::memcpy(str, s, s.length *
sizeof(Ch));
1577 str[s.length] =
'\0';
1583 flags_ = rhs.flags_;
1584 rhs.flags_ = kNullFlag;
1587 template <
typename SourceAllocator>
1588 bool StringEqual(
const GenericValue<Encoding, SourceAllocator>& rhs)
const {
1593 const SizeType len2 = rhs.GetStringLength();
1594 if(len1 != len2) {
return false; }
1596 const Ch*
const str1 = GetString();
1597 const Ch*
const str2 = rhs.GetString();
1598 if(str1 == str2) {
return true; }
1600 return (std::memcmp(str1, str2,
sizeof(Ch) * len1) == 0);
1621 template <
typename Encoding,
typename Allocator = MemoryPoolAllocator<>,
typename StackAllocator = CrtAllocator>
1624 typedef typename Encoding::Ch
Ch;
1634 allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
1640 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1643 : ValueType(std::move(rhs)),
1644 allocator_(rhs.allocator_),
1645 ownAllocator_(rhs.ownAllocator_),
1646 stack_(std::move(rhs.stack_)),
1647 parseResult_(rhs.parseResult_)
1650 rhs.ownAllocator_ = 0;
1659 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1670 allocator_ = rhs.allocator_;
1671 ownAllocator_ = rhs.ownAllocator_;
1672 stack_ = std::move(rhs.stack_);
1673 parseResult_ = rhs.parseResult_;
1676 rhs.ownAllocator_ = 0;
1677 rhs.parseResult_ = ParseResult();
1693 template <
unsigned parseFlags,
typename SourceEncoding,
typename InputStream>
1695 ValueType::SetNull();
1697 ClearStackOnExit scope(*
this);
1698 parseResult_ = reader.template Parse<parseFlags>(is, *
this);
1701 this->RawAssign(*stack_.template Pop<ValueType>(1));
1712 template <
unsigned parseFlags,
typename InputStream>
1714 return ParseStream<parseFlags,Encoding,InputStream>(is);
1722 template <
typename InputStream>
1724 return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
1737 template <
unsigned parseFlags,
typename SourceEncoding>
1740 return ParseStream<parseFlags | kParseInsituFlag, SourceEncoding>(s);
1748 template <
unsigned parseFlags>
1750 return ParseInsitu<parseFlags, Encoding>(str);
1758 return ParseInsitu<kParseDefaultFlags, Encoding>(str);
1770 template <
unsigned parseFlags,
typename SourceEncoding>
1774 return ParseStream<parseFlags, SourceEncoding>(s);
1781 template <
unsigned parseFlags>
1783 return Parse<parseFlags, Encoding>(str);
1790 return Parse<kParseDefaultFlags>(str);
1816 struct ClearStackOnExit {
1818 ~ClearStackOnExit() { d_.ClearStack(); }
1820 ClearStackOnExit(
const ClearStackOnExit&);
1821 ClearStackOnExit& operator=(
const ClearStackOnExit&);
1826 template <
typename,
typename,
typename>
friend class GenericReader;
1827 template <
typename,
typename>
friend class GenericValue;
1830 bool Null() {
new (stack_.template Push<ValueType>())
ValueType();
return true; }
1831 bool Bool(
bool b) {
new (stack_.template Push<ValueType>())
ValueType(b);
return true; }
1832 bool Int(
int i) {
new (stack_.template Push<ValueType>())
ValueType(i);
return true; }
1833 bool Uint(
unsigned i) {
new (stack_.template Push<ValueType>())
ValueType(i);
return true; }
1834 bool Int64(int64_t i) {
new (stack_.template Push<ValueType>())
ValueType(i);
return true; }
1835 bool Uint64(uint64_t i) {
new (stack_.template Push<ValueType>())
ValueType(i);
return true; }
1836 bool Double(
double d) {
new (stack_.template Push<ValueType>())
ValueType(d);
return true; }
1838 bool String(
const Ch* str,
SizeType length,
bool copy) {
1842 new (stack_.template Push<ValueType>())
ValueType(str, length);
1846 bool StartObject() {
new (stack_.template Push<ValueType>())
ValueType(
kObjectType);
return true; }
1848 bool Key(
const Ch* str,
SizeType length,
bool copy) {
return String(str, length, copy); }
1850 bool EndObject(
SizeType memberCount) {
1851 typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
1852 stack_.template Top<ValueType>()->SetObjectRaw(members, (
SizeType)memberCount,
GetAllocator());
1856 bool StartArray() {
new (stack_.template Push<ValueType>())
ValueType(
kArrayType);
return true; }
1858 bool EndArray(
SizeType elementCount) {
1859 ValueType* elements = stack_.template Pop<ValueType>(elementCount);
1860 stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount,
GetAllocator());
1869 if (Allocator::kNeedFree)
1870 while (stack_.GetSize() > 0)
1871 (stack_.template Pop<ValueType>(1))->~
ValueType();
1874 stack_.ShrinkToFit();
1881 static const size_t kDefaultStackCapacity = 1024;
1882 Allocator* allocator_;
1883 Allocator* ownAllocator_;
1884 internal::Stack<StackAllocator> stack_;
1885 ParseResult parseResult_;
1892 template <
typename Encoding,
typename Allocator>
1893 template <
typename SourceAllocator>
1899 RawAssign(*d.stack_.template Pop<GenericValue>(1));
1904 #if defined(_MSC_VER) || defined(__GNUC__)
1908 #endif // RAPIDJSON_DOCUMENT_H_
BaseType::difference_type DifferenceType
Signed integer type (e.g. ptrdiff_t)
Definition: document.h:136
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:1625
GenericValue(unsigned u) RAPIDJSON_NOEXCEPT
Constructor for unsigned value.
Definition: document.h:502
true
Definition: rapidjson.h:570
ValueIterator Erase(ConstValueIterator first, ConstValueIterator last)
Remove elements in the range [first, last) of the array.
Definition: document.h:1284
Definition: document.h:1497
Read-only string stream.
Definition: rapidjson.h:496
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:663
ValueIterator Begin()
Element iterator.
Definition: document.h:1167
GenericMemberIterator< true, Encoding, Allocator > ConstIterator
Constant iterator type.
Definition: document.h:127
DifferenceType operator-(ConstIterator that) const
Distance.
Definition: document.h:197
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:543
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with Encoding conversion)
Definition: document.h:1738
GenericValue(int64_t i64) RAPIDJSON_NOEXCEPT
Constructor for int64_t value.
Definition: document.h:509
~GenericValue()
Destructor.
Definition: document.h:558
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:186
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:363
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with kParseDefaultFlags)
Definition: document.h:1723
GenericValue(StringRefType s) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:540
GenericValue & SetString(const std::basic_string< Ch > &s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1379
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:794
GenericStringRef< Ch > StringRefType
Reference to a constant string.
Definition: document.h:428
GenericMemberIterator Iterator
Iterator type itself.
Definition: document.h:125
ConstMemberIterator MemberBegin() const
Const member iterator.
Definition: document.h:844
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:591
ConstMemberIterator MemberEnd() const
Const past-the-end member iterator.
Definition: document.h:847
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:247
GenericMemberIterator< false, Encoding, Allocator > NonConstIterator
Non-constant iterator type.
Definition: document.h:129
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:1626
MemberIterator FindMember(const GenericValue< Encoding, SourceAllocator > &name)
Find member by name.
Definition: document.h:910
bool ObjectEmpty() const
Check whether the object is empty.
Definition: document.h:800
false
Definition: rapidjson.h:569
ParseErrorCode
Error code of parsing.
Definition: error.h:63
bool operator!=(const GenericValue< Encoding, SourceAllocator > &rhs) const
Not-equal-to operator.
Definition: document.h:731
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:301
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:546
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:1043
bool Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:1392
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:1258
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:1184
ValueIterator End()
Past-the-end element iterator
Definition: document.h:1170
bool IsError() const
Whether the result is an error.
Definition: error.h:120
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with kParseDefaultFlags)
Definition: document.h:1789
bool GetBool() const
Set boolean value.
Definition: document.h:782
MemberIterator RemoveMember(MemberIterator m)
Remove a member in object by iterator.
Definition: document.h:1067
MemberIterator MemberBegin()
Member iterator.
Definition: document.h:850
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:426
GenericValue & AddMember(StringRefType name, StringRefType value, Allocator &allocator)
Add a constant string value as member (name-value pair) to the object.
Definition: document.h:994
GenericValue(const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:537
GenericValue & operator[](const GenericValue< Encoding, SourceAllocator > &name)
Get a value from an object associated with the name.
Definition: document.h:829
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1361
MemberIterator EraseMember(ConstMemberIterator pos)
Remove a member from an object by iterator.
Definition: document.h:1095
GenericStringRef(const CharType *str, SizeType len)
Create constant string reference from pointer and length.
Definition: document.h:318
bool operator==(const std::basic_string< Ch > &rhs) const
Equal-to operator with string object.
Definition: document.h:719
Name-value pair in a JSON object value.
Definition: document.h:82
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:1344
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string (with kParseDefaultFlags)
Definition: document.h:1757
SizeType Size() const
Get the number of elements in array.
Definition: document.h:1134
const SizeType length
length of the string (excluding the trailing NULL terminator)
Definition: document.h:325
BaseType::reference Reference
Reference to (const) GenericMember.
Definition: document.h:134
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:432
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: document.h:1804
Concept for encoding of Unicode characters.
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:931
Result of parsing (wraps ParseErrorCode)
Definition: error.h:105
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition: document.h:1694
MemberIterator FindMember(const Ch *name)
Find member by name.
Definition: document.h:889
ConstValueIterator Begin() const
Constant element iterator.
Definition: document.h:1173
void Clear()
Remove all elements in the array.
Definition: document.h:1146
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string.
Definition: document.h:348
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:1782
Type
Type of JSON value.
Definition: rapidjson.h:567
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:1624
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:1158
BaseType::pointer Pointer
Pointer to (const) GenericMember.
Definition: document.h:132
ParseErrorCode GetParseError() const
Get the ParseErrorCode of last parsing.
Definition: document.h:1801
object
Definition: rapidjson.h:571
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a GenericValue at the end of the array.
Definition: document.h:1203
GenericValue & operator[](T *name)
Get a value from an object associated with the name.
Definition: document.h:812
GenericValue & Swap(GenericValue &other) RAPIDJSON_NOEXCEPT
Exchange the contents of this value with those of other.
Definition: document.h:653
MemberIterator MemberEnd()
Past-the-end member iterator
Definition: document.h:853
GenericStringRef(const CharType(&str)[N]) RAPIDJSON_NOEXCEPT
Create string reference from const character array.
Definition: document.h:286
bool operator!=(const Ch *rhs) const
Not-equal-to operator with const C-string pointer.
Definition: document.h:734
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:552
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition: rapidjson.h:408
GenericValue(Type type) RAPIDJSON_NOEXCEPT
Constructor with JSON value type.
Definition: document.h:458
A document for parsing JSON text as DOM.
Definition: document.h:1622
array
Definition: rapidjson.h:572
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:431
bool operator==(const GenericValue< Encoding, SourceAllocator > &rhs) const
Equal-to operator.
Definition: document.h:674
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:412
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:427
Definition: document.h:1501
main RapidJSON namespace
Definition: rapidjson.h:241
GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
Member iterator for iterating in object.
Definition: document.h:429
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:1812
GenericValue(bool b) RAPIDJSON_NOEXCEPT
Constructor for boolean value.
Definition: document.h:487
GenericValue(int i) RAPIDJSON_NOEXCEPT
Constructor for int value.
Definition: document.h:495
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:84
GenericValue() RAPIDJSON_NOEXCEPT
Default constructor creates a null value.
Definition: document.h:438
ParseErrorCode Code() const
Get the error code.
Definition: error.h:113
GenericStringRef(const CharType *str)
Explicitly create string reference from const character pointer.
Definition: document.h:308
null
Definition: rapidjson.h:568
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
Constructor.
Definition: document.h:1633
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:83
string
Definition: rapidjson.h:573
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:1809
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:424
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream.
Definition: document.h:1713
SizeType MemberCount() const
Get the number of members in the object.
Definition: document.h:797
CharType Ch
character type of the string
Definition: document.h:260
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:425
bool HasMember(const GenericValue< Encoding, SourceAllocator > &name) const
Check whether a member exists in the object with GenericValue name.
Definition: document.h:875
GenericValue & SetString(StringRefType s)
Set this value as a string without copying source string.
Definition: document.h:1351
void RemoveAllMembers()
Remove all members in the object.
Definition: document.h:1028
GenericMemberIterator(const NonConstIterator &it)
Iterator conversions to more const.
Definition: document.h:160
GenericValue & operator=(StringRefType str) RAPIDJSON_NOEXCEPT
Assignment of constant string reference (no copy)
Definition: document.h:610
bool operator==(const Ch *rhs) const
Equal-to operator with const C-string pointer.
Definition: document.h:713
In-situ(destructive) parsing.
Definition: reader.h:129
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:863
bool Empty() const
Check whether the array is empty.
Definition: document.h:1140
Reference to a constant string (not taking a copy)
Definition: document.h:259
GenericValue(double d) RAPIDJSON_NOEXCEPT
Constructor for double value.
Definition: document.h:534
GenericValue & SetBool(bool b)
Definition: document.h:785
Concept for allocating, resizing and freeing memory block.
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:73
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1608
GenericValue & CopyFrom(const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
Deep-copy assignment from Value.
Definition: document.h:641
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:115
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:1131
(Constant) member iterator for a JSON object value
Definition: document.h:112
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:1369
MemberIterator EraseMember(ConstMemberIterator first, ConstMemberIterator last)
Remove members in the range [first, last) from an object.
Definition: document.h:1108
const Ch *const s
plain CharType pointer
Definition: document.h:324
GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:430
ConstValueIterator End() const
Constant past-the-end element iterator.
Definition: document.h:1176
GenericMemberIterator()
Default constructor (singular value)
Definition: document.h:142
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:1137
GenericValue & PushBack(StringRefType value, Allocator &allocator)
Append a constant string reference at the end of the array.
Definition: document.h:1226
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition: document.h:1798
GenericValue & AddMember(StringRefType name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:980
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:269
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:1889
GenericValue(uint64_t u64) RAPIDJSON_NOEXCEPT
Constructor for uint64_t value.
Definition: document.h:523
number
Definition: rapidjson.h:574
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:1749
ValueIterator Erase(ConstValueIterator pos)
Remove an element of array by iterator.
Definition: document.h:1272
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:1771
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:1334
A read-write string stream.
Definition: rapidjson.h:530