![]() |
Plasma Engine
2.0
|
A low level JSON parser that can incrementally parse the structure of a JSON document. More...
#include <JSONParser.h>
Public Member Functions | |
plJSONParser () | |
Constructor. | |
void | SetLogInterface (plLogInterface *pLog) |
Allows to specify an plLogInterface through which errors and warnings are reported. | |
Protected Member Functions | |
void | SetInputStream (plStreamReader &stream, plUInt32 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 (plStringView sMessage, bool bFatal) |
Outputs that a parsing error was detected (via OnParsingError) and stops further parsing, if bFatal is set to true. | |
Protected Attributes | |
plLogInterface * | m_pLogInterface = nullptr |
Private Member Functions | |
virtual bool | OnVariable (plStringView 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 (plStringView 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 (plStringView sMessage, bool bFatal, plUInt32 uiLine, plUInt32 uiColumn) |
Called when something unexpected is encountered in the JSON document. | |
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.
|
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.
|
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 plJSONReader.
|
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 plJSONReader.
|
privatepure virtual |
Called when the end of an array is encountered.
Implemented in plJSONReader.
|
privatepure virtual |
Called when the end of an object is encountered.
Implemented in plJSONReader.
|
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 plJSONReader.
|
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 plJSONReader.
|
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 plJSONReader.
|
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 plJSONReader.
|
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 plJSONReader.
|
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 plJSONReader.