Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
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 >:

## Public Types
typedef Encoding::Ch | Ch
| Character type derived from Encoding.
typedef GenericValue< Encoding, Allocator > | ValueType
| Value type of the document.
typedef Allocator | AllocatorType
| Allocator type from template parameter.
Public Types inherited from rapidjson::GenericValue< Encoding, Allocator >
typedef GenericMember< Encoding, Allocator > | Member
| 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< Ch > | StringRefType
| 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 GenericValue * | ValueIterator
| Value iterator for iterating in array.
typedef const GenericValue * | ConstValueIterator
| Constant value iterator for iterating in array.
typedef GenericValue< Encoding, Allocator > | ValueType
| Value type of itself.
typedef GenericArray< false, ValueType > | Array
typedef GenericArray< true, ValueType > | ConstArray
typedef GenericObject< false, ValueType > | Object
typedef GenericObject< true, ValueType > | ConstObject

## Public Member Functions
| GenericDocument (Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
| Constructor.
| GenericDocument (Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
| Constructor.
GenericDocument & | Swap (GenericDocument &rhs) RAPIDJSON_NOEXCEPT
| Exchange the contents of this document with those of another.
template<typename Generator >
GenericDocument & | Populate (Generator &g)
| Populate this document by a generator which produces SAX events.
Allocator & | GetAllocator ()
| 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 >
GenericDocument & | ParseStream (InputStream &is)
| Parse JSON text from an input stream (with Encoding conversion)
template<unsigned parseFlags, typename InputStream >
GenericDocument & | ParseStream (InputStream &is)
| Parse JSON text from an input stream.
template<typename InputStream >
GenericDocument & | ParseStream (InputStream &is)
| Parse JSON text from an input stream (with kParseDefaultFlags)
Parse in-place from mutable string
template<unsigned parseFlags>
GenericDocument & | ParseInsitu (Ch *str)
| Parse JSON text from a mutable string.
GenericDocument & | ParseInsitu (Ch *str)
| Parse JSON text from a mutable string (with kParseDefaultFlags)
Parse from read-only string
template<unsigned parseFlags, typename SourceEncoding >
GenericDocument & | Parse (const typename SourceEncoding::Ch *str)
| Parse JSON text from a read-only string (with Encoding conversion)
template<unsigned parseFlags>
GenericDocument & | Parse (const Ch *str)
| Parse JSON text from a read-only string.
GenericDocument & | Parse (const Ch *str)
| Parse JSON text from a read-only string (with kParseDefaultFlags)
template<unsigned parseFlags, typename SourceEncoding >
GenericDocument & | Parse (const typename SourceEncoding::Ch *str, size_t length)
template<unsigned parseFlags>
GenericDocument & | Parse (const Ch *str, size_t length)
GenericDocument & | Parse (const Ch *str, size_t length)
Handling parse errors
bool | HasParseError () const
| Whether a parse error has occured 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.
Public Member Functions inherited from rapidjson::GenericValue< Encoding, Allocator >
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
bool | IsLosslessDouble () const
bool | IsFloat () const
bool | IsLosslessFloat () const
GenericValue & | SetNull ()
bool | GetBool () const
| Set boolean value.
GenericValue & | SetBool (bool b)
GenericValue & | SetObject ()
| Set this value as an empty object.
SizeType | MemberCount () const
| Get the number of members in the object.
bool | ObjectEmpty () const
| Check whether the object is empty.
template<typename T >
GenericValue & | operator[] (T *name)
| Get a value from an object associated with the name.
template<typename T >
const GenericValue & | operator[] (T *name) const
template<typename SourceAllocator >
GenericValue & | operator[] (const GenericValue< Encoding, SourceAllocator > &name)
| Get a value from an object associated with the name.
template<typename SourceAllocator >
const GenericValue & | operator[] (const GenericValue< Encoding, SourceAllocator > &name) const
ConstMemberIterator | MemberBegin () const
| Const member iterator.
ConstMemberIterator | MemberEnd () const
| Const past-the-end member iterator.
MemberIterator | MemberBegin ()
| Member iterator.
MemberIterator | MemberEnd ()
| Past-the-end member iterator
bool | HasMember (const Ch *name) const
| Check whether a member exists in the object.
template<typename SourceAllocator >
bool | HasMember (const GenericValue< Encoding, SourceAllocator > &name) const
| Check whether a member exists in the object with GenericValue name.
MemberIterator | FindMember (const Ch *name)
| Find member by name.
ConstMemberIterator | FindMember (const Ch *name) const
template<typename SourceAllocator >
MemberIterator | FindMember (const GenericValue< Encoding, SourceAllocator > &name)
| Find member by name.
template<typename SourceAllocator >
ConstMemberIterator | FindMember (const GenericValue< Encoding, SourceAllocator > &name) const
GenericValue & | AddMember (GenericValue &name, GenericValue &value, Allocator &allocator)
| Add a member (name-value pair) to the object.
GenericValue & | AddMember (GenericValue &name, StringRefType value, Allocator &allocator)
| Add a constant string value as member (name-value pair) to the object.
template<typename T >
GenericValue & | AddMember (GenericValue &name, T value, Allocator &allocator)
| Add any primitive value as member (name-value pair) to the object.
GenericValue & | AddMember (StringRefType name, GenericValue &value, Allocator &allocator)
| Add a member (name-value pair) to the object.
GenericValue & | AddMember (StringRefType name, StringRefType value, Allocator &allocator)
| Add a constant string value as member (name-value pair) to the object.
template<typename T >
GenericValue & | AddMember (StringRefType name, T value, Allocator &allocator)
| Add any primitive value as member (name-value pair) to the object.
void | RemoveAllMembers ()
| Remove all members in the object.
bool | RemoveMember (const Ch *name)
| Remove a member in object by its name.
template<typename SourceAllocator >
bool | RemoveMember (const GenericValue< Encoding, SourceAllocator > &name)
MemberIterator | RemoveMember (MemberIterator m)
| Remove a member in object by iterator.
MemberIterator | EraseMember (ConstMemberIterator pos)
| Remove a member from an object by iterator.
MemberIterator | EraseMember (ConstMemberIterator first, ConstMemberIterator last)
| Remove members in the range [first, last) from an object.
bool | EraseMember (const Ch *name)
| Erase a member in object by its name.
template<typename SourceAllocator >
bool | EraseMember (const GenericValue< Encoding, SourceAllocator > &name)
Object | GetObject ()
ConstObject | GetObject () const
int | GetInt () const
unsigned | GetUint () const
int64_t | GetInt64 () const
uint64_t | GetUint64 () const
double | GetDouble () const
| Get the value as double type.
float | GetFloat () const
| Get the value as float type.
GenericValue & | SetInt (int i)
GenericValue & | SetUint (unsigned u)
GenericValue & | SetInt64 (int64_t i64)
GenericValue & | SetUint64 (uint64_t u64)
GenericValue & | SetDouble (double d)
GenericValue & | SetFloat (float f)
const Ch * | GetString () const
SizeType | GetStringLength () const
| Get the length of string.
GenericValue & | SetString (const Ch *s, SizeType length)
| Set this value as a string without copying source string.
GenericValue & | SetString (StringRefType s)
| Set this value as a string without copying source string.
GenericValue & | SetString (const Ch *s, SizeType length, Allocator &allocator)
| Set this value as a string by copying from source string.
GenericValue & | SetString (const Ch *s, Allocator &allocator)
| Set this value as a string by copying from source string.
GenericValue & | SetArray ()
| Set this value as an empty array.
SizeType | Size () const
| Get the number of elements in array.
SizeType | Capacity () const
| Get the capacity of array.
bool | Empty () const
| Check whether the array is empty.
void | Clear ()
| Remove all elements in the array.
GenericValue & | operator[] (SizeType index)
| Get an element from array by index.
const GenericValue & | operator[] (SizeType index) const
ValueIterator | Begin ()
| Element iterator.
ValueIterator | End ()
| Past-the-end element iterator
ConstValueIterator | Begin () const
| Constant element iterator.
ConstValueIterator | End () const
| Constant past-the-end element iterator.
GenericValue & | Reserve (SizeType newCapacity, Allocator &allocator)
| Request the array to have enough capacity to store elements.
GenericValue & | PushBack (GenericValue &value, Allocator &allocator)
| Append a GenericValue at the end of the array.
GenericValue & | PushBack (StringRefType value, Allocator &allocator)
| Append a constant string reference at the end of the array.
template<typename T >
GenericValue & | PushBack (T value, Allocator &allocator)
| Append a primitive value at the end of the array.
GenericValue & | PopBack ()
| Remove the last element in the array.
ValueIterator | Erase (ConstValueIterator pos)
| Remove an element of array by iterator.
ValueIterator | Erase (ConstValueIterator first, ConstValueIterator last)
| Remove elements in the range [first, last) of the array.
Array | GetArray ()
ConstArray | GetArray () const
template<typename T >
bool | Is () const
| Templated version for checking whether this value is type T.
template<typename T >
T | Get () const
template<typename T >
T | Get ()
template<typename T >
ValueType & | Set (const T &data)
template<typename T >
ValueType & | Set (const T &data, AllocatorType &allocator)
template<typename Handler >
bool | Accept (Handler &handler) const
| Generate events of this value to a Handler.
GenericValue & | operator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
| Assignment with move semantics.
GenericValue & | operator= (StringRefType str) RAPIDJSON_NOEXCEPT
| Assignment of constant string reference (no copy)
template<typename T >
GenericValue & | operator= (T value)
| Assignment with primitive types.
template<typename SourceAllocator >
GenericValue & | CopyFrom (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
| Deep-copy assignment from Value.
GenericValue & | Swap (GenericValue &other) RAPIDJSON_NOEXCEPT
| Exchange the contents of this value with those of other.
GenericValue & | Move () RAPIDJSON_NOEXCEPT
| Prepare Value for move semantics.
template<typename SourceAllocator >
bool | operator== (const GenericValue< Encoding, SourceAllocator > &rhs) const
| Equal-to operator.
bool | operator== (const Ch *rhs) const
| Equal-to operator with const C-string pointer.
template<typename T >
bool | operator== (const T &rhs) const
| Equal-to operator with primitive types.
template<typename SourceAllocator >
bool | operator!= (const GenericValue< Encoding, SourceAllocator > &rhs) const
| Not-equal-to operator.
bool | operator!= (const Ch *rhs) const
| Not-equal-to operator with const C-string pointer.
template<typename T >
bool | operator!= (const T &rhs) const
| Not-equal-to operator with arbitrary types.
| GenericValue () RAPIDJSON_NOEXCEPT
| Default constructor creates a null value.
| GenericValue (Type type) RAPIDJSON_NOEXCEPT
| Constructor with JSON value type.
template<typename SourceAllocator >
| GenericValue (const GenericValue< Encoding, SourceAllocator > &rhs, Allocator &allocator)
| Explicit copy constructor (with allocator)
| GenericValue (bool b) RAPIDJSON_NOEXCEPT
| Constructor for boolean value.
| 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 (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 (Array a) RAPIDJSON_NOEXCEPT
| Constructor for Array.
| GenericValue (Object o) RAPIDJSON_NOEXCEPT
| Constructor for Object.
| ~GenericValue ()
| Destructor.

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

## Detailed Description

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

A document for parsing JSON text as DOM.

Note
  implements Handler concept

Template Parameters

  Encoding | Encoding for both parsing and string storage.
  Allocator | Allocator for allocating memory for the DOM
  StackAllocator | Allocator 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 , typename StackAllocator >

rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::GenericDocument | ( | Type | type,
|  | Allocator * | allocator = 0,
|  | size_t | stackCapacity = kDefaultStackCapacity,
|  | StackAllocator * | stackAllocator = 0 )
| inline explicit

Constructor.

Creates an empty document of specified type.

Parameters

  type | Mandatory type of object to create.
  allocator | Optional allocator for allocating memory.
  stackCapacity | Optional initial capacity of stack in bytes.
  stackAllocator | Optional allocator for allocating memory for stack.

## ◆ GenericDocument() [2/2]

template<typename Encoding , typename Allocator , typename StackAllocator >

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

  allocator | Optional allocator for allocating memory.
  stackCapacity | Optional initial capacity of stack in bytes.
  stackAllocator | Optional allocator for allocating memory for stack.

## Member Function Documentation

## ◆ operator ParseResult()

template<typename Encoding , typename Allocator , typename StackAllocator >

rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::operator ParseResult | ( |  | ) | const
| inline

Implicit conversion to get the last parse result.

Returns
  ParseResult of the last parse operation

Document doc;
ParseResult ok = doc.Parse(json);
if (!ok)
printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset());
rapidjson::GenericDocument
A document for parsing JSON text as DOM.
Definition fwd.h:119
rapidjson::GenericDocument::Parse
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2219
rapidjson::ParseResult::Code
ParseErrorCode Code() const
Get the error code.
Definition error.h:114
rapidjson::ParseResult::Offset
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition error.h:116
rapidjson::GetParseError_En
const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition en.h:36
rapidjson::ParseResult
Result of parsing (wraps ParseErrorCode)
Definition error.h:106

## ◆ Parse() [1/3]

template<typename Encoding , typename Allocator , typename StackAllocator >
template<unsigned parseFlags>

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse | ( | const Ch * | str | ) |
| inline

Parse JSON text from a read-only string.

Template Parameters

  parseFlags | Combination of ParseFlag (must not contain kParseInsituFlag).

Parameters

  str | Read-only zero-terminated string to be parsed.

## ◆ Parse() [2/3]

template<typename Encoding , typename Allocator , typename StackAllocator >

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse | ( | const Ch * | str | ) |
| inline

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

Parameters

  str | Read-only zero-terminated string to be parsed.

## ◆ Parse() [3/3]

template<typename Encoding , typename Allocator , typename StackAllocator >
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

  parseFlags | Combination of ParseFlag (must not contain kParseInsituFlag).
  SourceEncoding | Transcoding from input Encoding

Parameters

  str | Read-only zero-terminated string to be parsed.

## ◆ ParseInsitu() [1/2]

template<typename Encoding , typename Allocator , typename StackAllocator >
template<unsigned parseFlags>

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseInsitu | ( | Ch * | str | ) |
| inline

Parse JSON text from a mutable string.

Template Parameters

  parseFlags | Combination of ParseFlag.

Parameters

  str | Mutable zero-terminated string to be parsed.

Returns
  The document itself for fluent API.

## ◆ ParseInsitu() [2/2]

template<typename Encoding , typename Allocator , typename StackAllocator >

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseInsitu | ( | Ch * | str | ) |
| inline

Parse JSON text from a mutable string (with kParseDefaultFlags)

Parameters

  str | Mutable zero-terminated string to be parsed.

Returns
  The document itself for fluent API.

## ◆ ParseStream() [1/3]

template<typename Encoding , typename Allocator , typename StackAllocator >
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

  parseFlags | Combination of ParseFlag.
  SourceEncoding | Encoding of input stream
  InputStream | Type of input stream, implementing Stream concept

Parameters

  is | Input stream to be parsed.

Returns
  The document itself for fluent API.

## ◆ ParseStream() [2/3]

template<typename Encoding , typename Allocator , typename StackAllocator >
template<unsigned parseFlags, typename InputStream >

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream | ( | InputStream & | is | ) |
| inline

Parse JSON text from an input stream.

Template Parameters

  parseFlags | Combination of ParseFlag.
  InputStream | Type of input stream, implementing Stream concept

Parameters

  is | Input stream to be parsed.

Returns
  The document itself for fluent API.

## ◆ ParseStream() [3/3]

template<typename Encoding , typename Allocator , typename StackAllocator >
template<typename InputStream >

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream | ( | InputStream & | is | ) |
| inline

Parse JSON text from an input stream (with kParseDefaultFlags)

Template Parameters

  InputStream | Type of input stream, implementing Stream concept

Parameters

  is | Input stream to be parsed.

Returns
  The document itself for fluent API.

## ◆ Populate()

template<typename Encoding , typename Allocator , typename StackAllocator >
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

  Generator | A functor with `bool f(Handler)` prototype.

Parameters

  g | Generator functor which sends SAX events to the parameter.

Returns
  The document itself for fluent API.

## ◆ Swap()

template<typename Encoding , typename Allocator , typename StackAllocator >

GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Swap | ( | GenericDocument< Encoding, Allocator, StackAllocator > & | rhs | ) |
| inline

Exchange the contents of this document with those of another.

Parameters

  rhs | Another document.

Note
  Constant complexity.

See also
  GenericValue::Swap

## Friends And Related Symbol Documentation

## ◆ swap

template<typename Encoding , typename Allocator , typename StackAllocator >

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);
// ...
}
rapidjson::GenericDocument::swap
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:2125

See also
  Swap()

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

- include/rapidjson/document.h
- include/rapidjson/fwd.h