Open Lighting Architecture  Latest Git
Public Member Functions | Static Public Member Functions | List of all members
ola::web::JsonParser Class Reference

Detailed Description

A JsonParserInterface implementation that builds a tree of JsonValues.

This is the most common implementation of the JsonParserInterface but it's also the least efficient since it loads the entire document into memory.

Inheritance diagram for ola::web::JsonParser:
Inheritance graph
[legend]
Collaboration diagram for ola::web::JsonParser:
Collaboration graph
[legend]

Public Member Functions

void Begin ()
 Called when parsing begins.
 
void End ()
 Called when parsing completes.
 
void String (const std::string &value)
 Called when a string is encountered. More...
 
void Number (uint32_t value)
 Called when a uint32_t is encountered.
 
void Number (int32_t value)
 Called when a int32_t is encountered.
 
void Number (uint64_t value)
 Called when a uint64_t is encountered.
 
void Number (int64_t value)
 Called when a int64_t is encountered.
 
void Number (const JsonDouble::DoubleRepresentation &rep)
 Called when a double value is encountered. More...
 
void Number (double value)
 Called when a double value is encountered.
 
void Bool (bool value)
 Called when a bool is encountered.
 
void Null ()
 Called when a null token is encountered.
 
void OpenArray ()
 Called when an array starts.
 
void CloseArray ()
 Called when an array completes.
 
void OpenObject ()
 Called when an object starts.
 
void ObjectKey (const std::string &key)
 Called when a new key is encountered. More...
 
void CloseObject ()
 Called when an object completes.
 
void SetError (const std::string &error)
 Can be called at any time to indicate an error with the input data.
 
std::string GetError () const
 Check if parsing was successful.
 
JsonValueGetRoot ()
 Get the root of the parse tree, or NULL if parsing failed. More...
 
JsonValueClaimRoot ()
 Get the root of the parse tree, or NULL if parsing failed. More...
 

Static Public Member Functions

static JsonValueParse (const std::string &input, std::string *error)
 Parse text and return a JsonValue representation.
 

Member Function Documentation

◆ ClaimRoot()

JsonValue * ola::web::JsonParser::ClaimRoot ( )

Get the root of the parse tree, or NULL if parsing failed.

Returns
the root JsonValue. Ownership is transferred to the caller.

◆ GetRoot()

JsonValue * ola::web::JsonParser::GetRoot ( )

Get the root of the parse tree, or NULL if parsing failed.

Returns
the root JsonValue. Ownership is not transferred.

◆ Number()

void ola::web::JsonParser::Number ( const JsonDouble::DoubleRepresentation rep)
virtual

Called when a double value is encountered.

MinGW struggles with long doubles http://mingw.5.n7.nabble.com/Strange-behaviour-of-gcc-4-8-1-with-long-double-td32949.html To avoid this, and to keep as many significant bits as possible we keep the components of a double separate. See JsonDouble for details.

Implements ola::web::JsonParserInterface.

◆ ObjectKey()

void ola::web::JsonParser::ObjectKey ( const std::string &  key)
virtual

Called when a new key is encountered.

This may be called multiple times for the same object. The standard doesn't specify how to handle duplicate keys, so I generally use the last one.

Implements ola::web::JsonParserInterface.

◆ String()

void ola::web::JsonParser::String ( const std::string &  value)
virtual

Called when a string is encountered.

This is not called for object keys, see ObjectKey() below.

Implements ola::web::JsonParserInterface.


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