Base class for all json types. More...

#include <json_type.hpp>

Inherited by oos::json_array, oos::json_bool, oos::json_null, oos::json_number, oos::json_object, and oos::json_string.

Public Member Functions

virtual bool parse (std::istream &in)=0
 
virtual void print (std::ostream &out) const =0
 
virtual json_valueoperator[] (const std::string &key)
 
virtual json_valueoperator[] (size_t index)
 
virtual const json_valueoperator[] (size_t index) const
 
virtual void push_back (const json_value &x)
 
virtual size_t size () const
 
std::string type () const
 

Protected Member Functions

 json_type (const std::string &name)
 
void type (const std::string &type)
 

Static Protected Attributes

static json_parser parser
 

Friends

OOS_API std::ostream & operator<< (std::ostream &str, const json_type &value)
 
OOS_API std::istream & operator>> (std::istream &str, json_object &obj)
 
OOS_API std::istream & operator>> (std::istream &str, json_array &obj)
 

Detailed Description

Base class for all json types.

This is the base class for all json types

  • array
  • object
  • string
  • number
  • boolean
  • null

It provides all accessors to get the values for each concrete class.

Constructor & Destructor Documentation

oos::json_type::json_type ( const std::string &  name)
explicitprotected

Creates a json_type of a certain type

Parameters
nameType of the json_type

Member Function Documentation

virtual json_value& oos::json_type::operator[] ( const std::string &  key)
virtual

Returns a json_value with the given key. If the concrete type doesn't support this method an exception is thrown.

Parameters
keyThe key of the json_value.
Returns
the corresponding json_value.

Reimplemented in oos::json_object.

virtual json_value& oos::json_type::operator[] ( size_t  index)
virtual

Returns a json_value at the given index. If the concrete type doesn't support this method an exception is thrown.

Parameters
indexThe index of the json_value.
Returns
the corresponding json_value.

Reimplemented in oos::json_array.

virtual const json_value& oos::json_type::operator[] ( size_t  index) const
virtual

Returns a json_value at the given index. If the concrete type doesn't support this method an exception is thrown.

Parameters
indexThe index of the json_value.
Returns
the corresponding json_value.

Reimplemented in oos::json_array.

virtual bool oos::json_type::parse ( std::istream &  in)
pure virtual

Parses in json input stream

Parameters
inThe json input stream
Returns
True if stream was parsed correctly

Implemented in oos::json_string, oos::json_number, oos::json_array, oos::json_object, oos::json_bool, and oos::json_null.

virtual void oos::json_type::print ( std::ostream &  out) const
pure virtual

Prints the json type (tree) to a output stream.

Parameters
outThe stream to write on.

Implemented in oos::json_string, oos::json_number, oos::json_array, oos::json_object, oos::json_bool, and oos::json_null.

virtual void oos::json_type::push_back ( const json_value x)
virtual

Adds a json_value to the current value. If the concrete type doesn't support this method an exception is thrown.

Parameters
xThe json_value to add.

Reimplemented in oos::json_array.

virtual size_t oos::json_type::size ( ) const
virtual

Returns the size of the json_value. If the concrete type doesn't support this method an exception is thrown.

Returns
The size of the json_value.

Reimplemented in oos::json_object, and oos::json_array.

std::string oos::json_type::type ( ) const

Return the type string of the json_type.

Returns
The type string.
void oos::json_type::type ( const std::string &  type)
protected

Sets the type string of the json_type.

Parameters
typeThe type string to set

Friends And Related Function Documentation

OOS_API std::ostream& operator<< ( std::ostream &  str,
const json_type value 
)
friend

Output operator for json_type. Each concrete type overloads a print method, to have it print out correctly.

Parameters
strThe output stream to print on.
valueThe json_type to print.
Returns
The modified output stream.
OOS_API std::istream& operator>> ( std::istream &  str,
json_object obj 
)
friend

Input operator for json_object. In order to parse an object the corresponding input operator needs access to json_type.

Parameters
strThe input stream to print on.
objThe json_object to parse.
Returns
The modified input stream.
OOS_API std::istream& operator>> ( std::istream &  str,
json_array obj 
)
friend

Input operator for json_array. In order to parse an array the corresponding input operator needs access to json_type.

Parameters
strThe input stream to print on.
objThe json_array to parse.
Returns
The modified input stream.

Member Data Documentation

json_parser oos::json_type::parser
staticprotected

The json_parser object


The documentation for this class was generated from the following file:
  • json/json_type.hpp