Plasma Engine  2.0
Loading...
Searching...
No Matches
plJSONReader Class Reference

This JSON reader will read an entire JSON document into a hierarchical structure of plVariants. More...

#include <JSONReader.h>

Inheritance diagram for plJSONReader:

Classes

struct  Element
 

Public Types

enum class  ElementType : plInt8 { None , Dictionary , Array }
 

Public Member Functions

plResult Parse (plStreamReader &ref_input, plUInt32 uiFirstLineOffset=0)
 Reads the entire stream and creates the internal data structure that represents the JSON document. Returns PL_FAILURE if any parsing error occurred.
 
const plVariantDictionaryGetTopLevelObject () const
 Returns the top-level object of the JSON document.
 
const plVariantArrayGetTopLevelArray () const
 Returns the top-level array of the JSON document.
 
ElementType GetTopLevelElementType () const
 Returns whether the top level element is an array or an object.
 
- Public Member Functions inherited from plJSONParser
 plJSONParser ()
 Constructor.
 
void SetLogInterface (plLogInterface *pLog)
 Allows to specify an plLogInterface through which errors and warnings are reported.
 

Protected Attributes

plHybridArray< Element, 32 > m_Stack
 
bool m_bParsingError = false
 
plString m_sLastName
 
- Protected Attributes inherited from plJSONParser
plLogInterfacem_pLogInterface = nullptr
 

Private Member Functions

virtual bool OnVariable (plStringView sVarName) override
 This function can be overridden to skip certain variables, however the overriding function must still call this.
 
virtual void OnReadValue (plStringView sValue) override
 [internal] Do not override further.
 
virtual void OnReadValue (double fValue) override
 [internal] Do not override further.
 
virtual void OnReadValue (bool bValue) override
 [internal] Do not override further.
 
virtual void OnReadValueNULL () override
 [internal] Do not override further.
 
virtual void OnBeginObject () override
 [internal] Do not override further.
 
virtual void OnEndObject () override
 [internal] Do not override further.
 
virtual void OnBeginArray () override
 [internal] Do not override further.
 
virtual void OnEndArray () override
 [internal] Do not override further.
 
virtual void OnParsingError (plStringView sMessage, bool bFatal, plUInt32 uiLine, plUInt32 uiColumn) override
 Called when something unexpected is encountered in the JSON document.
 

Additional Inherited Members

- Protected Member Functions inherited from plJSONParser
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.
 

Detailed Description

This JSON reader will read an entire JSON document into a hierarchical structure of plVariants.

The reader will parse the entire document and create a data structure of plVariants, which can then be traversed easily. Note that this class is much less efficient at reading large JSON documents, as it will dynamically allocate and copy objects around quite a bit. For small to medium sized documents that might be good enough, for large files one should prefer to write a dedicated class derived from plJSONParser.

Member Enumeration Documentation

◆ ElementType

enum class plJSONReader::ElementType : plInt8
strong
Enumerator
None 

The JSON document is entirely empty (not even containing an empty object or array)

Dictionary 

The top level element in the JSON document is an object.

Array 

The top level element in the JSON document is an array.

Member Function Documentation

◆ OnBeginArray()

void plJSONReader::OnBeginArray ( )
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnBeginObject()

void plJSONReader::OnBeginObject ( )
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnEndArray()

void plJSONReader::OnEndArray ( )
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnEndObject()

void plJSONReader::OnEndObject ( )
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnParsingError()

void plJSONReader::OnParsingError ( plStringView sMessage,
bool bFatal,
plUInt32 uiLine,
plUInt32 uiColumn )
overrideprivatevirtual

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 from plJSONParser.

◆ OnReadValue() [1/3]

void plJSONReader::OnReadValue ( bool bValue)
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnReadValue() [2/3]

void plJSONReader::OnReadValue ( double fValue)
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnReadValue() [3/3]

void plJSONReader::OnReadValue ( plStringView sValue)
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnReadValueNULL()

void plJSONReader::OnReadValueNULL ( )
overrideprivatevirtual

[internal] Do not override further.

Implements plJSONParser.

◆ OnVariable()

bool plJSONReader::OnVariable ( plStringView sVarName)
overrideprivatevirtual

This function can be overridden to skip certain variables, however the overriding function must still call this.

Implements plJSONParser.


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