Electroneum
GenericDocument< Encoding, Allocator, StackAllocator > Class Template Reference

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

#include <document.h>

Inheritance diagram for GenericDocument< Encoding, Allocator, StackAllocator >:
Collaboration diagram for GenericDocument< Encoding, Allocator, StackAllocator >:

Public Types

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

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 ()
 
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...
 
Allocator & GetAllocator ()
 Get the allocator of this document. More...
 
size_t GetStackCapacity () const
 Get the capacity of stack in bytes. More...
 
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)
 
Handling parse errors
bool HasParseError () const
 Whether a parse error has occurred in the last parsing. More...
 
ParseErrorCode GetParseError () const
 Get the ParseErrorCode of last parsing. More...
 
size_t GetErrorOffset () const
 Get the position of last parsing error in input, 0 otherwise. More...
 
 operator ParseResult () const
 Implicit conversion to get the last parse result. More...
 
- Public Member Functions inherited from GenericValue< Encoding, Allocator >
template<typename T >
 RAPIDJSON_DISABLEIF_RETURN ((internal::IsPointer< T >),(GenericValue &)) operator
 Assignment with primitive types. More...
 
RAPIDJSON_FORCEINLINE const ChGetStringPointer () const
 
RAPIDJSON_FORCEINLINE const ChSetStringPointer (const Ch *str)
 
RAPIDJSON_FORCEINLINE GenericValueGetElementsPointer () const
 
RAPIDJSON_FORCEINLINE GenericValueSetElementsPointer (GenericValue *elements)
 
RAPIDJSON_FORCEINLINE MemberGetMembersPointer () const
 
RAPIDJSON_FORCEINLINE MemberSetMembersPointer (Member *members)
 
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. More...
 
void SetStringRaw (StringRefType s) RAPIDJSON_NOEXCEPT
 Initialize this value as constant string, without calling destructor. More...
 
void SetStringRaw (StringRefType s, Allocator &allocator)
 Initialize this value as copy string with initial data, without calling destructor. More...
 
void RawAssign (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment without calling destructor. More...
 
template<typename SourceAllocator >
bool StringEqual (const GenericValue< Encoding, SourceAllocator > &rhs) const
 
GenericValueoperator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment with move semantics. More...
 
GenericValueoperator= (StringRefType str) RAPIDJSON_NOEXCEPT
 Assignment of constant string reference (no copy) More...
 
 GenericValue () RAPIDJSON_NOEXCEPT
 Default constructor creates a null value. More...
 
 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...
 
template<typename T >
 GenericValue (T b, RAPIDJSON_ENABLEIF((internal::IsSame< bool, T >))) RAPIDJSON_NOEXCEPT
 Constructor for boolean value. More...
 
 GenericValue (int i) RAPIDJSON_NOEXCEPT
 Constructor for int value. More...
 
 GenericValue (unsigned u) RAPIDJSON_NOEXCEPT
 Constructor for unsigned value. More...
 
 GenericValue (int64_t i64) RAPIDJSON_NOEXCEPT
 Constructor for int64_t value. More...
 
 GenericValue (uint64_t u64) RAPIDJSON_NOEXCEPT
 Constructor for uint64_t value. More...
 
 GenericValue (double d) RAPIDJSON_NOEXCEPT
 Constructor for double value. More...
 
 GenericValue (float f) RAPIDJSON_NOEXCEPT
 Constructor for float value. More...
 
 GenericValue (const Ch *s, SizeType length) RAPIDJSON_NOEXCEPT
 Constructor for constant string (i.e. do not make a copy of string) More...
 
 GenericValue (StringRefType s) RAPIDJSON_NOEXCEPT
 Constructor for constant string (i.e. do not make a copy of string) More...
 
 GenericValue (const Ch *s, SizeType length, Allocator &allocator)
 Constructor for copy-string (i.e. do make a copy of string) More...
 
 GenericValue (const Ch *s, Allocator &allocator)
 Constructor for copy-string (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

- Public Attributes inherited from GenericValue< Encoding, Allocator >
Data data_
 
- Static Public Attributes inherited from GenericValue< Encoding, Allocator >
static const SizeType kDefaultArrayCapacity = 16
 
static const SizeType kDefaultObjectCapacity = 16
 

Detailed Description

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

Definition at line 60 of file document.h.

Member Typedef Documentation

◆ AllocatorType

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

Allocator type from template parameter.

Definition at line 2134 of file document.h.

◆ Ch

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

Character type derived from Encoding.

Definition at line 2132 of file document.h.

◆ ValueType

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

Value type of the document.

Definition at line 2133 of file document.h.

Constructor & Destructor Documentation

◆ GenericDocument() [1/2]

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

Definition at line 2143 of file document.h.

2143  :
2144  GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2145  {
2146  if (!allocator_)
2147  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2148  }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:603

◆ GenericDocument() [2/2]

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

Definition at line 2156 of file document.h.

2156  :
2157  allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2158  {
2159  if (!allocator_)
2160  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2161  }
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:603

◆ ~GenericDocument()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
GenericDocument< Encoding, Allocator, StackAllocator >::~GenericDocument ( )
inline

Definition at line 2178 of file document.h.

2178  {
2179  Destroy();
2180  }

Member Function Documentation

◆ Bool()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Bool ( bool  b)
inline

Definition at line 2444 of file document.h.

2444 { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ Double()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Double ( double  d)
inline

Definition at line 2449 of file document.h.

2449 { new (stack_.template Push<ValueType>()) ValueType(d); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ EndArray()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::EndArray ( SizeType  elementCount)
inline

Definition at line 2479 of file document.h.

2479  {
2480  ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2481  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2482  return true;
2483  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2418
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator)
Definition: document.h:2030

◆ EndObject()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::EndObject ( SizeType  memberCount)
inline

Definition at line 2471 of file document.h.

2471  {
2472  typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2473  stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2474  return true;
2475  }
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2418
void SetObjectRaw(Member *members, SizeType count, Allocator &allocator)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:2048
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:578

◆ GetAllocator()

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

Get the allocator of this document.

Definition at line 2418 of file document.h.

2418  {
2419  RAPIDJSON_ASSERT(allocator_);
2420  return *allocator_;
2421  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
Here is the caller graph for this function:

◆ GetErrorOffset()

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

Get the position of last parsing error in input, 0 otherwise.

Definition at line 2400 of file document.h.

2400 { return parseResult_.Offset(); }
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118
Here is the caller graph for this function:

◆ GetParseError()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
ParseErrorCode GenericDocument< Encoding, Allocator, StackAllocator >::GetParseError ( ) const
inline

Get the ParseErrorCode of last parsing.

Definition at line 2397 of file document.h.

2397 { return parseResult_.Code(); }
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116
Here is the caller graph for this function:

◆ GetStackCapacity()

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

Get the capacity of stack in bytes.

Definition at line 2424 of file document.h.

2424 { return stack_.GetCapacity(); }
size_t GetCapacity() const
Definition: stack.h:178

◆ HasParseError()

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

Whether a parse error has occurred in the last parsing.

Definition at line 2394 of file document.h.

2394 { return parseResult_.IsError(); }
bool IsError() const
Whether the result is an error.
Definition: error.h:123
Here is the caller graph for this function:

◆ Int()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Int ( int  i)
inline

Definition at line 2445 of file document.h.

2445 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ Int64()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Int64 ( int64_t  i)
inline

Definition at line 2447 of file document.h.

2447 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ Key()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Key ( const Ch str,
SizeType  length,
bool  copy 
)
inline

Definition at line 2469 of file document.h.

2469 { return String(str, length, copy); }
bool String(const Ch *str, SizeType length, bool copy)
Definition: document.h:2459
void copy(key &AA, const key &A)
Definition: rctOps.h:79

◆ Null()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Null ( )
inline

Definition at line 2443 of file document.h.

2443 { new (stack_.template Push<ValueType>()) ValueType(); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ operator ParseResult()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
GenericDocument< Encoding, Allocator, StackAllocator >::operator ParseResult ( ) const
inline

Implicit conversion to get the last parse result.

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

Definition at line 2414 of file document.h.

2414 { return parseResult_; }

◆ Parse() [1/6]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename SourceEncoding >
GenericDocument& 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.

Definition at line 2331 of file document.h.

2331  {
2332  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2334  return ParseStream<parseFlags, SourceEncoding>(s);
2335  }
Read-only string stream.
Definition: fwd.h:47
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
In-situ(destructive) parsing.
Definition: reader.h:147
Here is the caller graph for this function:

◆ Parse() [2/6]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags>
GenericDocument& 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.

Definition at line 2342 of file document.h.

2342  {
2343  return Parse<parseFlags, Encoding>(str);
2344  }

◆ Parse() [3/6]

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

Definition at line 2349 of file document.h.

2349  {
2350  return Parse<kParseDefaultFlags>(str);
2351  }

◆ Parse() [4/6]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename SourceEncoding >
GenericDocument& GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const typename SourceEncoding::Ch str,
size_t  length 
)
inline

Definition at line 2354 of file document.h.

2354  {
2355  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2356  MemoryStream ms(reinterpret_cast<const char*>(str), length * sizeof(typename SourceEncoding::Ch));
2358  ParseStream<parseFlags, SourceEncoding>(is);
2359  return *this;
2360  }
Represents an in-memory input byte stream.
Definition: memorystream.h:40
#define Ch(x, y, z)
Definition: hash_impl.h:17
Input byte stream wrapper with a statically bound encoding.
Definition: encodedstream.h:39
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
In-situ(destructive) parsing.
Definition: reader.h:147

◆ Parse() [5/6]

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

Definition at line 2363 of file document.h.

2363  {
2364  return Parse<parseFlags, Encoding>(str, length);
2365  }

◆ Parse() [6/6]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
GenericDocument& GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const Ch str,
size_t  length 
)
inline

Definition at line 2367 of file document.h.

2367  {
2368  return Parse<kParseDefaultFlags>(str, length);
2369  }

◆ ParseInsitu() [1/2]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags>
GenericDocument& 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.

Definition at line 2308 of file document.h.

2308  {
2310  return ParseStream<parseFlags | kParseInsituFlag>(s);
2311  }
A read-write string stream.
Definition: fwd.h:52
Here is the caller graph for this function:

◆ ParseInsitu() [2/2]

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

Definition at line 2317 of file document.h.

2317  {
2318  return ParseInsitu<kParseDefaultFlags>(str);
2319  }

◆ ParseStream() [1/3]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename SourceEncoding , typename InputStream >
GenericDocument& 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.

Definition at line 2265 of file document.h.

2265  {
2267  stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
2268  ClearStackOnExit scope(*this);
2269  parseResult_ = reader.template Parse<parseFlags>(is, *this);
2270  if (parseResult_) {
2271  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2272  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2273  }
2274  return *this;
2275  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
size_t GetSize() const
Definition: stack.h:177
Allocator & GetAllocator()
Definition: stack.h:171
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: fwd.h:88
bool HasAllocator() const
Definition: stack.h:167
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:833
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
Here is the caller graph for this function:

◆ ParseStream() [2/3]

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream >
GenericDocument& 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.

Definition at line 2284 of file document.h.

2284  {
2285  return ParseStream<parseFlags, Encoding, InputStream>(is);
2286  }

◆ ParseStream() [3/3]

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

Definition at line 2294 of file document.h.

2294  {
2295  return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2296  }

◆ Populate()

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

Definition at line 2245 of file document.h.

2245  {
2246  ClearStackOnExit scope(*this);
2247  if (g(*this)) {
2248  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2249  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2250  }
2251  return *this;
2252  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
size_t GetSize() const
Definition: stack.h:177
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:833
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
Here is the caller graph for this function:

◆ RawNumber()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::RawNumber ( const Ch str,
SizeType  length,
bool  copy 
)
inline

Definition at line 2451 of file document.h.

2451  {
2452  if (copy)
2453  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2454  else
2455  new (stack_.template Push<ValueType>()) ValueType(str, length);
2456  return true;
2457  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
void copy(key &AA, const key &A)
Definition: rctOps.h:79
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2418

◆ StartArray()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::StartArray ( )
inline

Definition at line 2477 of file document.h.

2477 { new (stack_.template Push<ValueType>()) ValueType(kArrayType); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
array
Definition: rapidjson.h:625

◆ StartObject()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::StartObject ( )
inline

Definition at line 2467 of file document.h.

2467 { new (stack_.template Push<ValueType>()) ValueType(kObjectType); return true; }
object
Definition: rapidjson.h:624
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ String()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::String ( const Ch str,
SizeType  length,
bool  copy 
)
inline

Definition at line 2459 of file document.h.

2459  {
2460  if (copy)
2461  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2462  else
2463  new (stack_.template Push<ValueType>()) ValueType(str, length);
2464  return true;
2465  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133
void copy(key &AA, const key &A)
Definition: rctOps.h:79
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2418
Here is the caller graph for this function:

◆ Swap()

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

Definition at line 2212 of file document.h.

2212  {
2213  ValueType::Swap(rhs);
2214  stack_.Swap(rhs.stack_);
2215  internal::Swap(allocator_, rhs.allocator_);
2216  internal::Swap(ownAllocator_, rhs.ownAllocator_);
2217  internal::Swap(parseResult_, rhs.parseResult_);
2218  return *this;
2219  }
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
void Swap(Stack &rhs) RAPIDJSON_NOEXCEPT
Definition: stack.h:89
Here is the caller graph for this function:

◆ Uint()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Uint ( unsigned  i)
inline

Definition at line 2446 of file document.h.

2446 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

◆ Uint64()

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
bool GenericDocument< Encoding, Allocator, StackAllocator >::Uint64 ( uint64_t  i)
inline

Definition at line 2448 of file document.h.

2448 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2133

Friends And Related Function Documentation

◆ GenericValue

template<typename Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
template<typename , typename >
friend class GenericValue
friend

Definition at line 2439 of file document.h.

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

Definition at line 2237 of file document.h.

2237 { a.Swap(b); }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124

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