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

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

#include <document.h>

Inheritance diagram for rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >:
rapidjson::GenericValue< Encoding, Allocator >

Public Types

typedef Encoding::Ch Ch
 Character type derived from Encoding.
 
typedef GenericValue< Encoding, AllocatorValueType
 Value type of the document.
 
typedef Allocator AllocatorType
 Allocator type from template parameter.
 
- Public Types inherited from rapidjson::GenericValue< Encoding, Allocator >
typedef GenericMember< Encoding, AllocatorMember
 Name-value pair in an object.
 
typedef Encoding EncodingType
 Encoding type from template parameter.
 
typedef Allocator AllocatorType
 Allocator type from template parameter.
 
typedef Encoding::Ch Ch
 Character type derived from Encoding.
 
typedef GenericStringRef< ChStringRefType
 Reference to a constant string.
 
typedef GenericMemberIterator< false, Encoding, Allocator >::Iterator MemberIterator
 Member iterator for iterating in object.
 
typedef GenericMemberIterator< true, Encoding, Allocator >::Iterator ConstMemberIterator
 Constant member iterator for iterating in object.
 
typedef GenericValueValueIterator
 Value iterator for iterating in array.
 
typedef GenericValue< Encoding, AllocatorValueType
 Value type of itself.
 
typedef GenericArray< false, ValueTypeArray
 
typedef GenericArray< true, ValueTypeConstArray
 
typedef GenericObject< false, ValueTypeObject
 
typedef GenericObject< true, ValueTypeConstObject
 
enum  {
  kBoolFlag = 0x0008, kNumberFlag = 0x0010, kIntFlag = 0x0020, kUintFlag = 0x0040,
  kInt64Flag = 0x0080, kUint64Flag = 0x0100, kDoubleFlag = 0x0200, kStringFlag = 0x0400,
  kCopyFlag = 0x0800, kInlineStrFlag = 0x1000, kNullFlag = kNullType, kTrueFlag = static_cast<int>(kTrueType) | static_cast<int>(kBoolFlag),
  kFalseFlag = static_cast<int>(kFalseType) | static_cast<int>(kBoolFlag), kNumberIntFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kIntFlag | kInt64Flag), kNumberUintFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag), kNumberInt64Flag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kInt64Flag),
  kNumberUint64Flag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kUint64Flag), kNumberDoubleFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kDoubleFlag), kNumberAnyFlag = static_cast<int>(kNumberType) | static_cast<int>(kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag), kConstStringFlag = static_cast<int>(kStringType) | static_cast<int>(kStringFlag),
  kCopyStringFlag = static_cast<int>(kStringType) | static_cast<int>(kStringFlag | kCopyFlag), kShortStringFlag = static_cast<int>(kStringType) | static_cast<int>(kStringFlag | kCopyFlag | kInlineStrFlag), kObjectFlag = kObjectType, kArrayFlag = kArrayType,
  kTypeMask = 0x07
}
 

Public Member Functions

 GenericDocument (Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
 Constructor. More...
 
 GenericDocument (Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
 Constructor. More...
 
GenericDocumentSwap (GenericDocument &rhs) RAPIDJSON_NOEXCEPT
 Exchange the contents of this document with those of another. More...
 
template<typename Generator >
GenericDocumentPopulate (Generator &g)
 Populate this document by a generator which produces SAX events. More...
 
AllocatorGetAllocator ()
 Get the allocator of this document.
 
size_t GetStackCapacity () const
 Get the capacity of stack in bytes.
 
bool Null ()
 
bool Bool (bool b)
 
bool Int (int i)
 
bool Uint (unsigned i)
 
bool Int64 (int64_t i)
 
bool Uint64 (uint64_t i)
 
bool Double (double d)
 
bool RawNumber (const Ch *str, SizeType length, bool copy)
 
bool String (const Ch *str, SizeType length, bool copy)
 
bool StartObject ()
 
bool Key (const Ch *str, SizeType length, bool copy)
 
bool EndObject (SizeType memberCount)
 
bool StartArray ()
 
bool EndArray (SizeType elementCount)
 
Parse from stream
template<unsigned parseFlags, typename SourceEncoding , typename InputStream >
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream (with Encoding conversion) More...
 
template<unsigned parseFlags, typename InputStream >
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream. More...
 
template<typename InputStream >
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream (with kParseDefaultFlags) More...
 
Parse in-place from mutable string
template<unsigned parseFlags>
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string. More...
 
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string (with kParseDefaultFlags) More...
 
Parse from read-only string
template<unsigned parseFlags, typename SourceEncoding >
GenericDocumentParse (const typename SourceEncoding::Ch *str)
 Parse JSON text from a read-only string (with Encoding conversion) More...
 
template<unsigned parseFlags>
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string. More...
 
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string (with kParseDefaultFlags) More...
 
template<unsigned parseFlags, typename SourceEncoding >
GenericDocumentParse (const typename SourceEncoding::Ch *str, size_t length)
 
template<unsigned parseFlags>
GenericDocumentParse (const Ch *str, size_t length)
 
GenericDocumentParse (const Ch *str, size_t length)
 
template<unsigned parseFlags, typename SourceEncoding >
GenericDocumentParse (const std::basic_string< typename SourceEncoding::Ch > &str)
 
template<unsigned parseFlags>
GenericDocumentParse (const std::basic_string< Ch > &str)
 
GenericDocumentParse (const std::basic_string< Ch > &str)
 
Handling parse errors
bool HasParseError () const
 Whether a parse error has occurred in the last parsing.
 
ParseErrorCode GetParseError () const
 Get the ParseErrorCode of last parsing.
 
size_t GetErrorOffset () const
 Get the position of last parsing error in input, 0 otherwise.
 
 operator ParseResult () const
 Implicit conversion to get the last parse result. More...
 
- Public Member Functions inherited from rapidjson::GenericValue< Encoding, Allocator >
GenericValueoperator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment with move semantics. More...
 
GenericValueoperator= (StringRefType str) RAPIDJSON_NOEXCEPT
 Assignment of constant string reference (no copy) More...
 
template<typename T >
 RAPIDJSON_DISABLEIF_RETURN ((internal::IsPointer< T >),(GenericValue &)) operator
 Assignment with primitive types. More...
 
const RAPIDJSON_FORCEINLINE ChGetStringPointer () const
 
const RAPIDJSON_FORCEINLINE ChSetStringPointer (const Ch *str)
 
RAPIDJSON_FORCEINLINE GenericValueGetElementsPointer () const
 
RAPIDJSON_FORCEINLINE GenericValueSetElementsPointer (GenericValue *elements)
 
RAPIDJSON_FORCEINLINE MemberGetMembersPointer () const
 
RAPIDJSON_FORCEINLINE MemberSetMembersPointer (Member *members)
 
RAPIDJSON_FORCEINLINE MemberDoAllocMembers (SizeType capacity, Allocator &allocator)
 
void DoReserveMembers (SizeType newCapacity, Allocator &allocator)
 
template<typename SourceAllocator >
MemberIterator DoFindMember (const GenericValue< Encoding, SourceAllocator > &name)
 
void DoClearMembers ()
 
void DoFreeMembers ()
 
void DoAddMember (GenericValue &name, GenericValue &value, Allocator &allocator)
 
MemberIterator DoRemoveMember (MemberIterator m)
 
MemberIterator DoEraseMembers (ConstMemberIterator first, ConstMemberIterator last)
 
template<typename SourceAllocator >
void DoCopyMembers (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings)
 
void SetArrayRaw (GenericValue *values, SizeType count, Allocator &allocator)
 
void SetObjectRaw (Member *members, SizeType count, Allocator &allocator)
 Initialize this value as object with initial data, without calling destructor.
 
void SetStringRaw (StringRefType s) RAPIDJSON_NOEXCEPT
 Initialize this value as constant string, without calling destructor.
 
void SetStringRaw (StringRefType s, Allocator &allocator)
 Initialize this value as copy string with initial data, without calling destructor.
 
void RawAssign (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment without calling destructor.
 
template<typename SourceAllocator >
bool StringEqual (const GenericValue< Encoding, SourceAllocator > &rhs) const
 
 GenericValue () RAPIDJSON_NOEXCEPT
 Default constructor creates a null value.
 
 GenericValue (Type type) RAPIDJSON_NOEXCEPT
 Constructor with JSON value type. More...
 
template<typename SourceAllocator >
 GenericValue (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator, bool copyConstStrings=false)
 Explicit copy constructor (with allocator) More...
 
 GenericValue (bool b) RAPIDJSON_NOEXCEPT
 Constructor for boolean value. More...
 
 GenericValue (int i) RAPIDJSON_NOEXCEPT
 Constructor for int value.
 
 GenericValue (unsigned u) RAPIDJSON_NOEXCEPT
 Constructor for unsigned value.
 
 GenericValue (int64_t i64) RAPIDJSON_NOEXCEPT
 Constructor for int64_t value.
 
 GenericValue (uint64_t u64) RAPIDJSON_NOEXCEPT
 Constructor for uint64_t value.
 
 GenericValue (double d) RAPIDJSON_NOEXCEPT
 Constructor for double value.
 
 GenericValue (float f) RAPIDJSON_NOEXCEPT
 Constructor for float value.
 
 GenericValue (const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
 Constructor for constant string (i.e. do not make a copy of string)
 
 GenericValue (StringRefType s) RAPIDJSON_NOEXCEPT
 Constructor for constant string (i.e. do not make a copy of string)
 
 GenericValue (const Ch *s, SizeType length, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string)
 
 GenericValue (const Ch *s, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string)
 
 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) More...
 
 GenericValue (Array a) RAPIDJSON_NOEXCEPT
 Constructor for Array. More...
 
 GenericValue (Object o) RAPIDJSON_NOEXCEPT
 Constructor for Object. More...
 
 ~GenericValue ()
 Destructor. More...
 

Friends

template<typename , typename >
class GenericValue
 
void swap (GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
 free-standing swap function helper More...
 

Additional Inherited Members

- Static Public Member Functions inherited from rapidjson::GenericValue< Encoding, Allocator >
static const RAPIDJSON_FORCEINLINE ChDataString (const Data &data)
 
static RAPIDJSON_FORCEINLINE SizeType DataStringLength (const Data &data)
 
- Public Attributes inherited from rapidjson::GenericValue< Encoding, Allocator >
const typedef GenericValueConstValueIterator
 Constant value iterator for iterating in array.
 
Data data_
 
- Static Public Attributes inherited from rapidjson::GenericValue< Encoding, Allocator >
static const SizeType kDefaultArrayCapacity = RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY
 
static const SizeType kDefaultObjectCapacity = RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY
 

Detailed Description

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
class rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >

A document for parsing JSON text as DOM.

Note
implements Handler concept
Template Parameters
EncodingEncoding for both parsing and string storage.
AllocatorAllocator for allocating memory for the DOM
StackAllocatorAllocator for allocating memory for stack during parsing.
Warning
Although GenericDocument inherits from GenericValue, the API does not provide any virtual functions, especially no virtual destructor. To avoid memory leaks, do not delete a GenericDocument object via a pointer to a GenericValue.

Constructor & Destructor Documentation

◆ GenericDocument() [1/2]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::GenericDocument ( Type  type,
Allocator allocator = 0,
size_t  stackCapacity = kDefaultStackCapacity,
StackAllocator *  stackAllocator = 0 
)
inlineexplicit

Constructor.

Creates an empty document of specified type.

Parameters
typeMandatory type of object to create.
allocatorOptional allocator for allocating memory.
stackCapacityOptional initial capacity of stack in bytes.
stackAllocatorOptional allocator for allocating memory for stack.

◆ GenericDocument() [2/2]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::GenericDocument ( Allocator allocator = 0,
size_t  stackCapacity = kDefaultStackCapacity,
StackAllocator *  stackAllocator = 0 
)
inline

Constructor.

Creates an empty document which type is Null.

Parameters
allocatorOptional allocator for allocating memory.
stackCapacityOptional initial capacity of stack in bytes.
stackAllocatorOptional allocator for allocating memory for stack.

Member Function Documentation

◆ operator ParseResult()

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::operator ParseResult ( ) const
inline

Implicit conversion to get the last parse result.

Returns
ParseResult of the last parse operation
ParseResult ok = doc.Parse(json);
if (!ok)
printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset());

◆ Parse() [1/3]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::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.

◆ Parse() [2/3]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const Ch str)
inline

Parse JSON text from a read-only string (with kParseDefaultFlags)

Parameters
strRead-only zero-terminated string to be parsed.

◆ Parse() [3/3]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags, typename SourceEncoding >
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const typename SourceEncoding::Ch *  str)
inline

Parse JSON text from a read-only string (with Encoding conversion)

Template Parameters
parseFlagsCombination of ParseFlag (must not contain kParseInsituFlag).
SourceEncodingTranscoding from input Encoding
Parameters
strRead-only zero-terminated string to be parsed.

◆ ParseInsitu() [1/2]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::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.

◆ ParseInsitu() [2/2]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseInsitu ( Ch str)
inline

Parse JSON text from a mutable string (with kParseDefaultFlags)

Parameters
strMutable zero-terminated string to be parsed.
Returns
The document itself for fluent API.

◆ ParseStream() [1/3]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags, typename SourceEncoding , typename InputStream >
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream ( InputStream &  is)
inline

Parse JSON text from an input stream (with Encoding conversion)

Template Parameters
parseFlagsCombination of ParseFlag.
SourceEncodingEncoding of input stream
InputStreamType of input stream, implementing Stream concept
Parameters
isInput stream to be parsed.
Returns
The document itself for fluent API.

◆ ParseStream() [2/3]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags, typename InputStream >
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream ( InputStream &  is)
inline

Parse JSON text from an input stream.

Template Parameters
parseFlagsCombination of ParseFlag.
InputStreamType of input stream, implementing Stream concept
Parameters
isInput stream to be parsed.
Returns
The document itself for fluent API.

◆ ParseStream() [3/3]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<typename InputStream >
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream ( InputStream &  is)
inline

Parse JSON text from an input stream (with kParseDefaultFlags)

Template Parameters
InputStreamType of input stream, implementing Stream concept
Parameters
isInput stream to be parsed.
Returns
The document itself for fluent API.

◆ Populate()

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<typename Generator >
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Populate ( Generator &  g)
inline

Populate this document by a generator which produces SAX events.

Template Parameters
GeneratorA functor with bool f(Handler) prototype.
Parameters
gGenerator functor which sends SAX events to the parameter.
Returns
The document itself for fluent API.

◆ Swap()

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericDocument& rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Swap ( GenericDocument< Encoding, Allocator, StackAllocator > &  rhs)
inline

Exchange the contents of this document with those of another.

Parameters
rhsAnother document.
Note
Constant complexity.
See also
GenericValue::Swap

Friends And Related Function Documentation

◆ swap

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
void swap ( GenericDocument< Encoding, Allocator, StackAllocator > &  a,
GenericDocument< Encoding, Allocator, StackAllocator > &  b 
)
friend

free-standing swap function helper

Helper function to enable support for common swap implementation pattern based on std::swap:

void swap(MyClass& a, MyClass& b) {
using std::swap;
swap(a.doc, b.doc);
// ...
}
See also
Swap()

The documentation for this class was generated from the following file:
rapidjson::GenericDocument::swap
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2598
rapidjson::Document
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2873
rapidjson::GetParseError_En
const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition: en.h:36