Electroneum
Loading...
Searching...
No Matches
GenericReader< SourceEncoding, TargetEncoding, StackAllocator > Class Template Reference

SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator. More...

#include <reader.h>

Public Types

typedef SourceEncoding::Ch Ch
 SourceEncoding character type.

Public Member Functions

 GenericReader (StackAllocator *stackAllocator=0, size_t stackCapacity=kDefaultStackCapacity)
 Constructor.
template<unsigned parseFlags, typename InputStream, typename Handler>
ParseResult Parse (InputStream &is, Handler &handler)
 Parse JSON text.
template<typename InputStream, typename Handler>
ParseResult Parse (InputStream &is, Handler &handler)
 Parse JSON text (with kParseDefaultFlags).
void IterativeParseInit ()
 Initialize JSON text token-by-token parsing.
template<unsigned parseFlags, typename InputStream, typename Handler>
bool IterativeParseNext (InputStream &is, Handler &handler)
 Parse one token from JSON text.
RAPIDJSON_FORCEINLINE bool IterativeParseComplete () const
 Check if token-by-token parsing JSON text is complete.
bool HasParseError () const
 Whether a parse error has occurred in the last parsing.
ParseErrorCode GetParseErrorCode () const
 Get the ParseErrorCode of last parsing.
size_t GetErrorOffset () const
 Get the position of last parsing error in input, 0 otherwise.

Protected Member Functions

void SetParseError (ParseErrorCode code, size_t offset)

Detailed Description

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
class GenericReader< SourceEncoding, TargetEncoding, StackAllocator >

SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.

GenericReader parses JSON text from a stream, and send events synchronously to an object implementing Handler concept.

It needs to allocate a stack for storing a single decoded string during non-destructive parsing.

For in-situ parsing, the decoded string is directly written to the source text string, no temporary buffer is required.

A GenericReader object can be reused for parsing multiple JSON text.

Template Parameters
SourceEncodingEncoding of the input stream.
TargetEncodingEncoding of the parse output.
StackAllocatorAllocator type for stack.

Definition at line 537 of file reader.h.

Member Typedef Documentation

◆ Ch

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
typedef SourceEncoding::Ch GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Ch

SourceEncoding character type.

Definition at line 539 of file reader.h.

Constructor & Destructor Documentation

◆ GenericReader()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::GenericReader ( StackAllocator * stackAllocator = 0,
size_t stackCapacity = kDefaultStackCapacity )
inline

Constructor.

Parameters
stackAllocatorOptional allocator for allocating stack memory. (Only use for non-destructive parsing)
stackCapacitystack capacity in bytes for storing a single decoded string. (Only use for non-destructive parsing)

Definition at line 545 of file reader.h.

545 :
546 stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState) {}
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition reader.h:537

Member Function Documentation

◆ GetErrorOffset()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
size_t GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::GetErrorOffset ( ) const
inline

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

Definition at line 686 of file reader.h.

686{ return parseResult_.Offset(); }
Here is the caller graph for this function:

◆ GetParseErrorCode()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
ParseErrorCode GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::GetParseErrorCode ( ) const
inline

Get the ParseErrorCode of last parsing.

Definition at line 683 of file reader.h.

683{ return parseResult_.Code(); }
Here is the caller graph for this function:

◆ HasParseError()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
bool GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::HasParseError ( ) const
inline

Whether a parse error has occurred in the last parsing.

Definition at line 680 of file reader.h.

680{ return parseResult_.IsError(); }
Here is the caller graph for this function:

◆ IterativeParseComplete()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
RAPIDJSON_FORCEINLINE bool GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::IterativeParseComplete ( ) const
inline

Check if token-by-token parsing JSON text is complete.

Returns
Whether the JSON has been fully decoded.

Definition at line 675 of file reader.h.

675 {
676 return IsIterativeParsingCompleteState(state_);
677 }
Here is the caller graph for this function:

◆ IterativeParseInit()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::IterativeParseInit ( )
inline

Initialize JSON text token-by-token parsing.

Definition at line 605 of file reader.h.

605 {
606 parseResult_.Clear();
607 state_ = IterativeParsingStartState;
608 }
Here is the caller graph for this function:

◆ IterativeParseNext()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream, typename Handler>
bool GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::IterativeParseNext ( InputStream & is,
Handler & handler )
inline

Parse one token from JSON text.

Template Parameters
InputStreamType of input stream, implementing Stream concept
HandlerType of handler, implementing Handler concept.
Parameters
isInput stream to be parsed.
handlerThe handler to receive events.
Returns
Whether the parsing is successful.

Definition at line 618 of file reader.h.

618 {
619 while (RAPIDJSON_LIKELY(is.Peek() != '\0')) {
620 SkipWhitespaceAndComments<parseFlags>(is);
621
622 Token t = Tokenize(is.Peek());
623 IterativeParsingState n = Predict(state_, t);
624 IterativeParsingState d = Transit<parseFlags>(state_, t, n, is, handler);
625
626 // If we've finished or hit an error...
627 if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) {
628 // Report errors.
629 if (d == IterativeParsingErrorState) {
630 HandleError(state_, is);
631 return false;
632 }
633
634 // Transition to the finish state.
635 RAPIDJSON_ASSERT(d == IterativeParsingFinishState);
636 state_ = d;
637
638 // If StopWhenDone is not set...
640 // ... and extra non-whitespace data is found...
641 SkipWhitespaceAndComments<parseFlags>(is);
642 if (is.Peek() != '\0') {
643 // ... this is considered an error.
644 HandleError(state_, is);
645 return false;
646 }
647 }
648
649 // Success! We are done!
650 return true;
651 }
652
653 // Transition to the new state.
654 state_ = d;
655
656 // If we parsed anything other than a delimiter, we invoked the handler, so we can return true now.
657 if (!IsIterativeParsingDelimiterState(n))
658 return true;
659 }
660
661 // We reached the end of file.
662 stack_.Clear();
663
664 if (state_ != IterativeParsingFinishState) {
665 HandleError(state_, is);
666 return false;
667 }
668
669 return true;
670 }
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition rapidjson.h:468
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:481
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:411
Here is the caller graph for this function:

◆ Parse() [1/2]

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<typename InputStream, typename Handler>
ParseResult GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Parse ( InputStream & is,
Handler & handler )
inline

Parse JSON text (with kParseDefaultFlags).

Template Parameters
InputStreamType of input stream, implementing Stream concept
HandlerType of handler, implementing Handler concept.
Parameters
isInput stream to be parsed.
handlerThe handler to receive events.
Returns
Whether the parsing is successful.

Definition at line 598 of file reader.h.

598 {
600 }
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition reader.h:557

◆ Parse() [2/2]

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream, typename Handler>
ParseResult GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Parse ( InputStream & is,
Handler & handler )
inline

Parse JSON text.

Template Parameters
parseFlagsCombination of ParseFlag.
InputStreamType of input stream, implementing Stream concept.
HandlerType of handler, implementing Handler concept.
Parameters
isInput stream to be parsed.
handlerThe handler to receive events.
Returns
Whether the parsing is successful.

Definition at line 557 of file reader.h.

557 {
559 return IterativeParse<parseFlags>(is, handler);
560
561 parseResult_.Clear();
562
563 ClearStackOnExit scope(*this);
564
565 SkipWhitespaceAndComments<parseFlags>(is);
567
568 if (RAPIDJSON_UNLIKELY(is.Peek() == '\0')) {
571 }
572 else {
573 ParseValue<parseFlags>(is, handler);
575
577 SkipWhitespaceAndComments<parseFlags>(is);
579
580 if (RAPIDJSON_UNLIKELY(is.Peek() != '\0')) {
583 }
584 }
585 }
586
587 return parseResult_;
588 }
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
Macro to indicate a parse error.
Definition reader.h:99

◆ SetParseError()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::SetParseError ( ParseErrorCode code,
size_t offset )
inlineprotected

Definition at line 689 of file reader.h.

689{ parseResult_.Set(code, offset); }

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/include/rapidjson/fwd.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/include/rapidjson/reader.h