rapidjson::GenericDocument< Encoding, Allocator, StackAllocator > 模板类 参考

A document for parsing JSON text as DOM. 更多...

#include <document.h>

Public 类型

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 成员函数

 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 更多...
 
GenericDocumentSwap (GenericDocument &rhs) RAPIDJSON_NOEXCEPT
 Exchange the contents of this document with those of another. 更多...
 
template<typename Generator >
GenericDocumentPopulate (Generator &g)
 Populate this document by a generator which produces SAX events. 更多...
 
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)
 
GenericValueSwap (GenericValue &other) RAPIDJSON_NOEXCEPT
 Exchange the contents of this value with those of other. 更多...
 
Parse from stream
template<unsigned parseFlags, typename SourceEncoding , typename InputStream >
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream (with Encoding conversion) 更多...
 
template<unsigned parseFlags, typename InputStream >
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream 更多...
 
template<typename InputStream >
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream (with kParseDefaultFlags) 更多...
 
Parse in-place from mutable string
template<unsigned parseFlags>
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string 更多...
 
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string (with kParseDefaultFlags) 更多...
 
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) 更多...
 
template<unsigned parseFlags>
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string 更多...
 
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string (with kParseDefaultFlags) 更多...
 
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 更多...
 

友元

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

详细描述

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.

注解
implements Handler concept
模板参数
EncodingEncoding for both parsing and string storage.
AllocatorAllocator for allocating memory for the DOM
StackAllocatorAllocator for allocating memory for stack during parsing.
警告
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.

构造及析构函数说明

◆ 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.

参数
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.

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

成员函数说明

◆ 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

返回
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

模板参数
parseFlagsCombination of ParseFlag (must not contain kParseInsituFlag).
参数
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)

参数
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)

模板参数
parseFlagsCombination of ParseFlag (must not contain kParseInsituFlag).
SourceEncodingTranscoding from input Encoding
参数
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

模板参数
parseFlagsCombination of ParseFlag.
参数
strMutable zero-terminated string to be parsed.
返回
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)

参数
strMutable zero-terminated string to be parsed.
返回
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)

模板参数
parseFlagsCombination of ParseFlag.
SourceEncodingEncoding of input stream
InputStreamType of input stream, implementing Stream concept
参数
isInput stream to be parsed.
返回
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

模板参数
parseFlagsCombination of ParseFlag.
InputStreamType of input stream, implementing Stream concept
参数
isInput stream to be parsed.
返回
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)

模板参数
InputStreamType of input stream, implementing Stream concept
参数
isInput stream to be parsed.
返回
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.

模板参数
GeneratorA functor with bool f(Handler) prototype.
参数
gGenerator functor which sends SAX events to the parameter.
返回
The document itself for fluent API.

◆ Swap() [1/2]

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.

参数
rhsAnother document.
注解
Constant complexity.
参见
GenericValue::Swap

◆ Swap() [2/2]

template<typename Encoding , typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericValue& rapidjson::GenericValue< Encoding, Allocator >::Swap
inline

Exchange the contents of this value with those of other.

参数
otherAnother value.
注解
Constant complexity.

友元及相关函数文档

◆ 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);
// ...
}
参见
Swap()

该类的文档由以下文件生成:
rapidjson::GenericDocument::swap
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition: document.h:2310
rapidjson::Document
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding
Definition: document.h:2585
rapidjson::GetParseError_En
const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition: en.h:36