Simpleson
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
json::reader Class Reference

Value reader. More...

#include <json.h>

Inheritance diagram for json::reader:
json::kvp_reader

Public Types

enum  push_result { ACCEPTED , REJECTED , WHITESPACE }
 

Public Member Functions

 reader ()
 Reader constructor.
 
virtual void clear ()
 Resets the reader. More...
 
virtual push_result push (const char next)
 
virtual jtype::jtype type () const
 Checks the value. More...
 
virtual bool is_valid () const
 Checks if the stored value is valid. More...
 
virtual std::string readout () const
 Returns the stored value. More...
 
virtual ~reader ()
 Destructor.
 

Protected Types

enum  string_reader_enum {
  STRING_EMPTY = 0 , STRING_OPENING_QUOTE , STRING_OPEN , STRING_ESCAPED ,
  STRING_CODE_POINT_START , STRING_CODE_POINT_1 , STRING_CODE_POINT_2 , STRING_CODE_POINT_3 ,
  STRING_CLOSED
}
 Enumeration of the state machine for strings. More...
 
enum  number_reader_enum {
  NUMBER_EMPTY = 0 , NUMBER_OPEN_NEGATIVE , NUMBER_ZERO , NUMBER_INTEGER_DIGITS ,
  NUMBER_DECIMAL , NUMBER_FRACTION_DIGITS , NUMBER_EXPONENT , NUMBER_EXPONENT_SIGN ,
  NUMBER_EXPONENT_DIGITS
}
 
enum  array_reader_enum {
  ARRAY_EMPTY = 0 , ARRAY_OPEN_BRACKET , ARRAY_READING_VALUE , ARRAY_AWAITING_NEXT_LINE ,
  ARRAY_CLOSED
}
 
enum  object_reader_enum {
  OBJECT_EMPTY = 0 , OBJECT_OPEN_BRACE , OBJECT_READING_ENTRY , OBJECT_AWAITING_NEXT_LINE ,
  OBJECT_CLOSED
}
 

Protected Member Functions

push_result push_string (const char next)
 Pushes a character to a string value.
 
push_result push_array (const char next)
 Pushes a character to an array value.
 
push_result push_object (const char next)
 Pushes a character to an object value.
 
push_result push_number (const char next)
 Pushes a character to a number value.
 
push_result push_boolean (const char next)
 Pushes a character to a boolean value.
 
push_result push_null (const char next)
 Pushes a character to a null value.
 
template<typename T >
get_state () const
 Returns the stored state. More...
 
template<typename T >
void set_state (const T state)
 Stores the reader state. More...
 

Protected Attributes

readersub_reader
 The subreader used during reading. More...
 

Detailed Description

Value reader.

Member Enumeration Documentation

◆ array_reader_enum

Enumerator
ARRAY_EMPTY 

No values have been read.

ARRAY_OPEN_BRACKET 

The array has been opened.

ARRAY_READING_VALUE 

An array value is being read.

ARRAY_AWAITING_NEXT_LINE 

An array value has been read and a comma was encountered. Expecting new line.

ARRAY_CLOSED 

The array has been fully read. Reading should stop.

◆ number_reader_enum

Enumerator
NUMBER_EMPTY 

No values have been read.

NUMBER_OPEN_NEGATIVE 

A negative value has been read as the first character.

NUMBER_ZERO 

A zero has been read as an integer value.

NUMBER_INTEGER_DIGITS 

Integer digits were the last values read.

NUMBER_DECIMAL 

A decimal point was the last value read.

NUMBER_FRACTION_DIGITS 

A decimal point and subsequent digits were the last values read.

NUMBER_EXPONENT 

An exponent indicator has been read.

NUMBER_EXPONENT_SIGN 

An exponent sign has been read.

NUMBER_EXPONENT_DIGITS 

An exponent indicator and subsequent digits were the last values read.

◆ object_reader_enum

Enumerator
OBJECT_EMPTY 

No values have been read.

OBJECT_OPEN_BRACE 

The object has been opened.

OBJECT_READING_ENTRY 

An object key value pair is being read.

OBJECT_AWAITING_NEXT_LINE 

An object key value pair has been read and a comma was encountered. Expecting new line.

OBJECT_CLOSED 

The object has been fully read. Reading should stop.

◆ push_result

Enumerator
ACCEPTED 

The character was valid. Reading should continue.

REJECTED 

The character was not valid. Reading should stop.

WHITESPACE 

The character was whitespace. Reading should continue but the whtiespace was not stored.

◆ string_reader_enum

Enumeration of the state machine for strings.

Enumerator
STRING_EMPTY 

No values have been read.

STRING_OPENING_QUOTE 

The opening quote has been read. Equivalant to STRING_OPEN, but used for debugging the state.

STRING_OPEN 

The opening quote has been read and the last character was not an escape character.

STRING_ESCAPED 

The last character was an reverse solidus (), indicating the next character should be a control character.

STRING_CODE_POINT_START 

An encoded unicode character is encountered. Expecting four following hex digits.

STRING_CODE_POINT_1 

An encoded unicode character is encountered. Expecting three following hex digits (one has already been read).

STRING_CODE_POINT_2 

An encoded unicode character is encountered. Expecting two following hex digits (two have already been read).

STRING_CODE_POINT_3 

An encoded unicode character is encountered. Expecting one following hex digit (three has already been read).

STRING_CLOSED 

The closing quote has been read. Reading should cease.

Member Function Documentation

◆ clear()

void json::reader::clear ( )
virtual

Resets the reader.

Reimplemented in json::kvp_reader.

◆ get_state()

template<typename T >
T json::reader::get_state ( ) const
inlineprotected

Returns the stored state.

This template is intended for use with string_reader_enum, number_reader_enum, array_reader_enum, and object_reader_enum

◆ is_valid()

bool json::reader::is_valid ( ) const
virtual

Checks if the stored value is valid.

Returns
true if the stored value is valid, false otherwise

Reimplemented in json::kvp_reader.

◆ push()

json::reader::push_result json::reader::push ( const char  next)
virtual

\ brief Pushes a value to the back of the reader

Parameters
nextthe value to be pushed
Returns
ACCEPTED if the value was added to the reader, WHITESPACE if the input was whitespace that was not stored, and REJECTED is the input was invalid for the value type

Reimplemented in json::kvp_reader.

◆ readout()

virtual std::string json::reader::readout ( ) const
inlinevirtual

Returns the stored value.

Returns
A string containing the stored value
Warning
This method will return the value regardless of the state of the value, valid or not

Reimplemented in json::kvp_reader.

◆ set_state()

template<typename T >
void json::reader::set_state ( const T  state)
inlineprotected

Stores the reader state.

This template is intended for use with string_reader_enum, number_reader_enum, array_reader_enum, and object_reader_enum

◆ type()

virtual jtype::jtype json::reader::type ( ) const
inlinevirtual

Checks the value.

Returns
The type of value stored in the reader, or not_valid if no value is stored

Member Data Documentation

◆ sub_reader

reader* json::reader::sub_reader
protected

The subreader used during reading.

Arrays and objects will use a sub reader to store underlying values


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