IN2OSM  1.0.1
GenericDocument< Encoding, Allocator, StackAllocator >

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

#include <document.h>

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

Classes

struct  ClearStackOnExit
 

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...
 
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 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 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)
 
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
 
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 Attributes

Data data_
 

Static Public Attributes

static const SizeType kDefaultArrayCapacity = 16
 
static const SizeType kDefaultObjectCapacity = 16
 

Private Member Functions

 GenericDocument (const GenericDocument &)
 Prohibit copying. More...
 
GenericDocumentoperator= (const GenericDocument &)
 Prohibit assignment. More...
 
void ClearStack ()
 
void Destroy ()
 

Private Attributes

Allocator * allocator_
 
Allocator * ownAllocator_
 
internal::Stack< StackAllocator > stack_
 
ParseResult parseResult_
 

Static Private Attributes

static const size_t kDefaultStackCapacity = 1024
 

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 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 57 of file document.h.

Member Typedef Documentation

◆ AllocatorType

typedef Allocator AllocatorType

Allocator type from template parameter.

Definition at line 2128 of file document.h.

◆ Array

typedef GenericArray<false, ValueType> Array
inherited

Definition at line 591 of file document.h.

◆ Ch

typedef Encoding::Ch Ch

Character type derived from Encoding.

Definition at line 2126 of file document.h.

◆ ConstArray

typedef GenericArray<true, ValueType> ConstArray
inherited

Definition at line 592 of file document.h.

◆ ConstMemberIterator

typedef GenericMemberIterator<true,Encoding,Allocator>::Iterator ConstMemberIterator
inherited

Constant member iterator for iterating in object.

Definition at line 587 of file document.h.

◆ ConstObject

typedef GenericObject<true, ValueType> ConstObject
inherited

Definition at line 594 of file document.h.

◆ ConstValueIterator

typedef const GenericValue* ConstValueIterator
inherited

Constant value iterator for iterating in array.

Definition at line 589 of file document.h.

◆ EncodingType

typedef Encoding EncodingType
inherited

Encoding type from template parameter.

Definition at line 582 of file document.h.

◆ Member

typedef GenericMember<Encoding, Allocator> Member
inherited

Name-value pair in an object.

Definition at line 581 of file document.h.

◆ MemberIterator

typedef GenericMemberIterator<false,Encoding,Allocator>::Iterator MemberIterator
inherited

Member iterator for iterating in object.

Definition at line 586 of file document.h.

◆ Object

typedef GenericObject<false, ValueType> Object
inherited

Definition at line 593 of file document.h.

◆ StringRefType

typedef GenericStringRef<Ch> StringRefType
inherited

Reference to a constant string.

Definition at line 585 of file document.h.

◆ ValueIterator

typedef GenericValue* ValueIterator
inherited

Value iterator for iterating in array.

Definition at line 588 of file document.h.

◆ ValueType

typedef GenericValue<Encoding, Allocator> ValueType

Value type of the document.

Definition at line 2127 of file document.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
kBoolFlag 
kNumberFlag 
kIntFlag 
kUintFlag 
kInt64Flag 
kUint64Flag 
kDoubleFlag 
kStringFlag 
kCopyFlag 
kInlineStrFlag 
kNullFlag 
kTrueFlag 
kFalseFlag 
kNumberIntFlag 
kNumberUintFlag 
kNumberInt64Flag 
kNumberUint64Flag 
kNumberDoubleFlag 
kNumberAnyFlag 
kConstStringFlag 
kCopyStringFlag 
kShortStringFlag 
kObjectFlag 
kArrayFlag 
kTypeMask 

Definition at line 1911 of file document.h.

1911  {
1912  kBoolFlag = 0x0008,
1913  kNumberFlag = 0x0010,
1914  kIntFlag = 0x0020,
1915  kUintFlag = 0x0040,
1916  kInt64Flag = 0x0080,
1917  kUint64Flag = 0x0100,
1918  kDoubleFlag = 0x0200,
1919  kStringFlag = 0x0400,
1920  kCopyFlag = 0x0800,
1921  kInlineStrFlag = 0x1000,
1922 
1923  // Initial flags of different types.
1924  kNullFlag = kNullType,
1938 
1939  kTypeMask = 0x07
1940  };
object
Definition: rapidjson.h:646
array
Definition: rapidjson.h:647
false
Definition: rapidjson.h:644
string
Definition: rapidjson.h:648
number
Definition: rapidjson.h:649
true
Definition: rapidjson.h:645
null
Definition: rapidjson.h:643

Constructor & Destructor Documentation

◆ GenericDocument() [1/3]

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 2137 of file document.h.

2137  :
2138  GenericValue<Encoding, Allocator>(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2139  {
2140  if (!allocator_)
2141  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2142  }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:54
ParseResult parseResult_
Definition: document.h:2502
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:625
Allocator * allocator_
Definition: document.h:2499
Allocator * ownAllocator_
Definition: document.h:2500
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ GenericDocument() [2/3]

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 2150 of file document.h.

2150  :
2151  allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_()
2152  {
2153  if (!allocator_)
2154  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
2155  }
ParseResult parseResult_
Definition: document.h:2502
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:625
Allocator * allocator_
Definition: document.h:2499
Allocator * ownAllocator_
Definition: document.h:2500
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ ~GenericDocument()

~GenericDocument ( )
inline

Definition at line 2172 of file document.h.

2172  {
2173  Destroy();
2174  }
void Destroy()
Definition: document.h:2494

◆ GenericDocument() [3/3]

GenericDocument ( const GenericDocument< Encoding, Allocator, StackAllocator > &  )
private

Prohibit copying.

Member Function Documentation

◆ Bool()

bool Bool ( bool  b)
inline

Definition at line 2438 of file document.h.

2438 { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ ClearStack()

void ClearStack ( )
inlineprivate

Definition at line 2485 of file document.h.

2485  {
2486  if (Allocator::kNeedFree)
2487  while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
2488  (stack_.template Pop<ValueType>(1))->~ValueType();
2489  else
2490  stack_.Clear();
2491  stack_.ShrinkToFit();
2492  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
void Clear()
Definition: stack.h:98
size_t GetSize() const
Definition: stack.h:177
void ShrinkToFit()
Definition: stack.h:100
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ Destroy()

void Destroy ( )
inlineprivate

Definition at line 2494 of file document.h.

2494  {
2496  }
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:629
Allocator * ownAllocator_
Definition: document.h:2500

◆ Double()

bool Double ( double  d)
inline

Definition at line 2443 of file document.h.

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

◆ EndArray()

bool EndArray ( SizeType  elementCount)
inline

Definition at line 2473 of file document.h.

2473  {
2474  ValueType* elements = stack_.template Pop<ValueType>(elementCount);
2475  stack_.template Top<ValueType>()->SetArrayRaw(elements, elementCount, GetAllocator());
2476  return true;
2477  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2412
void SetArrayRaw(GenericValue *values, SizeType count, Allocator &allocator)
Definition: document.h:2034
internal::Stack< StackAllocator > stack_
Definition: document.h:2501
Here is the call graph for this function:

◆ EndObject()

bool EndObject ( SizeType  memberCount)
inline

Definition at line 2465 of file document.h.

2465  {
2466  typename ValueType::Member* members = stack_.template Pop<typename ValueType::Member>(memberCount);
2467  stack_.template Top<ValueType>()->SetObjectRaw(members, memberCount, GetAllocator());
2468  return true;
2469  }
void SetObjectRaw(Member *members, SizeType count, Allocator &allocator)
Initialize this value as object with initial data, without calling destructor.
Definition: document.h:2047
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2412
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:581
internal::Stack< StackAllocator > stack_
Definition: document.h:2501
Here is the call graph for this function:

◆ GetAllocator()

Allocator& GetAllocator ( )
inline

Get the allocator of this document.

Definition at line 2412 of file document.h.

2412  {
2414  return *allocator_;
2415  }
Allocator * allocator_
Definition: document.h:2499
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406

◆ GetElementsPointer()

RAPIDJSON_FORCEINLINE GenericValue* GetElementsPointer ( ) const
inlineinherited

Definition at line 2028 of file document.h.

Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:54
GenericValue * elements
Definition: document.h:2014
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:319
Here is the caller graph for this function:

◆ GetErrorOffset()

size_t GetErrorOffset ( ) const
inline

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

Definition at line 2394 of file document.h.

2394 { return parseResult_.Offset(); }
ParseResult parseResult_
Definition: document.h:2502
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:118

◆ GetMembersPointer()

RAPIDJSON_FORCEINLINE Member* GetMembersPointer ( ) const
inlineinherited

Definition at line 2030 of file document.h.

ObjectData o
Definition: document.h:2021
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:319
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:581
Here is the caller graph for this function:

◆ GetParseError()

ParseErrorCode GetParseError ( ) const
inline

Get the ParseErrorCode of last parsing.

Definition at line 2391 of file document.h.

2391 { return parseResult_.Code(); }
ParseResult parseResult_
Definition: document.h:2502
ParseErrorCode Code() const
Get the error code.
Definition: error.h:116

◆ GetStackCapacity()

size_t GetStackCapacity ( ) const
inline

Get the capacity of stack in bytes.

Definition at line 2418 of file document.h.

2418 { return stack_.GetCapacity(); }
internal::Stack< StackAllocator > stack_
Definition: document.h:2501
size_t GetCapacity() const
Definition: stack.h:178

◆ GetStringPointer()

RAPIDJSON_FORCEINLINE const Ch* GetStringPointer ( ) const
inlineinherited

Definition at line 2026 of file document.h.

2026 { return RAPIDJSON_GETPOINTER(Ch, data_.s.str); }
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:584
#define RAPIDJSON_GETPOINTER(type, p)
Definition: rapidjson.h:319

◆ HasParseError()

bool HasParseError ( ) const
inline

Whether a parse error has occurred in the last parsing.

Definition at line 2388 of file document.h.

2388 { return parseResult_.IsError(); }
ParseResult parseResult_
Definition: document.h:2502
bool IsError() const
Whether the result is an error.
Definition: error.h:123

◆ Int()

bool Int ( int  i)
inline

Definition at line 2439 of file document.h.

2439 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ Int64()

bool Int64 ( int64_t  i)
inline

Definition at line 2441 of file document.h.

2441 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ Key()

bool Key ( const Ch str,
SizeType  length,
bool  copy 
)
inline

Definition at line 2463 of file document.h.

2463 { return String(str, length, copy); }
bool String(const Ch *str, SizeType length, bool copy)
Definition: document.h:2453

◆ Null()

bool Null ( )
inline

Definition at line 2437 of file document.h.

2437 { new (stack_.template Push<ValueType>()) ValueType(); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ operator ParseResult()

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

Definition at line 2408 of file document.h.

2408 { return parseResult_; }
ParseResult parseResult_
Definition: document.h:2502

◆ operator=()

GenericDocument& operator= ( const GenericDocument< Encoding, Allocator, StackAllocator > &  )
private

Prohibit assignment.

◆ Parse() [1/6]

GenericDocument& 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 2325 of file document.h.

2325  {
2326  RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
2328  return ParseStream<parseFlags, SourceEncoding>(s);
2329  }
Read-only string stream.
Definition: fwd.h:47
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
In-situ(destructive) parsing.
Definition: reader.h:147

◆ Parse() [2/6]

GenericDocument& 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 2336 of file document.h.

2336  {
2337  return Parse<parseFlags, Encoding>(str);
2338  }

◆ Parse() [3/6]

GenericDocument& 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 2343 of file document.h.

2343  {
2344  return Parse<kParseDefaultFlags>(str);
2345  }

◆ Parse() [4/6]

GenericDocument& Parse ( const typename SourceEncoding::Ch *  str,
size_t  length 
)
inline

Definition at line 2348 of file document.h.

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

◆ Parse() [5/6]

GenericDocument& Parse ( const Ch str,
size_t  length 
)
inline

Definition at line 2357 of file document.h.

2357  {
2358  return Parse<parseFlags, Encoding>(str, length);
2359  }

◆ Parse() [6/6]

GenericDocument& Parse ( const Ch str,
size_t  length 
)
inline

Definition at line 2361 of file document.h.

2361  {
2362  return Parse<kParseDefaultFlags>(str, length);
2363  }

◆ ParseInsitu() [1/2]

GenericDocument& 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 2302 of file document.h.

2302  {
2304  return ParseStream<parseFlags | kParseInsituFlag>(s);
2305  }
A read-write string stream.
Definition: fwd.h:52

◆ ParseInsitu() [2/2]

GenericDocument& 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 2311 of file document.h.

2311  {
2312  return ParseInsitu<kParseDefaultFlags>(str);
2313  }

◆ ParseStream() [1/3]

GenericDocument& 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 2259 of file document.h.

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

◆ ParseStream() [2/3]

GenericDocument& 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 2278 of file document.h.

2278  {
2279  return ParseStream<parseFlags, Encoding, InputStream>(is);
2280  }

◆ ParseStream() [3/3]

GenericDocument& 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 2288 of file document.h.

2288  {
2289  return ParseStream<kParseDefaultFlags, Encoding, InputStream>(is);
2290  }

◆ Populate()

GenericDocument& 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 2239 of file document.h.

2239  {
2240  ClearStackOnExit scope(*this);
2241  if (g(*this)) {
2242  RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
2243  ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
2244  }
2245  return *this;
2246  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
GenericValue & operator=(GenericValue &rhs) RAPIDJSON_NOEXCEPT
Assignment with move semantics.
Definition: document.h:836
size_t GetSize() const
Definition: stack.h:177
internal::Stack< StackAllocator > stack_
Definition: document.h:2501
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406

◆ RAPIDJSON_DISABLEIF_RETURN()

RAPIDJSON_DISABLEIF_RETURN ( (internal::IsPointer< T >)  ,
(GenericValue< Encoding, Allocator > &)   
)
inherited

Assignment with primitive types.

Template Parameters
TEither Type, int, unsigned, int64_t, uint64_t
Parameters
valueThe value to be assigned.
Note
The source type T explicitly disallows all pointer types, especially (const) Ch*. This helps avoiding implicitly referencing character strings with insufficient lifetime, use SetString(const Ch*, Allocator&) (for copying) or StringRef() (to explicitly mark the pointer as constant) instead. All other pointer types would implicitly convert to bool, use SetBool() instead.Set boolean value

◆ RawAssign()

void RawAssign ( GenericValue< Encoding, Allocator > &  rhs)
inlineinherited

Assignment without calling destructor.

Definition at line 2084 of file document.h.

2084  {
2085  data_ = rhs.data_;
2086  // data_.f.flags = rhs.data_.f.flags;
2087  rhs.data_.f.flags = kNullFlag;
2088  }
Here is the caller graph for this function:

◆ RawNumber()

bool RawNumber ( const Ch str,
SizeType  length,
bool  copy 
)
inline

Definition at line 2445 of file document.h.

2445  {
2446  if (copy)
2447  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2448  else
2449  new (stack_.template Push<ValueType>()) ValueType(str, length);
2450  return true;
2451  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2412
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ SetArrayRaw()

void SetArrayRaw ( GenericValue< Encoding, Allocator > *  values,
SizeType  count,
Allocator &  allocator 
)
inlineinherited

Definition at line 2034 of file document.h.

2034  {
2035  data_.f.flags = kArrayFlag;
2036  if (count) {
2037  GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
2038  SetElementsPointer(e);
2039  std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
2040  }
2041  else
2042  SetElementsPointer(0);
2043  data_.a.size = data_.a.capacity = count;
2044  }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:54
RAPIDJSON_FORCEINLINE GenericValue * SetElementsPointer(GenericValue *elements)
Definition: document.h:2029
Here is the caller graph for this function:

◆ SetElementsPointer()

RAPIDJSON_FORCEINLINE GenericValue* SetElementsPointer ( GenericValue< Encoding, Allocator > *  elements)
inlineinherited

Definition at line 2029 of file document.h.

2029 { return RAPIDJSON_SETPOINTER(GenericValue, data_.a.elements, elements); }
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:54
GenericValue * elements
Definition: document.h:2014
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:318

◆ SetMembersPointer()

RAPIDJSON_FORCEINLINE Member* SetMembersPointer ( Member members)
inlineinherited

Definition at line 2031 of file document.h.

2031 { return RAPIDJSON_SETPOINTER(Member, data_.o.members, members); }
ObjectData o
Definition: document.h:2021
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:318
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:581

◆ SetObjectRaw()

void SetObjectRaw ( Member members,
SizeType  count,
Allocator &  allocator 
)
inlineinherited

Initialize this value as object with initial data, without calling destructor.

Definition at line 2047 of file document.h.

2047  {
2049  if (count) {
2050  Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
2051  SetMembersPointer(m);
2052  std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
2053  }
2054  else
2055  SetMembersPointer(0);
2056  data_.o.size = data_.o.capacity = count;
2057  }
RAPIDJSON_FORCEINLINE Member * SetMembersPointer(Member *members)
Definition: document.h:2031
ObjectData o
Definition: document.h:2021
GenericMember< Encoding, Allocator > Member
Name-value pair in an object.
Definition: document.h:581
Here is the caller graph for this function:

◆ SetStringPointer()

RAPIDJSON_FORCEINLINE const Ch* SetStringPointer ( const Ch str)
inlineinherited

Definition at line 2027 of file document.h.

2027 { return RAPIDJSON_SETPOINTER(Ch, data_.s.str, str); }
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:584
#define RAPIDJSON_SETPOINTER(type, p, x)
Definition: rapidjson.h:318

◆ SetStringRaw() [1/2]

void SetStringRaw ( StringRefType  s)
inlineinherited

Initialize this value as constant string, without calling destructor.

Definition at line 2060 of file document.h.

2060  {
2062  SetStringPointer(s);
2063  data_.s.length = s.length;
2064  }
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:2027

◆ SetStringRaw() [2/2]

void SetStringRaw ( StringRefType  s,
Allocator &  allocator 
)
inlineinherited

Initialize this value as copy string with initial data, without calling destructor.

Definition at line 2067 of file document.h.

2067  {
2068  Ch* str = 0;
2069  if (ShortString::Usable(s.length)) {
2071  data_.ss.SetLength(s.length);
2072  str = data_.ss.str;
2073  } else {
2075  data_.s.length = s.length;
2076  str = static_cast<Ch *>(allocator.Malloc((s.length + 1) * sizeof(Ch)));
2077  SetStringPointer(str);
2078  }
2079  std::memcpy(str, s, s.length * sizeof(Ch));
2080  str[s.length] = '\0';
2081  }
void SetLength(SizeType len)
Definition: document.h:1975
RAPIDJSON_FORCEINLINE const Ch * SetStringPointer(const Ch *str)
Definition: document.h:2027
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:584
ShortString ss
Definition: document.h:2019
static bool Usable(SizeType len)
Definition: document.h:1974

◆ StartArray()

bool StartArray ( )
inline

Definition at line 2471 of file document.h.

2471 { new (stack_.template Push<ValueType>()) ValueType(kArrayType); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
array
Definition: rapidjson.h:647
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ StartObject()

bool StartObject ( )
inline

Definition at line 2461 of file document.h.

2461 { new (stack_.template Push<ValueType>()) ValueType(kObjectType); return true; }
object
Definition: rapidjson.h:646
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ String()

bool String ( const Ch str,
SizeType  length,
bool  copy 
)
inline

Definition at line 2453 of file document.h.

2453  {
2454  if (copy)
2455  new (stack_.template Push<ValueType>()) ValueType(str, length, GetAllocator());
2456  else
2457  new (stack_.template Push<ValueType>()) ValueType(str, length);
2458  return true;
2459  }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2412
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ StringEqual()

bool StringEqual ( const GenericValue< Encoding, SourceAllocator > &  rhs) const
inlineinherited

Definition at line 2091 of file document.h.

2091  {
2092  RAPIDJSON_ASSERT(IsString());
2093  RAPIDJSON_ASSERT(rhs.IsString());
2094 
2095  const SizeType len1 = GetStringLength();
2096  const SizeType len2 = rhs.GetStringLength();
2097  if(len1 != len2) { return false; }
2098 
2099  const Ch* const str1 = GetString();
2100  const Ch* const str2 = rhs.GetString();
2101  if(str1 == str2) { return true; } // fast path for constant string
2102 
2103  return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
2104  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Encoding::Ch Ch
Character type derived from Encoding.
Definition: document.h:584
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the caller graph for this function:

◆ Swap()

GenericDocument& 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 2206 of file document.h.

2206  {
2207  ValueType::Swap(rhs);
2208  stack_.Swap(rhs.stack_);
2212  return *this;
2213  }
void Swap(Stack &rhs) RAPIDJSON_NOEXCEPT
Definition: stack.h:89
ParseResult parseResult_
Definition: document.h:2502
Allocator * allocator_
Definition: document.h:2499
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
Allocator * ownAllocator_
Definition: document.h:2500
internal::Stack< StackAllocator > stack_
Definition: document.h:2501
Here is the call graph for this function:

◆ Uint()

bool Uint ( unsigned  i)
inline

Definition at line 2440 of file document.h.

2440 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

◆ Uint64()

bool Uint64 ( uint64_t  i)
inline

Definition at line 2442 of file document.h.

2442 { new (stack_.template Push<ValueType>()) ValueType(i); return true; }
GenericValue< Encoding, Allocator > ValueType
Value type of the document.
Definition: document.h:2127
internal::Stack< StackAllocator > stack_
Definition: document.h:2501

Friends And Related Function Documentation

◆ GenericValue

friend class GenericValue
friend

Definition at line 2433 of file document.h.

◆ swap

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 2231 of file document.h.

2231 { a.Swap(b); }
GenericDocument & Swap(GenericDocument &rhs) RAPIDJSON_NOEXCEPT
Exchange the contents of this document with those of another.
Definition: document.h:2206

Member Data Documentation

◆ allocator_

Allocator* allocator_
private

Definition at line 2499 of file document.h.

◆ data_

Data data_
inherited

Definition at line 2106 of file document.h.

◆ kDefaultArrayCapacity

const SizeType kDefaultArrayCapacity = 16
staticinherited

Definition at line 1942 of file document.h.

◆ kDefaultObjectCapacity

const SizeType kDefaultObjectCapacity = 16
staticinherited

Definition at line 1943 of file document.h.

◆ kDefaultStackCapacity

const size_t kDefaultStackCapacity = 1024
staticprivate

Definition at line 2498 of file document.h.

◆ ownAllocator_

Allocator* ownAllocator_
private

Definition at line 2500 of file document.h.

◆ parseResult_

ParseResult parseResult_
private

Definition at line 2502 of file document.h.

◆ stack_

internal::Stack<StackAllocator> stack_
private

Definition at line 2501 of file document.h.


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