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

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

`#include <document.h>`

## 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 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...
GenericDocument & | Swap (GenericDocument &rhs) RAPIDJSON_NOEXCEPT
| Exchange the contents of this document with those of another. More...
template<typename Generator >
GenericDocument & | Populate (Generator &g)
| Populate this document by a generator which produces SAX events. More...
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) More...
template<unsigned parseFlags, typename InputStream >
GenericDocument & | ParseStream (InputStream &is)
| Parse JSON text from an input stream. More...
template<typename InputStream >
GenericDocument & | ParseStream (InputStream &is)
| Parse JSON text from an input stream (with kParseDefaultFlags) More...
Parse in-place from mutable string
template<unsigned parseFlags>
GenericDocument & | ParseInsitu (Ch *str)
| Parse JSON text from a mutable string. More...
GenericDocument & | ParseInsitu (Ch *str)
| Parse JSON text from a mutable string (with kParseDefaultFlags) More...
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) More...
template<unsigned parseFlags>
GenericDocument & | Parse (const Ch *str)
| Parse JSON text from a read-only string. More...
GenericDocument & | Parse (const Ch *str)
| Parse JSON text from a read-only string (with kParseDefaultFlags) More...
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)
template<unsigned parseFlags, typename SourceEncoding >
GenericDocument & | Parse (const std::basic_string< typename SourceEncoding::Ch > &str)
template<unsigned parseFlags>
GenericDocument & | Parse (const std::basic_string< Ch > &str)
GenericDocument & | Parse (const std::basic_string< Ch > &str)
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. More...

## Friends

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

## Detailed Description

### template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>

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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>

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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>

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());

## Parse() [1/3]

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

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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>

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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
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 = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>

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 Function Documentation

## swap

template<typename Encoding , typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>

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:

- include/rapidjson/document.h

rapidjson::GenericDocument::swap
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2127
rapidjson::Document
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2402
rapidjson::GetParseError_En
const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition: en.h:36