document.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef RAPIDJSON_DOCUMENT_H_
27 #define RAPIDJSON_DOCUMENT_H_
28 
29 #include "reader.h"
30 #include "internal/strfunc.h"
31 #include <new> // placement new
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable : 4127) // conditional expression is constant
36 #endif
37 
38 namespace rapidjson {
39 
41 // GenericValue
42 
44 
53 #pragma pack (push, 4)
54 template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
55 class GenericValue {
56 public:
58  struct Member {
61  };
62 
65  typedef typename Encoding::Ch Ch;
67  typedef const Member* ConstMemberIterator;
70 
72 
73 
76 
78 private:
80 
81 public:
82 
84 
89  static const unsigned defaultFlags[7] = {
92  };
94  flags_ = defaultFlags[type];
95  memset(&data_, 0, sizeof(data_));
96  }
97 
100 
103  data_.n.i64 = i;
104  if (i >= 0)
106  }
107 
110  data_.n.u64 = u;
111  if (!(u & 0x80000000))
113  }
114 
117  data_.n.i64 = i64;
118  if (i64 >= 0) {
120  if (!(i64 & 0xFFFFFFFF00000000LL))
121  flags_ |= kUintFlag;
122  if (!(i64 & 0xFFFFFFFF80000000LL))
123  flags_ |= kIntFlag;
124  }
125  else if (i64 >= -2147483648LL)
126  flags_ |= kIntFlag;
127  }
128 
131  data_.n.u64 = u64;
132  if (!(u64 & 0x8000000000000000ULL))
133  flags_ |= kInt64Flag;
134  if (!(u64 & 0xFFFFFFFF00000000ULL))
135  flags_ |= kUintFlag;
136  if (!(u64 & 0xFFFFFFFF80000000ULL))
137  flags_ |= kIntFlag;
138  }
139 
142 
144  GenericValue(const Ch* s, SizeType length) {
145  RAPIDJSON_ASSERT(s != NULL);
147  data_.s.str = s;
148  data_.s.length = length;
149  }
150 
153 
155  GenericValue(const Ch* s, SizeType length, Allocator& allocator) { SetStringRaw(s, length, allocator); }
156 
158  GenericValue(const Ch*s, Allocator& allocator) { SetStringRaw(s, internal::StrLen(s), allocator); }
159 
161 
164  if (Allocator::kNeedFree) { // Shortcut by Allocator's trait
165  switch(flags_) {
166  case kArrayFlag:
167  for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
168  v->~GenericValue();
169  Allocator::Free(data_.a.elements);
170  break;
171 
172  case kObjectFlag:
173  for (Member* m = data_.o.members; m != data_.o.members + data_.o.size; ++m) {
174  m->name.~GenericValue();
175  m->value.~GenericValue();
176  }
177  Allocator::Free(data_.o.members);
178  break;
179 
180  case kCopyStringFlag:
181  Allocator::Free(const_cast<Ch*>(data_.s.str));
182  break;
183  }
184  }
185  }
186 
188 
190 
191 
193 
196  RAPIDJSON_ASSERT(this != &rhs);
197  this->~GenericValue();
198  memcpy(this, &rhs, sizeof(GenericValue));
199  rhs.flags_ = kNull_Flag;
200  return *this;
201  }
202 
204 
207  template <typename T>
209  this->~GenericValue();
210  new (this) GenericValue(value);
211  return *this;
212  }
214 
216 
217 
218  Type GetType() const { return static_cast<Type>(flags_ & kTypeMask); }
219  bool IsNull_() const { return flags_ == kNull_Flag; }
220  bool IsFalse() const { return flags_ == kFalseFlag; }
221  bool IsTrue() const { return flags_ == kTrueFlag; }
222  bool IsBool_() const { return (flags_ & kBool_Flag) != 0; }
223  bool IsObject() const { return flags_ == kObjectFlag; }
224  bool IsArray() const { return flags_ == kArrayFlag; }
225  bool IsNumber() const { return (flags_ & kNumberFlag) != 0; }
226  bool IsInt() const { return (flags_ & kIntFlag) != 0; }
227  bool IsUint() const { return (flags_ & kUintFlag) != 0; }
228  bool IsInt64() const { return (flags_ & kInt64Flag) != 0; }
229  bool IsUint64() const { return (flags_ & kUint64Flag) != 0; }
230  bool IsDouble() const { return (flags_ & kDoubleFlag) != 0; }
231  bool IsString() const { return (flags_ & kStringFlag) != 0; }
232 
234 
236 
237 
238  GenericValue& SetNull_() { this->~GenericValue(); new (this) GenericValue(); return *this; }
239 
241 
243 
244 
245  bool GetBool_() const { RAPIDJSON_ASSERT(IsBool_()); return flags_ == kTrueFlag; }
246  GenericValue& SetBool_(bool b) { this->~GenericValue(); new (this) GenericValue(b); return *this; }
247 
249 
251 
252 
254  GenericValue& SetObject() { this->~GenericValue(); new (this) GenericValue(kObjectType); return *this; }
255 
258  if (Member* member = FindMember(name))
259  return member->value;
260  else {
261  static GenericValue Null_Value;
262  return Null_Value;
263  }
264  }
265  const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; }
266 
272 
274  bool HasMember(const Ch* name) const { return FindMember(name) != 0; }
275 
277 
285  RAPIDJSON_ASSERT(name.IsString());
286  Object& o = data_.o;
287  if (o.size >= o.capacity) {
288  if (o.capacity == 0) {
290  o.members = (Member*)allocator.Malloc(o.capacity * sizeof(Member));
291  }
292  else {
293  SizeType oldCapacity = o.capacity;
294  o.capacity *= 2;
295  o.members = (Member*)allocator.Realloc(o.members, oldCapacity * sizeof(Member), o.capacity * sizeof(Member));
296  }
297  }
298  o.members[o.size].name.RawAssign(name);
299  o.members[o.size].value.RawAssign(value);
300  o.size++;
301  return *this;
302  }
303 
304  GenericValue& AddMember(const Ch* name, Allocator& nameAllocator, GenericValue& value, Allocator& allocator) {
305  GenericValue n(name, internal::StrLen(name), nameAllocator);
306  return AddMember(n, value, allocator);
307  }
308 
309  GenericValue& AddMember(const Ch* name, GenericValue& value, Allocator& allocator) {
311  return AddMember(n, value, allocator);
312  }
313 
314  template <typename T>
315  GenericValue& AddMember(const Ch* name, T value, Allocator& allocator) {
317  GenericValue v(value);
318  return AddMember(n, v, allocator);
319  }
320 
322 
326  bool RemoveMember(const Ch* name) {
328  if (Member* m = FindMember(name)) {
331 
332  Member* last = data_.o.members + (data_.o.size - 1);
333  if (data_.o.size > 1 && m != last) {
334  // Move the last one to this place
335  m->name = last->name;
336  m->value = last->value;
337  }
338  else {
339  // Only one left, just destroy
340  m->name.~GenericValue();
341  m->value.~GenericValue();
342  }
343  --data_.o.size;
344  return true;
345  }
346  return false;
347  }
348 
350 
352 
353 
355  GenericValue& SetArray() { this->~GenericValue(); new (this) GenericValue(kArrayType); return *this; }
356 
358  SizeType Size() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size; }
359 
362 
364  bool Empty() const { RAPIDJSON_ASSERT(IsArray()); return data_.a.size == 0; }
365 
367 
369  void Clear() {
371  for (SizeType i = 0; i < data_.a.size; ++i)
372  data_.a.elements[i].~GenericValue();
373  data_.a.size = 0;
374  }
375 
377 
389  RAPIDJSON_ASSERT(index < data_.a.size);
390  return data_.a.elements[index];
391  }
392  const GenericValue& operator[](SizeType index) const { return const_cast<GenericValue&>(*this)[index]; }
393 
397  ConstValueIterator Begin() const { return const_cast<GenericValue&>(*this).Begin(); }
398  ConstValueIterator End() const { return const_cast<GenericValue&>(*this).End(); }
399 
401 
405  GenericValue& Reserve(SizeType newCapacity, Allocator &allocator) {
407  if (newCapacity > data_.a.capacity) {
408  data_.a.elements = (GenericValue*)allocator.Realloc(data_.a.elements, data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue));
409  data_.a.capacity = newCapacity;
410  }
411  return *this;
412  }
413 
415 
423  if (data_.a.size >= data_.a.capacity)
424  Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : data_.a.capacity * 2, allocator);
425  data_.a.elements[data_.a.size++].RawAssign(value);
426  return *this;
427  }
428 
429  template <typename T>
430  GenericValue& PushBack(T value, Allocator& allocator) {
431  GenericValue v(value);
432  return PushBack(v, allocator);
433  }
434 
439  data_.a.elements[--data_.a.size].~GenericValue();
440  return *this;
441  }
443 
445 
446 
447  int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i.i; }
448  unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u.u; }
449  int64_t GetInt64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.i64; }
450  uint64_t GetUint64() const { RAPIDJSON_ASSERT(flags_ & kUint64Flag); return data_.n.u64; }
451 
452  double GetDouble() const {
454  if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
455  if ((flags_ & kIntFlag) != 0) return data_.n.i.i; // int -> double
456  if ((flags_ & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
457  if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision)
458  RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision)
459  }
460 
461  GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; }
462  GenericValue& SetUint(unsigned u) { this->~GenericValue(); new (this) GenericValue(u); return *this; }
463  GenericValue& SetInt64(int64_t i64) { this->~GenericValue(); new (this) GenericValue(i64); return *this; }
464  GenericValue& SetUint64(uint64_t u64) { this->~GenericValue(); new (this) GenericValue(u64); return *this; }
465  GenericValue& SetDouble(double d) { this->~GenericValue(); new (this) GenericValue(d); return *this; }
466 
468 
470 
471 
472  const Ch* GetString() const { RAPIDJSON_ASSERT(IsString()); return data_.s.str; }
473 
475 
478 
480 
485  GenericValue& SetString(const Ch* s, SizeType length) { this->~GenericValue(); SetStringRaw(s, length); return *this; }
486 
488 
491  GenericValue& SetString(const Ch* s) { return SetString(s, internal::StrLen(s)); }
492 
494 
500  GenericValue& SetString(const Ch* s, SizeType length, Allocator& allocator) { this->~GenericValue(); SetStringRaw(s, length, allocator); return *this; }
501 
503 
507  GenericValue& SetString(const Ch* s, Allocator& allocator) { SetString(s, internal::StrLen(s), allocator); return *this; }
508 
510 
512 
518  template <typename Handler>
519  const GenericValue& Accept(Handler& handler) const {
520  switch(GetType()) {
521  case kNull_Type: handler.Null_(); break;
522  case kFalseType: handler.Bool_(false); break;
523  case kTrueType: handler.Bool_(true); break;
524 
525  case kObjectType:
526  handler.StartObject();
527  for (Member* m = data_.o.members; m != data_.o.members + data_.o.size; ++m) {
528  handler.String(m->name.data_.s.str, m->name.data_.s.length, false);
529  m->value.Accept(handler);
530  }
531  handler.EndObject(data_.o.size);
532  break;
533 
534  case kArrayType:
535  handler.StartArray();
536  for (GenericValue* v = data_.a.elements; v != data_.a.elements + data_.a.size; ++v)
537  v->Accept(handler);
538  handler.EndArray(data_.a.size);
539  break;
540 
541  case kStringType:
542  handler.String(data_.s.str, data_.s.length, false);
543  break;
544 
545  case kNumberType:
546  if (IsInt()) handler.Int(data_.n.i.i);
547  else if (IsUint()) handler.Uint(data_.n.u.u);
548  else if (IsInt64()) handler.Int64(data_.n.i64);
549  else if (IsUint64()) handler.Uint64(data_.n.u64);
550  else handler.Double(data_.n.d);
551  break;
552  }
553  return *this;
554  }
555 
556 private:
557  template <typename, typename>
558  friend class GenericDocument;
559 
560  enum {
561  kBool_Flag = 0x100,
562  kNumberFlag = 0x200,
563  kIntFlag = 0x400,
564  kUintFlag = 0x800,
565  kInt64Flag = 0x1000,
566  kUint64Flag = 0x2000,
567  kDoubleFlag = 0x4000,
568  kStringFlag = 0x100000,
569  kCopyFlag = 0x200000,
570 
571  // Initial flags of different types.
584 
585  kTypeMask = 0xFF // bitwise-and with mask of 0xFF can be optimized by compiler
586  };
587 
588  static const SizeType kDefaultArrayCapacity = 16;
589  static const SizeType kDefaultObjectCapacity = 16;
590 
591  struct String {
592  const Ch* str;
594  unsigned hashcode;
595  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
596 
597  // By using proper binary layout, retrieval of different integer types do not need conversions.
598  union Number {
599 #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
600  struct I {
601  int i;
602  char padding[4];
603  }i;
604  struct U {
605  unsigned u;
606  char padding2[4];
607  }u;
608 #else
609  struct I {
610  char padding[4];
611  int i;
612  }i;
613  struct U {
614  char padding2[4];
615  unsigned u;
616  }u;
617 #endif
618  int64_t i64;
619  uint64_t u64;
620  double d;
621  }; // 8 bytes
622 
623  struct Object {
627  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
628 
629  struct Array {
633  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
634 
635  union Data {
640  }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode
641 
646 
647  SizeType length = internal::StrLen(name);
648 
649  Object& o = data_.o;
650  for (Member* member = o.members; member != data_.o.members + data_.o.size; ++member)
651  if (length == member->name.data_.s.length && memcmp(member->name.data_.s.str, name, length * sizeof(Ch)) == 0)
652  return member;
653 
654  return 0;
655  }
656  const Member* FindMember(const Ch* name) const { return const_cast<GenericValue&>(*this).FindMember(name); }
657 
658  // Initialize this value as array with initial data, without calling destructor.
659  void SetArrayRaw(GenericValue* values, SizeType count, Allocator& alloctaor) {
660  flags_ = kArrayFlag;
661  data_.a.elements = (GenericValue*)alloctaor.Malloc(count * sizeof(GenericValue));
662  memcpy(data_.a.elements, values, count * sizeof(GenericValue));
663  data_.a.size = data_.a.capacity = count;
664  }
665 
667  void SetObjectRaw(Member* members, SizeType count, Allocator& alloctaor) {
669  data_.o.members = (Member*)alloctaor.Malloc(count * sizeof(Member));
670  memcpy(data_.o.members, members, count * sizeof(Member));
671  data_.o.size = data_.o.capacity = count;
672  }
673 
675  void SetStringRaw(const Ch* s, SizeType length) {
676  RAPIDJSON_ASSERT(s != NULL);
678  data_.s.str = s;
679  data_.s.length = length;
680  }
681 
683  void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
684  RAPIDJSON_ASSERT(s != NULL);
686  data_.s.str = (Ch *)allocator.Malloc((length + 1) * sizeof(Ch));
687  data_.s.length = length;
688  memcpy(const_cast<Ch*>(data_.s.str), s, length * sizeof(Ch));
689  const_cast<Ch*>(data_.s.str)[length] = '\0';
690  }
691 
693  void RawAssign(GenericValue& rhs) {
694  memcpy(this, &rhs, sizeof(GenericValue));
695  rhs.flags_ = kNull_Flag;
696  }
697 
699  unsigned flags_;
700 };
701 #pragma pack (pop)
702 
705 
707 // GenericDocument
708 
710 
715 template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
716 class GenericDocument : public GenericValue<Encoding, Allocator> {
717 public:
718  typedef typename Encoding::Ch Ch;
721 
723 
726  GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {}
727 
729 
733  template <unsigned parseFlags, typename Stream>
735  ValueType::SetNull_(); // Remove existing root if exist
737  if (reader.template Parse<parseFlags>(stream, *this)) {
738  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
739  this->RawAssign(*stack_.template Pop<ValueType>(1)); // Add this-> to prevent issue 13.
740  parseError_ = 0;
741  errorOffset_ = 0;
742  }
743  else {
744  parseError_ = reader.GetParseError();
745  errorOffset_ = reader.GetErrorOffset();
746  ClearStack();
747  }
748  return *this;
749  }
750 
752 
756  template <unsigned parseFlags>
759  return ParseStream<parseFlags | kParseInsituFlag>(s);
760  }
761 
763 
766  template <unsigned parseFlags>
767  GenericDocument& Parse(const Ch* str) {
768  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
770  return ParseStream<parseFlags>(s);
771  }
772 
774  bool HasParseError() const { return parseError_ != 0; }
775 
777  const char* GetParseError() const { return parseError_; }
778 
780  size_t GetErrorOffset() const { return errorOffset_; }
781 
783  Allocator& GetAllocator() { return stack_.GetAllocator(); }
784 
786  size_t GetStackCapacity() const { return stack_.GetCapacity(); }
787 
788 private:
789  // Prohibit assignment
791 
792  friend class GenericReader<Encoding, Allocator>; // for Reader to call the following private handler functions
793 
794  // Implementation of Handler
795  void Null_() { new (stack_.template Push<ValueType>()) ValueType(); }
796  void Bool_(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); }
797  void Int(int i) { new (stack_.template Push<ValueType>()) ValueType(i); }
798  void Uint(unsigned i) { new (stack_.template Push<ValueType>()) ValueType(i); }
799  void Int64(int64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); }
800  void Uint64(uint64_t i) { new (stack_.template Push<ValueType>()) ValueType(i); }
801  void Double(double d) { new (stack_.template Push<ValueType>()) ValueType(d); }
802 
803  void String(const Ch* str, SizeType length, bool copy) {
804  if (copy)
805  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
806  else
807  new (stack_.template Push<ValueType>()) ValueType(str, length);
808  }
809 
810  void StartObject() { new (stack_.template Push<ValueType>()) ValueType(kObjectType); }
811 
812  void EndObject(SizeType memberCount) {
813  typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
814  stack_.template Top<ValueType>()->SetObjectRaw(members, (SizeType)memberCount, GetAllocator());
815  }
816 
817  void StartArray() { new (stack_.template Push<ValueType>()) ValueType(kArrayType); }
818 
819  void EndArray(SizeType elementCount) {
820  ValueType* elements = stack_.template Pop<ValueType>(elementCount);
821  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
822  }
823 
824  void ClearStack() {
825  if (Allocator::kNeedFree)
826  while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
827  (stack_.template Pop<ValueType>(1))->~ValueType();
828  else
829  stack_.Clear();
830  }
831 
832  static const size_t kDefaultStackCapacity = 1024;
834  const char* parseError_;
835  size_t errorOffset_;
836 };
837 
839 
840 } // namespace rapidjson
841 
842 #ifdef _MSC_VER
843 #pragma warning(pop)
844 #endif
845 
846 #endif // RAPIDJSON_DOCUMENT_H_
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
A document for parsing JSON text as DOM.
Definition: document.h:716
void EndArray(SizeType elementCount)
Definition: document.h:819
size_t GetStackCapacity() const
Get the capacity of stack in bytes.
Definition: document.h:786
void String(const Ch *str, SizeType length, bool copy)
Definition: document.h:803
GenericDocument & ParseInsitu(Ch *str)
Parse JSON text from a mutable string.
Definition: document.h:757
internal::Stack< Allocator > stack_
Definition: document.h:833
void ClearStack()
Definition: document.h:824
void Uint(unsigned i)
Definition: document.h:798
const char * parseError_
Definition: document.h:834
size_t GetErrorOffset() const
Get the offset in character of the parsing error.
Definition: document.h:780
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:720
bool HasParseError() const
Whether a parse error was occured in the last parsing.
Definition: document.h:774
const char * GetParseError() const
Get the message of parsing error.
Definition: document.h:777
void Int(int i)
Definition: document.h:797
size_t errorOffset_
Definition: document.h:835
void Bool_(bool b)
Definition: document.h:796
GenericDocument & Parse(const Ch *str)
Parse JSON text from a read-only string.
Definition: document.h:767
void EndObject(SizeType memberCount)
Definition: document.h:812
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:718
static const size_t kDefaultStackCapacity
Definition: document.h:832
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:719
void Double(double d)
Definition: document.h:801
void Null_()
Definition: document.h:795
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:783
void StartObject()
Definition: document.h:810
void Int64(int64_t i)
Definition: document.h:799
GenericDocument & ParseStream(Stream &stream)
Parse JSON text from an input stream.
Definition: document.h:734
GenericDocument & operator=(const GenericDocument &)
GenericDocument(Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity)
Constructor.
Definition: document.h:726
void StartArray()
Definition: document.h:817
void Uint64(uint64_t i)
Definition: document.h:800
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: reader.h:231
const char * GetParseError() const
Definition: reader.h:286
size_t GetErrorOffset() const
Definition: reader.h:287
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:55
int64_t GetInt64() const
Definition: document.h:449
Encoding EncodingType
Encoding type from template parameter.
Definition: document.h:63
GenericValue * ValueIterator
Value iterator for iterating in array.
Definition: document.h:68
ConstValueIterator Begin() const
Definition: document.h:397
const GenericValue & operator[](const Ch *name) const
Definition: document.h:265
bool IsString() const
Definition: document.h:231
GenericValue & SetUint(unsigned u)
Definition: document.h:462
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a value at the end of the array.
Definition: document.h:421
GenericValue()
Default constructor creates a null value.
Definition: document.h:75
GenericValue & Reserve(SizeType newCapacity, Allocator &allocator)
Request the array to have enough capacity to store elements.
Definition: document.h:405
SizeType GetStringLength() const
Get the length of string.
Definition: document.h:477
bool IsTrue() const
Definition: document.h:221
const GenericValue & operator[](SizeType index) const
Definition: document.h:392
GenericValue & SetArray()
Set this value as an empty array.
Definition: document.h:355
GenericValue & SetInt64(int64_t i64)
Definition: document.h:463
bool GetBool_() const
Definition: document.h:245
Member * FindMember(const Ch *name)
Find member by name.
Definition: document.h:643
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &alloctaor)
Definition: document.h:659
ConstMemberIterator MemberEnd() const
Definition: document.h:269
GenericValue(int i)
Constructor for int value.
Definition: document.h:102
const Member * ConstMemberIterator
Constant member iterator for iterating in object.
Definition: document.h:67
void SetStringRaw(const Ch *s, SizeType length)
Initialize this value as constant string, without calling destructor.
Definition: document.h:675
GenericValue & operator=(GenericValue &rhs)
Assignment with move semantics.
Definition: document.h:195
~GenericValue()
Destructor.
Definition: document.h:163
GenericValue & AddMember(const Ch *name, T value, Allocator &allocator)
Definition: document.h:315
GenericValue(unsigned u)
Constructor for unsigned value.
Definition: document.h:109
bool IsUint64() const
Definition: document.h:229
GenericValue(Type type)
Constructor with JSON value type.
Definition: document.h:88
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:64
bool IsFalse() const
Definition: document.h:220
int GetInt() const
Definition: document.h:447
void SetObjectRaw(Member *members, SizeType count, Allocator &alloctaor)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:667
GenericValue(const Ch *s, SizeType length)
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:144
void RawAssign(GenericValue &rhs)
Assignment without calling destructor.
Definition: document.h:693
unsigned flags_
Definition: document.h:699
bool IsBool_() const
Definition: document.h:222
SizeType Size() const
Get the number of elements in array.
Definition: document.h:358
bool IsNull_() const
Definition: document.h:219
GenericValue & SetObject()
Set this value as an empty object.
Definition: document.h:254
Data data_
Definition: document.h:698
SizeType Capacity() const
Get the capacity of array.
Definition: document.h:361
GenericValue(const Ch *s, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:158
const Member * FindMember(const Ch *name) const
Definition: document.h:656
const GenericValue * ConstValueIterator
Constant value iterator for iterating in array.
Definition: document.h:69
GenericValue & SetUint64(uint64_t u64)
Definition: document.h:464
ValueIterator Begin()
Element iterator.
Definition: document.h:395
bool IsArray() const
Definition: document.h:224
MemberIterator MemberBegin()
Definition: document.h:270
const Ch * GetString() const
Definition: document.h:472
unsigned GetUint() const
Definition: document.h:448
double GetDouble() const
Definition: document.h:452
void Clear()
Remove all elements in the array.
Definition: document.h:369
GenericValue & PushBack(T value, Allocator &allocator)
Definition: document.h:430
bool RemoveMember(const Ch *name)
Remove a member in object by its name.
Definition: document.h:326
bool HasMember(const Ch *name) const
Check whether a member exists in the object.
Definition: document.h:274
GenericValue(double d)
Constructor for double value.
Definition: document.h:141
uint64_t GetUint64() const
Definition: document.h:450
GenericValue(const Ch *s)
Constructor for constant string (i.e. do not make a copy of string)
Definition: document.h:152
ValueIterator End()
Definition: document.h:396
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:283
GenericValue & AddMember(const Ch *name, GenericValue &value, Allocator &allocator)
Definition: document.h:309
static const SizeType kDefaultArrayCapacity
Definition: document.h:588
GenericValue & SetString(const Ch *s, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:507
bool IsObject() const
Definition: document.h:223
GenericValue & operator=(T value)
Assignment with primitive types.
Definition: document.h:208
GenericValue & SetString(const Ch *s)
Set this value as a string without copying source string.
Definition: document.h:491
ConstValueIterator End() const
Definition: document.h:398
GenericValue & AddMember(const Ch *name, Allocator &nameAllocator, GenericValue &value, Allocator &allocator)
Definition: document.h:304
static const SizeType kDefaultObjectCapacity
Definition: document.h:589
GenericValue(const GenericValue &rhs)
Copy constructor is not permitted.
bool IsInt() const
Definition: document.h:226
bool IsNumber() const
Definition: document.h:225
GenericValue & SetInt(int i)
Definition: document.h:461
GenericValue(int64_t i64)
Constructor for int64_t value.
Definition: document.h:116
Member * MemberIterator
Member iterator for iterating in object.
Definition: document.h:66
bool Empty() const
Check whether the array is empty.
Definition: document.h:364
GenericValue & SetNull_()
Definition: document.h:238
Type GetType() const
Definition: document.h:218
GenericValue(const Ch *s, SizeType length, Allocator &allocator)
Constructor for copy-string (i.e. do make a copy of string)
Definition: document.h:155
GenericValue(bool b)
Constructor for boolean value.
Definition: document.h:99
MemberIterator MemberEnd()
Definition: document.h:271
GenericValue & operator[](SizeType index)
Get an element from array by index.
Definition: document.h:387
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:65
bool IsDouble() const
Definition: document.h:230
GenericValue & operator[](const Ch *name)
Get the value associated with the object's name.
Definition: document.h:257
GenericValue & PopBack()
Remove the last element in the array.
Definition: document.h:436
GenericValue & SetString(const Ch *s, SizeType length, Allocator &allocator)
Set this value as a string by copying from source string.
Definition: document.h:500
bool IsUint() const
Definition: document.h:227
GenericValue & SetBool_(bool b)
Definition: document.h:246
ConstMemberIterator MemberBegin() const
Member iterators.
Definition: document.h:268
const GenericValue & Accept(Handler &handler) const
Generate events of this value to a Handler.
Definition: document.h:519
GenericValue(uint64_t u64)
Constructor for uint64_t value.
Definition: document.h:130
@ kStringFlag
Definition: document.h:568
@ kTrueFlag
Definition: document.h:573
@ kNumberDoubleFlag
Definition: document.h:579
@ kNumberUint64Flag
Definition: document.h:578
@ kFalseFlag
Definition: document.h:574
@ kDoubleFlag
Definition: document.h:567
@ kBool_Flag
Definition: document.h:561
@ kArrayFlag
Definition: document.h:583
@ kConstStringFlag
Definition: document.h:580
@ kTypeMask
Definition: document.h:585
@ kIntFlag
Definition: document.h:563
@ kObjectFlag
Definition: document.h:582
@ kCopyFlag
Definition: document.h:569
@ kNumberUintFlag
Definition: document.h:576
@ kUint64Flag
Definition: document.h:566
@ kNumberInt64Flag
Definition: document.h:577
@ kNull_Flag
Definition: document.h:572
@ kCopyStringFlag
Definition: document.h:581
@ kNumberIntFlag
Definition: document.h:575
@ kUintFlag
Definition: document.h:564
@ kNumberFlag
Definition: document.h:562
@ kInt64Flag
Definition: document.h:565
GenericValue & SetDouble(double d)
Definition: document.h:465
void SetStringRaw(const Ch *s, SizeType length, Allocator &allocator)
Initialize this value as copy string with initial data, without calling destructor.
Definition: document.h:683
GenericValue & SetString(const Ch *s, SizeType length)
Set this value as a string without copying source string.
Definition: document.h:485
bool IsInt64() const
Definition: document.h:228
Concept for receiving events from GenericReader upon parsing.
Concept for reading and writing characters.
A type-unsafe stack for storing different types of data.
Definition: stack.h:39
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:39
Definition: document.h:38
unsigned SizeType
Use 32-bit array/string indices even for 64-bit platform, instead of using size_t.
Definition: rapidjson.h:92
GenericDocument< UTF8<> > Document
Definition: document.h:838
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:69
Type
Type of JSON value.
Definition: rapidjson.h:538
@ kArrayType
array
Definition: rapidjson.h:543
@ kNull_Type
null
Definition: rapidjson.h:539
@ kTrueType
true
Definition: rapidjson.h:541
@ kFalseType
false
Definition: rapidjson.h:540
@ kNumberType
number
Definition: rapidjson.h:545
@ kObjectType
object
Definition: rapidjson.h:542
@ kStringType
string
Definition: rapidjson.h:544
GenericValue< UTF8<> > Value
Value with UTF8 encoding.
Definition: document.h:704
std::string name
Definition: MercuryProb.h:48
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:105
A read-write string stream.
Definition: rapidjson.h:512
Read-only string stream.
Definition: rapidjson.h:485
Definition: document.h:629
SizeType capacity
Definition: document.h:632
SizeType size
Definition: document.h:631
GenericValue< Encoding, Allocator > * elements
Definition: document.h:630
Name-value pair in an object.
Definition: document.h:58
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition: document.h:59
GenericValue< Encoding, Allocator > value
value of member.
Definition: document.h:60
Definition: document.h:600
char padding[4]
Definition: document.h:602
int i
Definition: document.h:601
Definition: document.h:604
char padding2[4]
Definition: document.h:606
unsigned u
Definition: document.h:605
Definition: document.h:623
SizeType capacity
Definition: document.h:626
SizeType size
Definition: document.h:625
Member * members
Definition: document.h:624
Definition: document.h:591
SizeType length
Definition: document.h:593
const Ch * str
Definition: document.h:592
unsigned hashcode
reserved
Definition: document.h:594
Definition: document.h:635
Number n
Definition: document.h:637
Array a
Definition: document.h:639
Object o
Definition: document.h:638
String s
Definition: document.h:636
Definition: document.h:598
uint64_t u64
Definition: document.h:619
int64_t i64
Definition: document.h:618
struct rapidjson::GenericValue::Number::I i
double d
Definition: document.h:620
struct rapidjson::GenericValue::Number::U u