rapidjson::GenericDocument< Encoding, Allocator > Class Template Reference

A document for parsing JSON text as DOM. More...

#include <document.h>

+ Inheritance diagram for rapidjson::GenericDocument< Encoding, Allocator >:

Public Types

typedef Encoding::Ch Ch
 Character type derived from Encoding. More...
 
typedef GenericValue< Encoding, AllocatorValueType
 Value type of the document. More...
 
typedef Allocator AllocatorType
 Allocator type from template parameter. More...
 
- Public Types inherited from rapidjson::GenericValue< Encoding, MemoryPoolAllocator<> >
typedef Encoding EncodingType
 Encoding type from template parameter. More...
 
typedef MemoryPoolAllocator<> AllocatorType
 Allocator type from template parameter. More...
 
typedef Encoding::Ch Ch
 Character type derived from Encoding. More...
 
typedef Member * MemberIterator
 Member iterator for iterating in object. More...
 
typedef const Member * ConstMemberIterator
 Constant member iterator for iterating in object. More...
 
typedef GenericValueValueIterator
 Value iterator for iterating in array. More...
 
typedef const GenericValueConstValueIterator
 Constant value iterator for iterating in array. More...
 

Public Member Functions

 GenericDocument (Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity)
 Constructor. More...
 
template<unsigned parseFlags, typename Stream >
GenericDocumentParseStream (Stream &stream)
 Parse JSON text from an input stream. More...
 
template<unsigned parseFlags>
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string. More...
 
template<unsigned parseFlags>
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string. More...
 
bool HasParseError () const
 Whether a parse error was occured in the last parsing. More...
 
const charGetParseError () const
 Get the message of parsing error. More...
 
size_t GetErrorOffset () const
 Get the offset in character of the parsing error. More...
 
AllocatorGetAllocator ()
 Get the allocator of this document. More...
 
size_t GetStackCapacity () const
 Get the capacity of stack in bytes. More...
 
- Public Member Functions inherited from rapidjson::GenericValue< Encoding, MemoryPoolAllocator<> >
GenericValueoperator= (GenericValue &rhs)
 Assignment with move semantics. More...
 
GenericValueoperator= (T value)
 Assignment with primitive types. More...
 
Type GetType () const
 
bool IsNull_ () const
 
bool IsFalse () const
 
bool IsTrue () const
 
bool IsBool_ () const
 
bool IsObject () const
 
bool IsArray () const
 
bool IsNumber () const
 
bool IsInt () const
 
bool IsUint () const
 
bool IsInt64 () const
 
bool IsUint64 () const
 
bool IsDouble () const
 
bool IsString () const
 
GenericValueSetNull_ ()
 
bool GetBool_ () const
 
GenericValueSetBool_ (bool b)
 
GenericValueSetObject ()
 Set this value as an empty object. More...
 
GenericValueoperator[] (const Ch *name)
 Get the value associated with the object's name. More...
 
const GenericValueoperator[] (const Ch *name) const
 
ConstMemberIterator MemberBegin () const
 Member iterators. More...
 
MemberIterator MemberBegin ()
 
ConstMemberIterator MemberEnd () const
 
MemberIterator MemberEnd ()
 
bool HasMember (const Ch *name) const
 Check whether a member exists in the object. More...
 
GenericValueAddMember (GenericValue &name, GenericValue &value, MemoryPoolAllocator<> &allocator)
 Add a member (name-value pair) to the object. More...
 
GenericValueAddMember (const Ch *name, MemoryPoolAllocator<> &nameAllocator, GenericValue &value, MemoryPoolAllocator<> &allocator)
 
GenericValueAddMember (const Ch *name, GenericValue &value, MemoryPoolAllocator<> &allocator)
 
GenericValueAddMember (const Ch *name, T value, MemoryPoolAllocator<> &allocator)
 
bool RemoveMember (const Ch *name)
 Remove a member in object by its name. More...
 
GenericValueoperator[] (SizeType index)
 Get an element from array by index. More...
 
const GenericValueoperator[] (SizeType index) const
 
GenericValueSetArray ()
 Set this value as an empty array. More...
 
SizeType Size () const
 Get the number of elements in array. More...
 
SizeType Capacity () const
 Get the capacity of array. More...
 
bool Empty () const
 Check whether the array is empty. More...
 
void Clear ()
 Remove all elements in the array. More...
 
ValueIterator Begin ()
 Element iterator. More...
 
ConstValueIterator Begin () const
 
ValueIterator End ()
 
ConstValueIterator End () const
 
GenericValueReserve (SizeType newCapacity, MemoryPoolAllocator<> &allocator)
 Request the array to have enough capacity to store elements. More...
 
GenericValuePushBack (GenericValue &value, MemoryPoolAllocator<> &allocator)
 Append a value at the end of the array. More...
 
GenericValuePushBack (T value, MemoryPoolAllocator<> &allocator)
 
GenericValuePopBack ()
 Remove the last element in the array. More...
 
int GetInt () const
 
unsigned GetUint () const
 
int64_t GetInt64 () const
 
uint64_t GetUint64 () const
 
double GetDouble () const
 
GenericValueSetInt (int i)
 
GenericValueSetUint (unsigned u)
 
GenericValueSetInt64 (int64_t i64)
 
GenericValueSetUint64 (uint64_t u64)
 
GenericValueSetDouble (double d)
 
const ChGetString () const
 
SizeType GetStringLength () const
 Get the length of string. More...
 
GenericValueSetString (const Ch *s, SizeType length)
 Set this value as a string without copying source string. More...
 
GenericValueSetString (const Ch *s)
 Set this value as a string without copying source string. More...
 
GenericValueSetString (const Ch *s, SizeType length, MemoryPoolAllocator<> &allocator)
 Set this value as a string by copying from source string. More...
 
GenericValueSetString (const Ch *s, MemoryPoolAllocator<> &allocator)
 Set this value as a string by copying from source string. More...
 
const GenericValueAccept (Handler &handler) const
 Generate events of this value to a Handler. More...
 
 GenericValue ()
 Default constructor creates a null value. More...
 
 GenericValue (Type type)
 Constructor with JSON value type. More...
 
 GenericValue (bool b)
 Constructor for boolean value. More...
 
 GenericValue (int i)
 Constructor for int value. More...
 
 GenericValue (unsigned u)
 Constructor for unsigned value. More...
 
 GenericValue (int64_t i64)
 Constructor for int64_t value. More...
 
 GenericValue (uint64_t u64)
 Constructor for uint64_t value. More...
 
 GenericValue (double d)
 Constructor for double value. More...
 
 GenericValue (const Ch *s, SizeType length)
 Constructor for constant string (i.e. do not make a copy of string) More...
 
 GenericValue (const Ch *s)
 Constructor for constant string (i.e. do not make a copy of string) More...
 
 GenericValue (const Ch *s, SizeType length, MemoryPoolAllocator<> &allocator)
 Constructor for copy-string (i.e. do make a copy of string) More...
 
 GenericValue (const Ch *s, MemoryPoolAllocator<> &allocator)
 Constructor for copy-string (i.e. do make a copy of string) More...
 
 ~GenericValue ()
 Destructor. More...
 

Private Member Functions

GenericDocumentoperator= (const GenericDocument &)
 
void Null_ ()
 
void Bool_ (bool b)
 
void Int (int i)
 
void Uint (unsigned i)
 
void Int64 (int64_t i)
 
void Uint64 (uint64_t i)
 
void Double (double d)
 
void String (const Ch *str, SizeType length, bool copy)
 
void StartObject ()
 
void EndObject (SizeType memberCount)
 
void StartArray ()
 
void EndArray (SizeType elementCount)
 
void ClearStack ()
 

Private Attributes

internal::Stack< Allocatorstack_
 
const charparseError_
 
size_t errorOffset_
 

Static Private Attributes

static const size_t kDefaultStackCapacity = 1024
 

Friends

class GenericReader< Encoding, Allocator >
 

Detailed Description

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
class rapidjson::GenericDocument< Encoding, Allocator >

A document for parsing JSON text as DOM.

Template Parameters
Encodingencoding for both parsing and string storage.
Alloactorallocator for allocating memory for the DOM, and the stack during parsing.

Member Typedef Documentation

◆ AllocatorType

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
typedef Allocator rapidjson::GenericDocument< Encoding, Allocator >::AllocatorType

Allocator type from template parameter.

◆ Ch

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
typedef Encoding::Ch rapidjson::GenericDocument< Encoding, Allocator >::Ch

Character type derived from Encoding.

◆ ValueType

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
typedef GenericValue<Encoding, Allocator> rapidjson::GenericDocument< Encoding, Allocator >::ValueType

Value type of the document.

Constructor & Destructor Documentation

◆ GenericDocument()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
rapidjson::GenericDocument< Encoding, Allocator >::GenericDocument ( Allocator allocator = 0,
size_t  stackCapacity = kDefaultStackCapacity 
)
inline

Constructor.

Parameters
allocatorOptional allocator for allocating stack memory.
stackCapacityInitial capacity of stack in bytes.
726 : stack_(allocator, stackCapacity), parseError_(0), errorOffset_(0) {}
internal::Stack< Allocator > stack_
Definition: document.h:833
const char * parseError_
Definition: document.h:834
size_t errorOffset_
Definition: document.h:835

Member Function Documentation

◆ Bool_()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Bool_ ( bool  b)
inlineprivate
796 { new (stack_.template Push<ValueType>()) ValueType(b); }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:719

References rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ ClearStack()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::ClearStack ( )
inlineprivate
824  {
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  }

References rapidjson::GenericDocument< Encoding, Allocator >::stack_.

Referenced by rapidjson::GenericDocument< Encoding, Allocator >::ParseStream().

◆ Double()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Double ( double  d)
inlineprivate
801 { new (stack_.template Push<ValueType>()) ValueType(d); }

References rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ EndArray()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::EndArray ( SizeType  elementCount)
inlineprivate
819  {
820  ValueType* elements = stack_.template Pop<ValueType>(elementCount);
821  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
822  }
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:783

References rapidjson::GenericDocument< Encoding, Allocator >::GetAllocator(), and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ EndObject()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::EndObject ( SizeType  memberCount)
inlineprivate
812  {
813  typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
814  stack_.template Top<ValueType>()->SetObjectRaw(members, (SizeType)memberCount, GetAllocator());
815  }
unsigned SizeType
Use 32-bit array/string indices even for 64-bit platform, instead of using size_t.
Definition: rapidjson.h:92

References rapidjson::GenericDocument< Encoding, Allocator >::GetAllocator(), and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ GetAllocator()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
Allocator& rapidjson::GenericDocument< Encoding, Allocator >::GetAllocator ( )
inline

◆ GetErrorOffset()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
size_t rapidjson::GenericDocument< Encoding, Allocator >::GetErrorOffset ( ) const
inline

Get the offset in character of the parsing error.

780 { return errorOffset_; }

References rapidjson::GenericDocument< Encoding, Allocator >::errorOffset_.

◆ GetParseError()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
const char* rapidjson::GenericDocument< Encoding, Allocator >::GetParseError ( ) const
inline

Get the message of parsing error.

777 { return parseError_; }

References rapidjson::GenericDocument< Encoding, Allocator >::parseError_.

◆ GetStackCapacity()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
size_t rapidjson::GenericDocument< Encoding, Allocator >::GetStackCapacity ( ) const
inline

Get the capacity of stack in bytes.

786 { return stack_.GetCapacity(); }

References rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ HasParseError()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
bool rapidjson::GenericDocument< Encoding, Allocator >::HasParseError ( ) const
inline

Whether a parse error was occured in the last parsing.

774 { return parseError_ != 0; }

References rapidjson::GenericDocument< Encoding, Allocator >::parseError_.

◆ Int()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Int ( int  i)
inlineprivate
797 { new (stack_.template Push<ValueType>()) ValueType(i); }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References constants::i, and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ Int64()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Int64 ( int64_t  i)
inlineprivate
799 { new (stack_.template Push<ValueType>()) ValueType(i); }

References constants::i, and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ Null_()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Null_ ( )
inlineprivate
795 { new (stack_.template Push<ValueType>()) ValueType(); }

References rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ operator=()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator >::operator= ( const GenericDocument< Encoding, Allocator > &  )
private

◆ Parse()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<unsigned parseFlags>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator >::Parse ( const Ch str)
inline

Parse JSON text from a read-only string.

Template Parameters
parseFlagsCombination of ParseFlag (must not contain kParseInsituFlag).
Parameters
strRead-only zero-terminated string to be parsed.
767  {
768  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
769  GenericStringStream<Encoding> s(str);
770  return ParseStream<parseFlags>(s);
771  }
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:69
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:105

References rapidjson::kParseInsituFlag, and RAPIDJSON_ASSERT.

◆ ParseInsitu()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<unsigned parseFlags>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator >::ParseInsitu ( Ch str)
inline

Parse JSON text from a mutable string.

Template Parameters
parseFlagsCombination of ParseFlag.
Parameters
strMutable zero-terminated string to be parsed.
Returns
The document itself for fluent API.
757  {
758  GenericInsituStringStream<Encoding> s(str);
759  return ParseStream<parseFlags | kParseInsituFlag>(s);
760  }

◆ ParseStream()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<unsigned parseFlags, typename Stream >
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator >::ParseStream ( Stream stream)
inline

Parse JSON text from an input stream.

Template Parameters
parseFlagsCombination of ParseFlag.
Parameters
streamInput stream to be parsed.
Returns
The document itself for fluent API.
734  {
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  }
void ClearStack()
Definition: document.h:824
friend class GenericReader< Encoding, Allocator >
Definition: document.h:792
void RawAssign(GenericValue &rhs)
Assignment without calling destructor.
Definition: document.h:693
GenericValue & SetNull_()
Definition: document.h:238

References rapidjson::GenericDocument< Encoding, Allocator >::ClearStack(), rapidjson::GenericDocument< Encoding, Allocator >::errorOffset_, rapidjson::GenericReader< Encoding, Allocator >::GetErrorOffset(), rapidjson::GenericReader< Encoding, Allocator >::GetParseError(), rapidjson::GenericDocument< Encoding, Allocator >::parseError_, RAPIDJSON_ASSERT, rapidjson::GenericValue< Encoding, MemoryPoolAllocator<> >::RawAssign(), rapidjson::GenericValue< Encoding, Allocator >::SetNull_(), and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ StartArray()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::StartArray ( )
inlineprivate
817 { new (stack_.template Push<ValueType>()) ValueType(kArrayType); }
@ kArrayType
array
Definition: rapidjson.h:543

References rapidjson::kArrayType, and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ StartObject()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::StartObject ( )
inlineprivate
810 { new (stack_.template Push<ValueType>()) ValueType(kObjectType); }
@ kObjectType
object
Definition: rapidjson.h:542

References rapidjson::kObjectType, and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ String()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::String ( const Ch str,
SizeType  length,
bool  copy 
)
inlineprivate
803  {
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  }

References rapidjson::GenericDocument< Encoding, Allocator >::GetAllocator(), and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ Uint()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Uint ( unsigned  i)
inlineprivate
798 { new (stack_.template Push<ValueType>()) ValueType(i); }

References constants::i, and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

◆ Uint64()

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
void rapidjson::GenericDocument< Encoding, Allocator >::Uint64 ( uint64_t  i)
inlineprivate
800 { new (stack_.template Push<ValueType>()) ValueType(i); }

References constants::i, and rapidjson::GenericDocument< Encoding, Allocator >::stack_.

Friends And Related Function Documentation

◆ GenericReader< Encoding, Allocator >

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
friend class GenericReader< Encoding, Allocator >
friend

Member Data Documentation

◆ errorOffset_

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
size_t rapidjson::GenericDocument< Encoding, Allocator >::errorOffset_
private

◆ kDefaultStackCapacity

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
const size_t rapidjson::GenericDocument< Encoding, Allocator >::kDefaultStackCapacity = 1024
staticprivate

◆ parseError_

◆ stack_


The documentation for this class was generated from the following file: