RetroArch
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GenericReader< SourceEncoding, TargetEncoding, StackAllocator > Class Template Reference

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

#include <fwd.h>

Collaboration diagram for GenericReader< SourceEncoding, TargetEncoding, StackAllocator >:
[legend]

Classes

struct  ClearStackOnExit
 
class  NumberStream
 
class  NumberStream< InputStream, false, false >
 
class  NumberStream< InputStream, true, false >
 
class  NumberStream< InputStream, true, true >
 
class  StackStream
 

Public Types

typedef SourceEncoding::Ch Ch
 SourceEncoding character type. More...
 

Public Member Functions

 GenericReader (StackAllocator *stackAllocator=0, size_t stackCapacity=kDefaultStackCapacity)
 Constructor. More...
 
template<unsigned parseFlags, typename InputStream , typename Handler >
ParseResult Parse (InputStream &is, Handler &handler)
 Parse JSON text. More...
 
template<typename InputStream , typename Handler >
ParseResult Parse (InputStream &is, Handler &handler)
 Parse JSON text (with kParseDefaultFlags) More...
 
bool HasParseError () const
 Whether a parse error has occured in the last parsing. More...
 
ParseErrorCode GetParseErrorCode () const
 Get the ParseErrorCode of last parsing. More...
 
size_t GetErrorOffset () const
 Get the position of last parsing error in input, 0 otherwise. More...
 

Protected Member Functions

void SetParseError (ParseErrorCode code, size_t offset)
 

Private Types

enum  IterativeParsingState {
  IterativeParsingStartState = 0, IterativeParsingFinishState, IterativeParsingErrorState, IterativeParsingObjectInitialState,
  IterativeParsingMemberKeyState, IterativeParsingKeyValueDelimiterState, IterativeParsingMemberValueState, IterativeParsingMemberDelimiterState,
  IterativeParsingObjectFinishState, IterativeParsingArrayInitialState, IterativeParsingElementState, IterativeParsingElementDelimiterState,
  IterativeParsingArrayFinishState, IterativeParsingValueState
}
 
enum  { cIterativeParsingStateCount = IterativeParsingValueState + 1 }
 
enum  Token {
  LeftBracketToken = 0, RightBracketToken, LeftCurlyBracketToken, RightCurlyBracketToken,
  CommaToken, ColonToken, StringToken, FalseToken,
  TrueToken, NullToken, NumberToken, kTokenCount
}
 

Private Member Functions

 GenericReader (const GenericReader &)
 
GenericReaderoperator= (const GenericReader &)
 
void ClearStack ()
 
template<unsigned parseFlags, typename InputStream >
void SkipWhitespaceAndComments (InputStream &is)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseObject (InputStream &is, Handler &handler)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseArray (InputStream &is, Handler &handler)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseNull (InputStream &is, Handler &handler)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseTrue (InputStream &is, Handler &handler)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseFalse (InputStream &is, Handler &handler)
 
template<typename InputStream >
unsigned ParseHex4 (InputStream &is, size_t escapeOffset)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseString (InputStream &is, Handler &handler, bool isKey=false)
 
template<unsigned parseFlags, typename SEncoding , typename TEncoding , typename InputStream , typename OutputStream >
RAPIDJSON_FORCEINLINE void ParseStringToStream (InputStream &is, OutputStream &os)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseNumber (InputStream &is, Handler &handler)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
void ParseValue (InputStream &is, Handler &handler)
 
RAPIDJSON_FORCEINLINE Token Tokenize (Ch c)
 
RAPIDJSON_FORCEINLINE IterativeParsingState Predict (IterativeParsingState state, Token token)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
RAPIDJSON_FORCEINLINE IterativeParsingState Transit (IterativeParsingState src, Token token, IterativeParsingState dst, InputStream &is, Handler &handler)
 
template<typename InputStream >
void HandleError (IterativeParsingState src, InputStream &is)
 
template<unsigned parseFlags, typename InputStream , typename Handler >
ParseResult IterativeParse (InputStream &is, Handler &handler)
 

Static Private Member Functions

template<typename InputStream >
static RAPIDJSON_FORCEINLINE bool Consume (InputStream &is, typename InputStream::Ch expect)
 
template<typename InputStream , typename OutputStream >
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString (InputStream &, OutputStream &)
 

Private Attributes

internal::Stack< StackAllocatorstack_
 A stack for storing decoded string temporarily during non-destructive parsing. More...
 
ParseResult parseResult_
 

Static Private Attributes

static const size_t kDefaultStackCapacity = 256
 Default stack capacity in bytes for storing a single decoded string. More...
 

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.

Member Typedef Documentation

◆ Ch

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

SourceEncoding character type.

Member Enumeration Documentation

◆ anonymous enum

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
anonymous enum
private
Enumerator
cIterativeParsingStateCount 

◆ IterativeParsingState

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
enum GenericReader::IterativeParsingState
private
Enumerator
IterativeParsingStartState 
IterativeParsingFinishState 
IterativeParsingErrorState 
IterativeParsingObjectInitialState 
IterativeParsingMemberKeyState 
IterativeParsingKeyValueDelimiterState 
IterativeParsingMemberValueState 
IterativeParsingMemberDelimiterState 
IterativeParsingObjectFinishState 
IterativeParsingArrayInitialState 
IterativeParsingElementState 
IterativeParsingElementDelimiterState 
IterativeParsingArrayFinishState 
IterativeParsingValueState 

◆ Token

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
enum GenericReader::Token
private
Enumerator
LeftBracketToken 
RightBracketToken 
LeftCurlyBracketToken 
RightCurlyBracketToken 
CommaToken 
ColonToken 
StringToken 
FalseToken 
TrueToken 
NullToken 
NumberToken 
kTokenCount 

Constructor & Destructor Documentation

◆ GenericReader() [1/2]

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)

◆ GenericReader() [2/2]

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::GenericReader ( const GenericReader< SourceEncoding, TargetEncoding, StackAllocator > &  )
private

Member Function Documentation

◆ ClearStack()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ClearStack ( )
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Consume()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<typename InputStream >
static RAPIDJSON_FORCEINLINE bool GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Consume ( InputStream &  is,
typename InputStream::Ch  expect 
)
inlinestaticprivate
Here is the caller graph for this function:

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

Here is the call 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.

Here is the call graph for this function:

◆ HandleError()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<typename InputStream >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::HandleError ( IterativeParsingState  src,
InputStream &  is 
)
inlineprivate
Here is the call graph for this function:
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 occured in the last parsing.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IterativeParse()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
ParseResult GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::IterativeParse ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ operator=()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
GenericReader& GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::operator= ( const GenericReader< SourceEncoding, TargetEncoding, StackAllocator > &  )
private

◆ Parse() [1/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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Parse() [2/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.

◆ ParseArray()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseArray ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ ParseFalse()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseFalse ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ ParseHex4()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<typename InputStream >
unsigned GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseHex4 ( InputStream &  is,
size_t  escapeOffset 
)
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseNull()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseNull ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ ParseNumber()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseNumber ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ ParseObject()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseObject ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ ParseString()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseString ( InputStream &  is,
Handler &  handler,
bool  isKey = false 
)
inlineprivate
Here is the call graph for this function:

◆ ParseStringToStream()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename SEncoding , typename TEncoding , typename InputStream , typename OutputStream >
RAPIDJSON_FORCEINLINE void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseStringToStream ( InputStream &  is,
OutputStream &  os 
)
inlineprivate
Here is the call graph for this function:

◆ ParseTrue()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseTrue ( InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

◆ ParseValue()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ParseValue ( InputStream &  is,
Handler &  handler 
)
inlineprivate

◆ Predict()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
RAPIDJSON_FORCEINLINE IterativeParsingState GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Predict ( IterativeParsingState  state,
Token  token 
)
inlineprivate
Here is the caller graph for this function:

◆ ScanCopyUnescapedString()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<typename InputStream , typename OutputStream >
static RAPIDJSON_FORCEINLINE void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::ScanCopyUnescapedString ( InputStream &  ,
OutputStream &   
)
inlinestaticprivate
Here is the caller graph for this function:

◆ SetParseError()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::SetParseError ( ParseErrorCode  code,
size_t  offset 
)
inlineprotected
Here is the call graph for this function:

◆ SkipWhitespaceAndComments()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream >
void GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::SkipWhitespaceAndComments ( InputStream &  is)
inlineprivate
Here is the call graph for this function:

◆ Tokenize()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
RAPIDJSON_FORCEINLINE Token GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Tokenize ( Ch  c)
inlineprivate
Here is the caller graph for this function:

◆ Transit()

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
template<unsigned parseFlags, typename InputStream , typename Handler >
RAPIDJSON_FORCEINLINE IterativeParsingState GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::Transit ( IterativeParsingState  src,
Token  token,
IterativeParsingState  dst,
InputStream &  is,
Handler &  handler 
)
inlineprivate
Here is the call graph for this function:

Member Data Documentation

◆ kDefaultStackCapacity

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
const size_t GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::kDefaultStackCapacity = 256
staticprivate

Default stack capacity in bytes for storing a single decoded string.

◆ parseResult_

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
ParseResult GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::parseResult_
private

◆ stack_

template<typename SourceEncoding, typename TargetEncoding, typename StackAllocator = CrtAllocator>
internal::Stack<StackAllocator> GenericReader< SourceEncoding, TargetEncoding, StackAllocator >::stack_
private

A stack for storing decoded string temporarily during non-destructive parsing.


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