This class represents either a json value an object or an array. More...
#include <json.hpp>
Public Types | |
enum | json_type { e_null , e_integer , e_real , e_boolean , e_string , e_object , e_array } |
typedef json_iterator< json > | iterator |
typedef const_json_iterator< json > | const_iterator |
typedef std::map< std::string, json > | object_type |
typedef std::vector< json > | array_type |
Public Member Functions | |
json () | |
template<class T > | |
json (T val, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< bool, T >::value >::type *=0) | |
template<class T > | |
json (T val, typename std::enable_if< std::is_floating_point< T >::value >::type *=0) | |
template<class T > | |
json (T val, typename std::enable_if< std::is_convertible< T, std::string >::value >::type *=0) | |
json (bool b) | |
json (std::initializer_list< json > l) | |
json (std::nullptr_t n) | |
json (json_type t) | |
~json () | |
template<class T > | |
json & | operator= (T val) |
json (const json &x) | |
json (json &&x) noexcept | |
json & | operator= (json &&x) noexcept |
json & | operator= (const json &x) |
std::string | str () const |
std::string | str (const json_format &format) const |
void | dump (std::ostream &out) const |
json & | operator[] (const std::string &key) |
const json & | operator[] (const std::string &key) const |
bool | contains (const std::string &key) const |
json & | operator[] (std::size_t i) |
const json & | operator[] (std::size_t i) const |
template<class T > | |
void | push_back (const T &val) |
json & | back () |
const json & | back () const |
template<class T > | |
void | reset (T val, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< bool, T >::value >::type *=0) |
template<class T > | |
void | reset (T val, typename std::enable_if< std::is_floating_point< T >::value >::type *=0) |
void | reset (const std::string &val) |
void | reset (const char *val) |
void | reset (bool b) |
std::size_t | size () const |
bool | empty () const |
iterator | begin () |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
template<class T > | |
std::enable_if< std::is_integral< T >::value &&!std::is_same< bool, T >::value, T >::type | as () const |
template<class T > | |
std::enable_if< std::is_floating_point< T >::value, T >::type | as () const |
template<class T > | |
std::enable_if< std::is_same< bool, T >::value, T >::type | as () const |
template<class T > | |
std::enable_if< std::is_convertible< T, std::string >::value, T >::type | as () const |
template<class T > | |
bool | fits_to_type (typename std::enable_if< std::is_integral< T >::value &&!std::is_same< bool, T >::value >::type *=0) const |
template<class T > | |
bool | fits_to_type (typename std::enable_if< std::is_floating_point< T >::value >::type *=0) const |
template<class T > | |
bool | fits_to_type (typename std::enable_if< std::is_same< bool, T >::value >::type *=0) const |
template<class T > | |
bool | fits_to_type (typename std::enable_if< std::is_convertible< T, std::string >::value >::type *=0) const |
json_type | type () const |
bool | is_number () const |
bool | is_real () const |
bool | is_integer () const |
bool | is_boolean () const |
bool | is_string () const |
bool | is_array () const |
bool | is_object () const |
bool | is_null () const |
template<class T > | |
T | at (std::size_t pos) const |
json & | get (const std::string &key) |
const json & | get (const std::string &key) const |
json & | at_path (const std::string &path, char delimiter='.') |
const json & | at_path (const std::string &path, char delimiter='.') const |
void | clear () |
void | erase (const std::string &key) |
void | erase (std::size_t i) |
Static Public Member Functions | |
static json | object () |
static json | array () |
Friends | |
class | json_iterator< json > |
class | const_json_iterator< json > |
OOS_JSON_API bool | operator== (const json &a, const json &b) |
OOS_JSON_API bool | operator!= (const json &a, const json &b) |
OOS_JSON_API bool | operator< (const json &a, const json &b) |
OOS_JSON_API bool | operator<= (const json &a, const json &b) |
OOS_JSON_API bool | operator> (const json &a, const json &b) |
OOS_JSON_API bool | operator>= (const json &a, const json &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator< (const json &a, const T &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator< (const T &a, const json &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator<= (const json &a, const T &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator<= (const T &a, const json &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator> (const json &a, const T &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator> (const T &a, const json &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator>= (const json &a, const T &b) |
template<class T , typename std::enable_if< std::is_scalar< T >::value >::type > | |
bool | operator>= (const T &a, const json &b) |
OOS_JSON_API std::ostream & | operator<< (std::ostream &out, const json &val) |
This class represents either a json value an object or an array.
This class represents any json value
typedef std::vector<json> matador::json::array_type |
Shortcut to json array vector type
Shortcut to json const iterator type
typedef json_iterator<json> matador::json::iterator |
Shortcut to json iterator type
typedef std::map<std::string, json> matador::json::object_type |
Shortcut to json object map type
matador::json::json | ( | ) |
Creates an json null value
|
inline |
Creates a number json value where the value is treated like an integer of type long long
T | Type of the value |
val | Value of the json object |
|
inline |
Creates a number json value where the value is treated like a floating point of type double
T | Type of the value |
val | Value of the json object |
|
inline |
Creates a string json value where the value is treated like std::string
T | Type of the value |
val | Value of the json object |
matador::json::json | ( | bool | b | ) |
Creates a boolean json value
b | The boolean value of the json object |
matador::json::json | ( | std::initializer_list< json > | l | ) |
Creates a json array from the initializer list.
Note: If the list contains just two elements and the first element is of type string an json object is created.
l |
matador::json::json | ( | std::nullptr_t | n | ) |
Creates a null value json object
n | Null value |
|
explicit |
Creates explicitly a json object of the give json type
t | Type of the json object |
matador::json::~json | ( | ) |
Destroys the json object
matador::json::json | ( | const json & | x | ) |
Copy construct a josn object from the given json object
x | The json object to copy from |
|
noexcept |
Copy move the given json object
x | The json object to copy move |
|
static |
Creates an empty json array.
|
inline |
Return the json value as an integral type
If json type isn't integer a std::logic_error is thrown
std::logic_error | If the type isn't integral |
|
inline |
Return the json value as a floating point type
If json type isn't a floating point a std::logic_error is thrown
std::logic_error | If the type isn't floating point |
|
inline |
Return the json value as a boolean
If json type isn't boolean a std::logic_error is thrown
std::logic_error | If the type isn't boolean |
|
inline |
Return the json value as a string
If json type isn't string a std::logic_error is thrown
std::logic_error | If the type isn't of type string |
|
inline |
Returns the json element at given position if the current json is of type array.
if current json isn't of type array an std::logic_error is thrown.
pos | The position of the requested element |
std::logic_error | If json isn't of type array |
json & matador::json::at_path | ( | const std::string & | path, |
char | delimiter = '.' |
||
) |
Returns the json value at the given path. The path is a list of keys delimited by a delimiter char. The default delimiter is a "." (dot).
path | Path to find |
delimiter | Delimiter in the path |
const json & matador::json::at_path | ( | const std::string & | path, |
char | delimiter = '.' |
||
) | const |
Returns the json value at the given path. The path is a list of keys delimited by a delimiter char. The default delimiter is a "." (dot).
path | Path to find |
delimiter | Delimiter in the path |
json & matador::json::back | ( | ) |
Returns a reference to the last json object of the array.
If the current type isn't array an exception is thrown.
std::logic_error | Throws a std::logic_error if the current type isn't of type array |
const json & matador::json::back | ( | ) | const |
Returns a const reference to the last json object of the array.
If the current type isn't array an exception is thrown.
std::logic_error | Throws a std::logic_error if the current type isn't of type array |
iterator matador::json::begin | ( | ) |
Returns the begin iterator of the json array or the json object. If the json isn't of type array or object this json object is return in the iterator
const_iterator matador::json::begin | ( | ) | const |
Returns the begin iterator of the json array or the json object. If the json isn't of type array or object this json object is return in the iterator
|
inline |
Clears the current json object.
All json values are deleted and the type is set to null
bool matador::json::contains | ( | const std::string & | key | ) | const |
Returns true if json is of type object and contains the given key
key | Key to check |
void matador::json::dump | ( | std::ostream & | out | ) | const |
Print the json object to the given ostream
out | The stream to write on |
bool matador::json::empty | ( | ) | const |
Returns the corresponding result of empty() if json is of type array or of type object. If json is of type null then false is returned. For all other types true is returned.
iterator matador::json::end | ( | ) |
Returns the end iterator of the json array or the json object. If the json isn't of type array or object this json object is return in the iterator
const_iterator matador::json::end | ( | ) | const |
Returns the end iterator of the json array or the json object. If the json isn't of type array or object this json object is return in the iterator
void matador::json::erase | ( | const std::string & | key | ) |
Erases the json element with given key. If json isn't of type object nothing is done.
key | The key of the element to erase |
void matador::json::erase | ( | std::size_t | i | ) |
Erases the json element at the given position. If json isn't of type array nothing is done. If the given position is out of bounce an appropriate std::logic_error is thrown
i | The position of the element to erase |
|
inline |
Returns true if the given type is a string
|
inline |
Returns true if the given type is a floating point type
|
inline |
Returns true if the given type is an integral type
|
inline |
Returns true if the given type is a boolean
json & matador::json::get | ( | const std::string & | key | ) |
Gets the json value at the given key. If the key couldn't be found an exception is thrown
key | Key to find |
const json & matador::json::get | ( | const std::string & | key | ) | const |
Gets the json value at the given key. If the key couldn't be found an exception is thrown
key | Key to find |
bool matador::json::is_array | ( | ) | const |
Returns true if json type is an array
bool matador::json::is_boolean | ( | ) | const |
Returns true if json type is a boolean
bool matador::json::is_integer | ( | ) | const |
Returns true if json type is an integral type
bool matador::json::is_null | ( | ) | const |
Returns true if json type is null
bool matador::json::is_number | ( | ) | const |
Returns true if json type is a number
bool matador::json::is_object | ( | ) | const |
Returns true if json type is an object
bool matador::json::is_real | ( | ) | const |
Returns true if json type is a floating point type
bool matador::json::is_string | ( | ) | const |
Returns true if json type is a string
|
static |
Creates an empty json object.
Copy assign the given json object
x | The json object to copy assign |
Move assign the given json object
x | The json object to move assign |
|
inline |
Assigns a value to the json object On json type change the changes are adjusted
T | Type of the value |
val | Value to assign |
json & matador::json::operator[] | ( | const std::string & | key | ) |
Get the json object of the given key. If the json type isn't object the type is changed to object and a json null value is inserted at key
key | The key of the requested value |
const json & matador::json::operator[] | ( | const std::string & | key | ) | const |
Get the json object of the given key. If the json type isn't object the type the object itself is returned (this)
key | The key of the requested value |
json & matador::json::operator[] | ( | std::size_t | i | ) |
Get the json object at given index i if the json if of type array.
If the json isn't of type array a reference the this json is returned. If the index is out of bound a logic_error is thrown
i | Index of the requested value |
std::logic_error | If the index is out of bounce |
const json & matador::json::operator[] | ( | std::size_t | i | ) | const |
Get the json object at given index i if the json if of type array.
If the json isn't of type array a reference the this json is returned. If the index is out of bound a logic_error is thrown
i | Index of the requested value |
std::logic_error | If the index is out of bounce |
|
inline |
Push back the given value to the json array
If the current type of the json object isn't array the type is changed to array.
T | The type of the value to push back |
val | The value to push back |
void matador::json::reset | ( | bool | b | ) |
Resets the json value to a new boolean type value.
b | Value to set |
|
inline |
Resets the json value to a new string type value.
T | Type of the new value |
val | Value to set |
|
inline |
Resets the json value to a new string type value.
T | Type of the new value |
val | Value to set |
|
inline |
Resets the json value to a new floating point (number) type value.
T | Type of the new value |
val | Value to set |
|
inline |
Resets the json value to a new integer (number) type value.
T | Type of the new value |
val | Value to set |
std::size_t matador::json::size | ( | ) | const |
Returns either the size of the json array or the size of a json object. If the type is null then 0 (zero) is returned. For all other types 1 (one) is returned
std::string matador::json::str | ( | ) | const |
Creates a string of the json object
std::string matador::json::str | ( | const json_format & | format | ) | const |
Creates a string of the json object with the given json format
format | Format object defining the json output |
json_type matador::json::type | ( | ) | const |
Returns the json type enum
Compares equality of two json objects
a | First json object to compare |
b | Second json object to compare |
Compares two json objects if first object is less than second.
a | First json object to compare |
b | Second json object to compare |
|
friend |
Less operator with a json value with a scalar value
T | Type of the scalar value |
a | The json value to compare |
b | The scalar value to compare |
|
friend |
Less operator with a scalar value with a json value
T | Type of the scalar value |
a | The scalar value to compare |
b | The json value to compare |
|
friend |
Print the json object to the given ostream
out | The stream to write on |
val | The json object to write |
Compares two json objects if first object is less than or equal second.
a | First json object to compare |
b | Second json object to compare |
|
friend |
Less or equal to operator with a json value with a scalar value
T | Type of the scalar value |
a | The json value to compare |
b | The scalar value to compare |
|
friend |
Less or equal to operator with a scalar value with a json value
T | Type of the scalar value |
a | The scalar value to compare |
b | The json value to compare |
Compares equality of two json objects
a | First json object to compare |
b | Second json object to compare |
Compares two json objects if first object is greater than second.
a | First json object to compare |
b | Second json object to compare |
|
friend |
Greater operator with a json value with a scalar value
T | Type of the scalar value |
a | The json value to compare |
b | The scalar value to compare |
|
friend |
Greater operator with a scalar value with a json value
T | Type of the scalar value |
a | The scalar value to compare |
b | The json value to compare |
Compares two json objects if first object is greater than or equal second.
a | First json object to compare |
b | Second json object to compare |
|
friend |
Greater or equal to operator with a json value with a scalar value
T | Type of the scalar value |
a | The json value to compare |
b | The scalar value to compare |
|
friend |
Greater or equal to operator with a scalar value with a json value
T | Type of the scalar value |
a | The scalar value to compare |
b | The json value to compare |