| 
    MLIB
    
   | 
 
Representation of a JSON node. More...
#include <json.h>
Classes | |
| 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).   | |
| void | push_back (const node &n) | 
| Append an element at the end of an array.  | |
| 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::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.  | |
| const node * | find (const std::string &name) const | 
| If node is an object and has a child with the given name, returns a pointer to child node.   | |
| node * | find (const std::string &name) | 
| If node is an object and has a child with the given name, returns a pointer to child node.   | |
| 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.  | |
| void | format (const std::string &f) | 
| Set output format for numerical values.  | |
| const std::string_view | format () const | 
| Return output format for numerical values.  | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const node &n) | 
| Insertion operator serializes a JSON node to an output stream.   | |
Representation of a JSON node.
      
  | 
  inline | 
Return value of an object node element.
If element doesn't exist it throws an ERR_JSON_MISSING exception.
| const node & mlib::json::node::at | ( | const std::string & | name | ) | const | 
Return value of an object node element.
If element doesn't exist throws an ERR_JSON_MISSING exception.
      
  | 
  inline | 
Return value of an object node element.
If element doesn't exist it throws an ERR_JSON_MISSING exception.
| const node & mlib::json::node::at | ( | size_t | index | ) | const | 
Return value of an array node element (const version).
If element doesn't exist throws an ERR_JSON_MISSING exception.
| node * mlib::json::node::find | ( | const std::string & | name | ) | 
If node is an object and has a child with the given name, returns a pointer to child node.
Otherwise returns nullptr 
| const node * mlib::json::node::find | ( | const std::string & | name | ) | const | 
If node is an object and has a child with the given name, returns a pointer to child node.
Otherwise returns nullptr 
| node & mlib::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 & mlib::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 & mlib::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 & mlib::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.
| erc mlib::json::node::read | ( | const std::string & | s | ) | 
Parse a string to a JSON node.
Returns an error if there are any extra characters after the JSON text.
| mlib::erc mlib::json::node::write | ( | std::string & | s, | 
| int | flags = 0, | ||
| int | spaces = 0 ) const | 
Write node to a string.
| s | output string | 
| flags | formatting flags | 
| spaces | number of spaces to indent. If 0 uses tabs instead of spaces | 
      
  | 
  friend | 
Insertion operator serializes a JSON node to an output stream.
Write a JSON object to a stream.