DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

GenericDocument< Encoding, Allocator, StackAllocator > Class Template Reference

GenericDocument< Encoding, Allocator, StackAllocator > Class Template Reference

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

#include <document.h>

Inherits GenericValue< Encoding, Allocator >.

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.
typedef GenericMember
< Encoding, Allocator > 
Member
 Name-value pair in an object.
typedef Encoding EncodingType
 Encoding type from template parameter.
typedef GenericStringRef< ChStringRefType
 Reference to a constant string.
typedef GenericMemberIterator
< false, Encoding, Allocator >
::Iterator 
MemberIterator
 Member iterator for iterating in object.
typedef GenericMemberIterator
< true, Encoding, Allocator >
::Iterator 
ConstMemberIterator
 Constant member iterator for iterating in object.
typedef GenericValueValueIterator
 Value iterator for iterating in array.
typedef const GenericValueConstValueIterator
 Constant value iterator for iterating in array.

Public Member Functions

 GenericDocument (Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
 Constructor.
 GenericDocument (Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
 Constructor.
 GenericDocument (GenericDocument &&rhs) RAPIDJSON_NOEXCEPT
 Move constructor in C++11.
GenericDocumentoperator= (GenericDocument &&rhs) RAPIDJSON_NOEXCEPT
 Move assignment in C++11.
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.
Allocator & GetAllocator ()
 Get the allocator of this document.
size_t GetStackCapacity () const
 Get the capacity of stack in bytes.
template<typename T >
 RAPIDJSON_DISABLEIF_RETURN ((internal::IsPointer< T >),(GenericValue &)) operator
 Assignment with primitive types.
void SetObjectRaw (Member *members, SizeType count, Allocator &allocator)
 Initialize this value as object with initial data, without calling destructor.
void SetStringRaw (StringRefType s) RAPIDJSON_NOEXCEPT
 Initialize this value as constant string, without calling destructor.
void SetStringRaw (StringRefType s, Allocator &allocator)
 Initialize this value as copy string with initial data, without calling destructor.
void RawAssign (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment without calling destructor.
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 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.

Friends

class GenericValue
void swap (GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
 free-standing swap function helper
class GenericDocument

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


Member Typedef Documentation

typedef Allocator AllocatorType

Allocator type from template parameter.

Reimplemented from GenericValue< Encoding, Allocator >.

Definition at line 2028 of file document.h.

typedef Encoding::Ch Ch

Character type derived from Encoding.

Reimplemented from GenericValue< Encoding, Allocator >.

Definition at line 2026 of file document.h.

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

Constant member iterator for iterating in object.

Definition at line 549 of file document.h.

typedef const GenericValue* ConstValueIterator [inherited]

Constant value iterator for iterating in array.

Definition at line 551 of file document.h.

typedef Encoding EncodingType [inherited]

Encoding type from template parameter.

Definition at line 544 of file document.h.

typedef GenericMember<Encoding, Allocator> Member [inherited]

Name-value pair in an object.

Definition at line 543 of file document.h.

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

Member iterator for iterating in object.

Definition at line 548 of file document.h.

typedef GenericStringRef<Ch> StringRefType [inherited]

Reference to a constant string.

Definition at line 547 of file document.h.

typedef GenericValue* ValueIterator [inherited]

Value iterator for iterating in array.

Definition at line 550 of file document.h.

typedef GenericValue<Encoding, Allocator> ValueType

Value type of the document.

Reimplemented from GenericValue< Encoding, Allocator >.

Definition at line 2027 of file document.h.


Constructor & Destructor Documentation

GenericDocument ( Type  type,
Allocator *  allocator = 0,
size_t  stackCapacity = kDefaultStackCapacity,
StackAllocator *  stackAllocator = 0 
) [explicit]

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

GenericDocument ( Allocator *  allocator = 0,
size_t  stackCapacity = kDefaultStackCapacity,
StackAllocator *  stackAllocator = 0 
)

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

GenericDocument ( GenericDocument< Encoding, Allocator, StackAllocator > &&  rhs )

Move constructor in C++11.

Definition at line 2059 of file document.h.


Member Function Documentation

Allocator& GetAllocator (  )

Get the allocator of this document.

Definition at line 2308 of file document.h.

size_t GetErrorOffset (  ) const

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

Definition at line 2290 of file document.h.

ParseErrorCode GetParseError (  ) const

Get the ParseErrorCode of last parsing.

Definition at line 2287 of file document.h.

size_t GetStackCapacity (  ) const

Get the capacity of stack in bytes.

Definition at line 2314 of file document.h.

bool HasParseError (  ) const

Whether a parse error has occured in the last parsing.

Definition at line 2284 of file document.h.

operator ParseResult (  ) const

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

Definition at line 2304 of file document.h.

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

Move assignment in C++11.

Reimplemented from GenericValue< Encoding, Allocator >.

Definition at line 2078 of file document.h.

GenericDocument& Parse ( const typename SourceEncoding::Ch *  str )

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

GenericDocument& Parse ( const Ch str )

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

GenericDocument& Parse ( const Ch str )

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

Parameters:
strRead-only zero-terminated string to be parsed.

Definition at line 2239 of file document.h.

GenericDocument& ParseInsitu ( Ch str )

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

GenericDocument& ParseInsitu ( Ch str )

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

GenericDocument& ParseStream ( InputStream &  is )

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

GenericDocument& ParseStream ( InputStream &  is )

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

GenericDocument& ParseStream ( InputStream &  is )

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

GenericDocument& Populate ( Generator &  g )

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

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
void RawAssign ( GenericValue< Encoding, Allocator > &  rhs ) [inherited]

Assignment without calling destructor.

Definition at line 1984 of file document.h.

void SetObjectRaw ( Member members,
SizeType  count,
Allocator &  allocator 
) [inherited]

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

Definition at line 1947 of file document.h.

void SetStringRaw ( StringRefType  s,
Allocator &  allocator 
) [inherited]

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

Definition at line 1967 of file document.h.

void SetStringRaw ( StringRefType  s ) [inherited]

Initialize this value as constant string, without calling destructor.

Definition at line 1960 of file document.h.

GenericDocument& Swap ( GenericDocument< Encoding, Allocator, StackAllocator > &  rhs )

Exchange the contents of this document with those of another.

Parameters:
rhsAnother document.
Note:
Constant complexity.
See also:
GenericValue::Swap

Definition at line 2106 of file document.h.


Friends And Related Function Documentation

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