|
CppCMS
|
This class is central representation of json objects. More...
#include <cppcms/json.h>
Public Member Functions | |
| json_type | type () const |
| bool | is_undefined () const |
| bool | is_null () const |
| bool const & | boolean () const |
| double const & | number () const |
| std::string const & | str () const |
| json::object const & | object () const |
| json::array const & | array () const |
| bool & | boolean () |
| double & | number () |
| std::string & | str () |
| json::object & | object () |
| json::array & | array () |
| void | undefined () |
| void | null () |
| void | boolean (bool) |
| void | number (double) |
| void | str (std::string const &) |
| void | object (json::object const &) |
| void | array (json::array const &) |
| template<typename T > | |
| T | get_value () const |
| template<typename T > | |
| void | set_value (T const &v) |
| value const & | find (std::string const &path) const |
| value const & | find (char const *path) const |
| value const & | at (std::string const &path) const |
| value const & | at (char const *path) const |
| value & | at (std::string const &path) |
| value & | at (char const *path) |
| void | at (std::string const &path, value const &v) |
| void | at (char const *path, value const &v) |
| template<typename T > | |
| value (T const &v) | |
| json_type | type (std::string const &path) const |
| json_type | type (char const *path) const |
| template<typename T > | |
| void | set (std::string const &path, T const &v) |
| template<typename T > | |
| void | set (char const *path, T const &v) |
| std::string | get (std::string const &path, char const *def) const |
| std::string | get (char const *path, char const *def) const |
| template<typename T > | |
| T | get (std::string const &path) const |
| template<typename T > | |
| T | get (char const *path) const |
| template<typename T > | |
| T | get (char const *path, T const &def) const |
| template<typename T > | |
| T | get (std::string const &path, T const &def) const |
| value & | operator[] (std::string const &name) |
| value const & | operator[] (std::string const &name) const |
| value & | operator[] (size_t n) |
| value const & | operator[] (size_t n) const |
| std::string | save (int how=compact) const |
| void | save (std::ostream &out, int how=compact) const |
| bool | load (std::istream &in, bool full, int *line_number=0) |
| bool | load (char const *&begin, char const *end, bool full, int *line_number=0) |
| bool | operator== (value const &other) const |
| bool | operator!= (value const &other) const |
| value & | operator= (value &&other) |
| value (value &&other) | |
| value (value const &other) | |
| value const & | operator= (value const &other) |
| value () | |
| ~value () | |
| void | swap (value &other) |
Friends | |
| struct | copyable |
This class is central representation of json objects.
It can be a value from any type including scalar, object, array and undefined
|
inline |
Creates a value from and object v of type T
|
inline |
Move constructor
|
inline |
Copy constructor
|
inline |
Default value - creates a value of undefined type
|
inline |
Destructor
| json::array const& cppcms::json::value::array | ( | ) | const |
Convert value to json::array, throws bad_value_cast if value's type is not array
Referenced by swap().
| json::array& cppcms::json::value::array | ( | ) |
Get reference to array variable that represents this value, throws bad_value_cast if type is invalid
| void cppcms::json::value::array | ( | json::array const & | ) |
Set value to array type and assign it
| value const& cppcms::json::value::at | ( | std::string const & | path | ) | const |
Searches a value in the path path, if not found throw bad_value_cast.
For example if the json::value represents { "x" : { "y" : 10 } }, then find("x.y") would return a reference to value that hold a number 10, find("x") returns a reference to a value that holds an object { "y" : 10 } and find("foo") throws
| value const& cppcms::json::value::at | ( | char const * | path | ) | const |
Searches a value in the path path, if not found throw bad_value_cast.
For example if the json::value represents { "x" : { "y" : 10 } }, then find("x.y") would return a reference to value that hold a number 10, find("x") returns a reference to a value that holds an object { "y" : 10 } and find("foo") throws
| value& cppcms::json::value::at | ( | std::string const & | path | ) |
Searches a value in the path path, if not found throw bad_value_cast.
For example if the json::value represents { "x" : { "y" : 10 } }, then find("x.y") would return a reference to value that hold a number 10, find("x") returns a reference to a value that holds an object { "y" : 10 } and find("foo") throws
| value& cppcms::json::value::at | ( | char const * | path | ) |
Searches a value in the path path, if not found throw bad_value_cast.
For example if the json::value represents { "x" : { "y" : 10 } }, then find("x.y") would return a reference to value that hold a number 10, find("x") returns a reference to a value that holds an object { "y" : 10 } and find("foo") throws
| void cppcms::json::value::at | ( | std::string const & | path, |
| value const & | v | ||
| ) |
Sets the value v at the path path, if the path invalid, creates it.
| void cppcms::json::value::at | ( | char const * | path, |
| value const & | v | ||
| ) |
Sets the value v at the path path, if the path invalid, creates it.
| bool const& cppcms::json::value::boolean | ( | ) | const |
Convert value to boolean, throws bad_value_cast if value's type is not boolean
| bool& cppcms::json::value::boolean | ( | ) |
Get reference to bool variable that represents this value, throws bad_value_cast if type is invalid
| void cppcms::json::value::boolean | ( | bool | ) |
Set value to boolean type and assign it
| value const& cppcms::json::value::find | ( | std::string const & | path | ) | const |
Searches a value in the path path
For example if the json::value represents { "x" : { "y" : 10 } }, then find("x.y") would return a reference to value that hold a number 10, find("x") returns a reference to a value that holds an object { "y" : 10 } and find("foo") would return value of undefined type.
| value const& cppcms::json::value::find | ( | char const * | path | ) | const |
Searches a value in the path path
For example if the json::value represents { "x" : { "y" : 10 } }, then find("x.y") would return a reference to value that hold a number 10, find("x") returns a reference to a value that holds an object { "y" : 10 } and find("foo") would return value of undefined type.
|
inline |
Get a string value from a path path. If the path is not invalid or the object is not of type string at this path, returns def instead
References get_value(), and is_undefined().
|
inline |
Get a string value from a path path. If the path is not invalid or the object is not of type string at this path, returns def instead
References get_value(), and is_undefined().
|
inline |
Get an object of type T from the path path. Throws bad_value_cast if such path does not exists of conversion can't be done
|
inline |
Get an object of type T from the path path. Throws bad_value_cast if such path does not exists of conversion can't be done
|
inline |
Get an object of type T from the path path. Returns def if such path does not exists of conversion can't be done
References get_value(), and is_undefined().
|
inline |
Get an object of type T from the path path. Returns def if such path does not exists of conversion can't be done
References cppcms::json::compact, get_value(), and is_undefined().
|
inline |
Convert the value to type T, using json::traits, throws bad_value_cast if conversion is not possible
References cppcms::json::traits< T >::get().
| bool cppcms::json::value::is_null | ( | ) | const |
Returns true if type()==json::is_null
| bool cppcms::json::value::is_undefined | ( | ) | const |
Returns true if type()==json::is_undefined
Referenced by get().
| bool cppcms::json::value::load | ( | std::istream & | in, |
| bool | full, | ||
| int * | line_number = 0 |
||
| ) |
Read a value from std::istream.
Note: only JSON object and JSON array are considered valid values
| in | the std::istream used to read the data |
| full | require EOF once the object is read, otherwise consider it as syntax error |
| line_number | return a number of the line where syntax error occurred |
| bool cppcms::json::value::load | ( | char const *& | begin, |
| char const * | end, | ||
| bool | full, | ||
| int * | line_number = 0 |
||
| ) |
Read a value from character range
Note: only JSON object and JSON array are considered valid values
| begin | - begin of the text range, at the end points to the end of parsed range |
| end | - end of the text range |
| full | require EOF once the object is read, otherwise consider it as syntax error |
| line_number | return a number of the line where syntax error occurred |
| void cppcms::json::value::null | ( | ) |
Set value to null type
| double const& cppcms::json::value::number | ( | ) | const |
Convert value to double, throws bad_value_cast if value's type is not number
Referenced by swap().
| double& cppcms::json::value::number | ( | ) |
Get reference to double variable that represents this value, throws bad_value_cast if type is invalid
| void cppcms::json::value::number | ( | double | ) |
Set value to numeric type and assign it
| json::object const& cppcms::json::value::object | ( | ) | const |
Convert value to json::object, throws bad_value_cast if value's type is not object
Referenced by swap().
| json::object& cppcms::json::value::object | ( | ) |
Get reference to object variable that represents this value, throws bad_value_cast if type is invalid
| void cppcms::json::value::object | ( | json::object const & | ) |
Set value to object type and assign it
| bool cppcms::json::value::operator!= | ( | value const & | other | ) | const |
Compare two values objects, return false if they are same
| bool cppcms::json::value::operator== | ( | value const & | other | ) | const |
Compare two values objects, return true if they are same
| value& cppcms::json::value::operator[] | ( | std::string const & | name | ) |
Returns a reference to the node name of the value. For value = {"x",10} and name == "x" return a value that holds 10.
If value is not object it's type set to object. If such node does not exits, it is created with undefined value
| value const& cppcms::json::value::operator[] | ( | std::string const & | name | ) | const |
Returns reference to the node name of the value. For value = {"x",10} and name == "x" return a value that holds 10.
If value is not object or such node does not exits, throws bad_value_cast
| value& cppcms::json::value::operator[] | ( | size_t | n | ) |
Returns a reference to n 'th entry of the array. If the value is not an array it is reset to array, of the array is too small it is resized to size of at least n+1
| value const& cppcms::json::value::operator[] | ( | size_t | n | ) | const |
Returns a reference to n 'th entry of array, if the value is not array or n is too big, throws bad_value_cast
| std::string cppcms::json::value::save | ( | int | how = compact | ) | const |
Convert a value to std::string, if how has value readable it is converted with indentation
| void cppcms::json::value::save | ( | std::ostream & | out, |
| int | how = compact |
||
| ) | const |
Write a value to std::ostream, if how has value readable it is converted with indentation
|
inline |
Convert an object v of type T to a value at specific path, same as at(path,value(v))
|
inline |
Convert an object v of type T to a value at specific path, same as at(path,value(v))
|
inline |
Convert the object v of type T to the value
References cppcms::json::traits< T >::set().
| std::string const& cppcms::json::value::str | ( | ) | const |
Convert value to strng, throws bad_value_cast if value's type is not string
| std::string& cppcms::json::value::str | ( | ) |
Get reference to string variable that represents this value, throws bad_value_cast if type is invalid
| void cppcms::json::value::str | ( | std::string const & | ) |
Set value to string type and assign it
|
inline |
Swaps two values, does not throw.
References array(), get_value(), number(), booster::locale::as::number(), object(), and cppcms::json::to_json().
|
inline |
|
inline |
| void cppcms::json::value::undefined | ( | ) |
Set value to undefined type
1.8.11