MLIB
|
Representation of a JSON node. More...
#include <json.h>
Data Structures | |
class | iterator_type |
node iterator More... | |
Public Types | |
using | pnode = std::unique_ptr< node > |
using | nodes_map = std::map< const std::string, pnode > |
using | nodes_array = std::vector< pnode > |
typedef iterator_type< false > | iterator |
typedef iterator_type< true > | const_iterator |
Public Member Functions | |
node (type t=type::null) | |
Constructor for an empty node. | |
node (const std::string &s) | |
Constructor for a string type node. | |
node (const char *s) | |
Alternate constructor for a string node. | |
node (double d) | |
Constructor for a numeric node. | |
node (int d) | |
Alternate constructor for a numeric node. | |
node (bool b) | |
Constructor for a boolean node. | |
template<typename T > | |
node (const std::vector< T > &vec) | |
Constructor from a vector. | |
template<class T > | |
node (const T &t, decltype(&T::to_json) *=nullptr) | |
Constructor from an object. | |
node (const node &other) | |
Copy constructor. | |
node (node &&other) | |
Move constructor. | |
node & | operator= (const node &rhs) |
Principal assignment operator. | |
node & | operator= (node &&rhs) |
Move assignment operator. | |
template<class T , typename B = decltype (&T::to_json)> | |
node & | operator= (const T &t) |
Assignment operator. | |
node & | operator= (bool b) |
Boolean assignment. | |
template<typename T , typename B = std::enable_if_t<std::is_arithmetic_v<T>>> | |
node & | operator= (T n) |
Numeric assignment. | |
node & | operator= (const std::string &s) |
String assignment. | |
node & | operator= (const char *s) |
C string assignment. | |
operator std::string () const | |
Return node value as a string (if possible) | |
operator const char * () const | |
operator double () const | |
Return numeric value of a node. | |
operator float () const | |
Return numeric value of a node. | |
operator int () const | |
operator bool () const | |
Return boolean value of the node. | |
double | to_num () const |
std::string | to_str () const |
String conversion function. | |
bool | to_bool () const |
Conversion to boolean value. | |
node & | operator[] (const std::string &name) |
Return value of an object node element. | |
const node & | operator[] (const std::string &name) const |
Return value of an object node element (const version). | |
node & | at (const std::string &name) |
Return value of an object node element. | |
const node & | at (const std::string &name) const |
Return value of an object node element. | |
node & | operator[] (size_t index) |
Return value of an array node element. | |
const node & | operator[] (size_t index) const |
Return value of an array node element (const version). | |
node & | at (size_t index) |
Return value of an object node element. | |
const node & | at (size_t index) const |
Return value of an array node element (const version). | |
const_iterator | begin () const |
Begin iterator (const variant) | |
iterator | begin () |
Begin iterator (non-const variant) | |
const_iterator | end () const |
End iterator (const variant) | |
iterator | end () |
End iterator (non-const variant) | |
bool | operator== (const node &other) const |
Equality operator. | |
bool | operator!= (const node &other) const |
inequality operator | |
mlib::erc | read (std::istream &s) |
Deserialize the node from an input stream. | |
mlib::erc | read (const std::string &s) |
Parse a string to a JSON node. | |
mlib::erc | write (std::ostream &os, int flags=0, int spaces=0, int level=0) const |
Write node to a stream. | |
mlib::erc | write (std::string &s, int flags=0, int spaces=0) const |
Write node to a string. | |
bool | has (const std::string &name) const |
Return true if node is an object and has a child with that name. | |
void | erase (const std::string &name) |
Erase the child with that name, if it exists. | |
void | clear (type t=type::null) |
Remove previous node content. | |
type | kind () const |
Return the type of node. | |
int | size () const |
Return number of direct descendants. | |
Representation of a JSON node.
Return value of an object node element.
If element doesn't exist it throws an ERR_JSON_MISSING exception.
Return value of an object node element.
If element doesn't exist throws an ERR_JSON_MISSING exception.
Return value of an object node element.
If element doesn't exist it throws an ERR_JSON_MISSING exception.
Return value of an array node element (const version).
If element doesn't exist throws an ERR_JSON_MISSING exception.
node & json::node::operator[] | ( | const std::string & | name | ) |
Return value of an object node element.
If name
doesn't exist, it is appended to node.
const node & json::node::operator[] | ( | const std::string & | name | ) | const |
Return value of an object node element (const version).
If element doesn't exist it throws an ERR_JSON_MISSING exception.
node & json::node::operator[] | ( | size_t | index | ) |
Return value of an array node element.
If element doesn't exist the array is extended with null elements.
const node & json::node::operator[] | ( | size_t | index | ) | const |
Return value of an array node element (const version).
If element doesn't exist throws an ERR_JSON_MISSING exception.
Parse a string to a JSON node.
Returns an error if there are any extra characters after the JSON text.
Write node to a stream.
os | stream to write to |
flags | formatting flags |
spaces | number of spaces to indent. If 0 uses tabs instead of spaces |
level | starting indentation level |