XII Release 0.1.0
Loading...
Searching...
No Matches
xiiJSONParser Class Referenceabstract

A low level JSON parser that can incrementally parse the structure of a JSON document. More...

#include <JSONParser.h>

Inheritance diagram for xiiJSONParser:
[legend]

Public Member Functions

 xiiJSONParser ()
 Constructor.
 
void SetLogInterface (xiiLogInterface *pLog)
 Allows to specify a xiiLogInterface through which errors and warnings are reported.
 

Protected Member Functions

void SetInputStream (xiiStreamReader &stream, xiiUInt32 uiFirstLineOffset=0)
 Resets the parser to the start state and configures it to read from the given stream.
 
bool ContinueParsing ()
 Does one parsing step.
 
void ParseAll ()
 Calls ContinueParsing() in a loop until that returns false.
 
void SkipObject ()
 Skips the rest of the currently open object. No OnEndArray() and OnEndObject() calls will be done for this object, cleanup must be done manually.
 
void SkipArray ()
 Skips the rest of the currently open array. No OnEndArray() and OnEndObject() calls will be done for this object, cleanup must be done manually.
 
void ParsingError (xiiStringView sMessage, bool bFatal)
 Outputs that a parsing error was detected (via OnParsingError) and stops further parsing, if bFatal is set to true.
 

Protected Attributes

xiiLogInterfacem_pLogInterface = nullptr
 

Private Member Functions

virtual bool OnVariable (xiiStringView sVarName)=0
 Called whenever a new variable is encountered. The variable name is passed along. At this point the type of the variable (simple, array, object) is not yet determined.
 
virtual void OnReadValue (xiiStringView sValue)=0
 Called whenever a new value is read.
 
virtual void OnReadValue (double fValue)=0
 Called whenever a new value is read.
 
virtual void OnReadValue (bool bValue)=0
 Called whenever a new value is read.
 
virtual void OnReadValueNULL ()=0
 Called whenever a new value is read.
 
virtual void OnBeginObject ()=0
 Called when a new object is encountered.
 
virtual void OnEndObject ()=0
 Called when the end of an object is encountered.
 
virtual void OnBeginArray ()=0
 Called when a new array is encountered.
 
virtual void OnEndArray ()=0
 Called when the end of an array is encountered.
 
virtual void OnParsingError (xiiStringView sMessage, bool bFatal, xiiUInt32 uiLine, xiiUInt32 uiColumn)
 Called when something unexpected is encountered in the JSON document.
 

Detailed Description

A low level JSON parser that can incrementally parse the structure of a JSON document.

The document structure is returned through virtual functions that need to be overridden.

Member Function Documentation

◆ ContinueParsing()

bool xiiJSONParser::ContinueParsing ( )
protected

Does one parsing step.

While this function returns true, the document has not been parsed completely. This function may call any of the OnSomething functions through which the structure of the document is obtained. This function calls at most one such callback, but there is no guarantee that it calls any at all, it might just advance its internal state.

◆ OnBeginArray()

virtual void xiiJSONParser::OnBeginArray ( )
privatepure virtual

Called when a new array is encountered.

Directly following a call to OnVariable(), this means the variable is of type 'array' (and has a name). In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in xiiJSONReader.

◆ OnBeginObject()

virtual void xiiJSONParser::OnBeginObject ( )
privatepure virtual

Called when a new object is encountered.

Directly following a call to OnVariable(), this means the variable is of type 'object' (and has a name). In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in xiiJSONReader.

◆ OnEndArray()

virtual void xiiJSONParser::OnEndArray ( )
privatepure virtual

Called when the end of an array is encountered.

Implemented in xiiJSONReader.

◆ OnEndObject()

virtual void xiiJSONParser::OnEndObject ( )
privatepure virtual

Called when the end of an object is encountered.

Implemented in xiiJSONReader.

◆ OnParsingError()

virtual void xiiJSONParser::OnParsingError ( xiiStringView sMessage,
bool bFatal,
xiiUInt32 uiLine,
xiiUInt32 uiColumn )
inlineprivatevirtual

Called when something unexpected is encountered in the JSON document.

The error message describes what was expected and what was encountered. If bFatal is true, the error has left the parser in an unrecoverable state and thus it not continue parsing. In that case client code will need to clean up it's open state, as no further OnEndObject() / OnEndArray() will be called. If bFatal is false, the document does not contain valid JSON, but the parser is able to continue still.

Reimplemented in xiiJSONReader.

◆ OnReadValue() [1/3]

virtual void xiiJSONParser::OnReadValue ( bool bValue)
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in xiiJSONReader.

◆ OnReadValue() [2/3]

virtual void xiiJSONParser::OnReadValue ( double fValue)
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in xiiJSONReader.

◆ OnReadValue() [3/3]

virtual void xiiJSONParser::OnReadValue ( xiiStringView sValue)
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in xiiJSONReader.

◆ OnReadValueNULL()

virtual void xiiJSONParser::OnReadValueNULL ( )
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in xiiJSONReader.

◆ OnVariable()

virtual bool xiiJSONParser::OnVariable ( xiiStringView sVarName)
privatepure virtual

Called whenever a new variable is encountered. The variable name is passed along. At this point the type of the variable (simple, array, object) is not yet determined.

The entire variable (independent of whether it is a simple value, an array or an object) can be skipped by returning false.

Implemented in xiiJSONReader.


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