#include <dxjson.h>
|
typedef std::map< std::string, JSON >::iterator | object_iterator |
|
typedef std::map< std::string, JSON >::const_iterator | const_object_iterator |
|
typedef std::vector< JSON >::iterator | array_iterator |
|
typedef std::vector< JSON >::const_iterator | const_array_iterator |
|
typedef std::map< std::string, JSON >::const_reverse_iterator | object_reverse_iterator |
|
typedef std::map< std::string, JSON >::reverse_iterator | const_object_reverse_iterator |
|
typedef std::vector< JSON >::reverse_iterator | array_reverse_iterator |
|
typedef std::vector< JSON >::const_reverse_iterator | const_array_reverse_iterator |
|
The JSON class. Object of this class are capable of storing/operating on arbitrary JSON values.
Definition at line 137 of file dxjson.h.
Default constructor for JSON. Creates JSON of type JSON_UNDEFINED.
Definition at line 175 of file dxjson.h.
JSON::JSON |
( |
const JSON & |
rhs | ) |
|
Copy constructor
- Parameters
-
rhs | This is the JSON object which will be copied. |
Definition at line 547 of file dxjson.cpp.
Construct a blank JSON object of a particular JSONValue type, i.e., (this->type() == rhs) after construction.
Definition at line 542 of file dxjson.cpp.
template<typename T >
dx::JSON::JSON |
( |
const T & |
x | ) |
|
This constructor copies the parameter x's value using operator=().
- Exceptions
-
- Parameters
-
x | The new JSON object will be constructed from this value. |
Definition at line 759 of file dxjson.h.
Erases and deallocate any memory for the current JSON object
Definition at line 611 of file dxjson.h.
JSON::const_array_iterator JSON::array_begin |
( |
| ) |
const |
Returns iterator to beginning.
- Exceptions
-
- Returns
- A const iterator to the first element in the container.
Definition at line 900 of file dxjson.cpp.
JSON::array_iterator JSON::array_begin |
( |
| ) |
|
Returns iterator to beginning.
- Exceptions
-
- Returns
- An iterator to the first element in the container.
Definition at line 912 of file dxjson.cpp.
JSON::const_array_iterator JSON::array_end |
( |
| ) |
const |
Returns iterator to end.
- Exceptions
-
- Returns
- A const iterator to the element past-the-end of the container.
Definition at line 924 of file dxjson.cpp.
JSON::array_iterator JSON::array_end |
( |
| ) |
|
Returns iterator to end.
- Exceptions
-
- Returns
- An iterator to the element past-the-end of the container.
Definition at line 936 of file dxjson.cpp.
JSON::const_array_reverse_iterator JSON::array_rbegin |
( |
| ) |
const |
Returns reverse iterator to reverse beginning.
- Exceptions
-
JSONException | If called on an object which not a JSON_ARRAY A reverse iterator referring to the last element in the container. |
Definition at line 949 of file dxjson.cpp.
JSON::array_reverse_iterator JSON::array_rbegin |
( |
| ) |
|
Returns reverse iterator to reverse beginning.
- Exceptions
-
JSONException | If called on an object which not a JSON_ARRAY A const reverse iterator referring to the last element in the container. |
Definition at line 961 of file dxjson.cpp.
JSON::const_array_reverse_iterator JSON::array_rend |
( |
| ) |
const |
Returns reverse iterator to reverse end.
- Exceptions
-
JSONException | If called on an object which not a JSON_ARRAY A const reverse iterator referring to the element right before the first element (which is considered to be the reverse end) |
Definition at line 973 of file dxjson.cpp.
JSON::array_reverse_iterator JSON::array_rend |
( |
| ) |
|
Returns reverse iterator to reverse end.
- Exceptions
-
JSONException | If called on an object which not a JSON_ARRAY A reverse iterator referring to the element right before the first element (which is considered to be the reverse end) |
Definition at line 985 of file dxjson.cpp.
void JSON::erase |
( |
const size_t & |
indx | ) |
|
Removes a particular index inside a JSON_ARRAY
- Exceptions
-
- Parameters
-
indx | The index to be removed from array |
Definition at line 682 of file dxjson.cpp.
void JSON::erase |
( |
const std::string & |
key | ) |
|
Removes a particular key and it's associated value inside a JSON_HASH
- Exceptions
-
- Note
- The parameter "key" will be treated as serialized JSON string
- Parameters
-
key | The key value to be removed from object. |
Definition at line 688 of file dxjson.cpp.
template<typename T >
T dx::JSON::get |
( |
| ) |
const |
|
inline |
Provide conversion functionality from JSON object to some fundamental data types. This generic version works only for numeric types (and has same effect as overloaded conversion operator). A specialization for std::string exist too.
- Returns
- Value of JSON object in desired fundamental type
- Exceptions
-
Definition at line 442 of file dxjson.h.
double JSON::getEpsilon |
( |
| ) |
|
|
static |
Returns the current "epsilon" paramerer value. This value determines the "slack" while checking equality of two JSON_REAL values.
- Returns
- The currrent value of "epsilon" parameter
- See also
- json_epsilon
Definition at line 27 of file dxjson.cpp.
Referenced by erase().
template<typename T >
bool dx::JSON::has |
( |
const T & |
indx | ) |
const |
|
inline |
Returns true if the given numeric value represent a valid index in current JSON_ARRAY.
- Exceptions
-
- Parameters
-
indx | the value representing an index inside array. |
- Returns
- true if "indx" is a valid location in array, else false.
Definition at line 488 of file dxjson.h.
Referenced by has().
bool JSON::has |
( |
const size_t & |
indx | ) |
const |
Returns true if the given size_t value represent a valid index in current JSON_ARRAY.
- Exceptions
-
- Parameters
-
indx | the value representing an index inside array. |
- Returns
- true if "indx" is a valid location in array, else false.
Definition at line 648 of file dxjson.cpp.
bool JSON::has |
( |
const std::string & |
key | ) |
const |
Returns true if the given std::string key represent a valid key in current JSON_OBJECT.
- Exceptions
-
- Note
- The parameter "key" will be treated as serialized JSON string
- Parameters
-
key | the value to be looked for inside current JSON_OBJECT. |
- Returns
- true if is a valid key, else false.
Definition at line 655 of file dxjson.cpp.
bool JSON::has |
( |
const JSON & |
j | ) |
const |
Allow using a JSON object for has() - converted to a suitable type before executing.
- Exceptions
-
JSONException | If suitable conversion of input parameter is not possible. |
Definition at line 665 of file dxjson.cpp.
bool JSON::has |
( |
const char * |
key | ) |
const |
Exactly same behavior as has(const std::string &key) function. The given C-string is converted to std::string before executing the function.
- Exceptions
-
- Note
- The parameter "key" will be treated as serialized JSON string
Definition at line 661 of file dxjson.cpp.
size_t dx::JSON::length |
( |
| ) |
const |
|
inline |
JSON::const_object_iterator JSON::object_begin |
( |
| ) |
const |
Returns iterator to beginning.
- Exceptions
-
- Returns
- A const iterator to the first element in the container.
Definition at line 894 of file dxjson.cpp.
JSON::object_iterator JSON::object_begin |
( |
| ) |
|
Returns iterator to beginning.
- Exceptions
-
- Returns
- An iterator to the first element in the container.
Definition at line 906 of file dxjson.cpp.
JSON::const_object_iterator JSON::object_end |
( |
| ) |
const |
Returns iterator to end.
- Exceptions
-
- Returns
- A const iterator to the element past-the-end of the container.
Definition at line 918 of file dxjson.cpp.
JSON::object_iterator JSON::object_end |
( |
| ) |
|
Returns iterator to end.
- Exceptions
-
- Returns
- An iterator to the element past-the-end of the container.
Definition at line 930 of file dxjson.cpp.
template<typename T >
dx::JSON::operator T |
( |
| ) |
const |
Conversion operator. Currently only typecasting to a numeric type (real/integer/bool) is supported.
- Returns
- The typecasted value of JSON object in requested type.
Definition at line 796 of file dxjson.h.
template<typename T >
JSON & dx::JSON::operator= |
( |
const T & |
rhs | ) |
|
Sets the current JSON object's value to the provided numeric value. This is a templatized version, specialized only for numeric types.
- Note
- Current value in object will be erased.
-
The type of JSON object (JSON_INTEGER or JSON_REAL) will be determined by the type of value provided.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 766 of file dxjson.h.
Referenced by JSON(), and operator=().
JSON & JSON::operator= |
( |
const JSON & |
rhs | ) |
|
Copies the provided JSON object's value to current JSON object.
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 569 of file dxjson.cpp.
Creates a blank JSON object of a particular JSONValue type, i.e., this->type() == rhs; to the function, after the call.
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The new type for the JSON |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 554 of file dxjson.cpp.
JSON & JSON::operator= |
( |
const char & |
c | ) |
|
Copies the provided character value to current JSON object (as a JSON_STRING)
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 589 of file dxjson.cpp.
JSON & JSON::operator= |
( |
const std::string & |
s | ) |
|
Copies the provided std::string value to current JSON object (as a JSON_STRING)
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 583 of file dxjson.cpp.
JSON & JSON::operator= |
( |
const bool & |
x | ) |
|
Copies the provided boolean value to current JSON object (as a JSON_BOOLEAN)
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 593 of file dxjson.cpp.
JSON & JSON::operator= |
( |
const char |
s[] | ) |
|
Copies the provided char* value to current JSON object (as a JSON_STRING)
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object (a C-style string) |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 606 of file dxjson.cpp.
JSON& dx::JSON::operator= |
( |
const Null & |
x | ) |
|
Copies the provided Null object's value to current JSON object (as a JSON_NULL).
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
template<typename T >
JSON & dx::JSON::operator= |
( |
const std::vector< T > & |
vec | ) |
|
Copies the provided std::vector value to current JSON object (as a JSON_ARRAY)
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 782 of file dxjson.h.
template<typename T >
JSON & dx::JSON::operator= |
( |
const std::map< std::string, T > & |
m | ) |
|
Copies the provided std::map value to current JSON object (as a JSON_OBJECT)
- Note
- Current value of object will be erased.
- Parameters
-
rhs | The value which will be copied to current object. |
- Returns
- Reference to current object (to allow chaining of = operations).
Definition at line 789 of file dxjson.h.
bool JSON::operator== |
( |
const JSON & |
other | ) |
const |
Equality comparison operator. Returns true if two JSON objects are equal. A deep matching of JSON object is performed.
- Note
- JSON_UNDEFINED != JSON_UNDEFINED
- Parameters
-
other | The JSON object to which current object will be compared. |
- Returns
- true if both objects are same, else false.
- See also
- operator!=()
Definition at line 888 of file dxjson.cpp.
const JSON & JSON::operator[] |
( |
const size_t & |
indx | ) |
const |
Access value stored inside a JSON array by numeric index
- Parameters
-
indx | Index location to be accessed inside current JSON array. |
- Returns
- A constant reference to JSON value stored at given location
- Exceptions
-
Definition at line 501 of file dxjson.cpp.
Referenced by operator[]().
const JSON & JSON::operator[] |
( |
const std::string & |
s | ) |
const |
Access value stored inside JSON object by it's key
- Parameters
-
s | A pre-existing Key inside current object |
- Returns
- A constant reference to JSON value stored under given Key
- Exceptions
-
Definition at line 471 of file dxjson.cpp.
const JSON & JSON::operator[] |
( |
const JSON & |
j | ) |
const |
Access a value inside a JSON object/array, and indexed by the provided JSON. The given JSON object (parameter j) must be numeric (if this->type() == JSON_ARRAY) or string (if this->type() == JSON_OBJECT).
- Parameters
-
j | This JSON value will be used to index the current JSON object. |
- Returns
- A constant reference to JSON value stored at given index.
- Note
- If j.type() == JSON_STRING, a non-serialized version of the string will be used.
- Exceptions
-
JSONException | if conditions specified in descriptions are not met, or if the referenced property/index does not exist. |
Definition at line 508 of file dxjson.cpp.
const JSON & JSON::operator[] |
( |
const char * |
str | ) |
const |
Same as const JSON& operator[](const std::string &s), just that c style string "str" is converted to std::string, before calling it.
- Parameters
-
str | C style string, representing a key inside the object. |
- Returns
- A constant reference to JSON value stored under given key.
Definition at line 492 of file dxjson.cpp.
template<typename T >
const JSON & dx::JSON::operator[] |
( |
const T & |
x | ) |
const |
This function take care of all possible numeric types used for referencing JSON array.
- Parameters
-
x | A numeric value (specialized under std::numeric_limits). It is typecasted to size_t before using it as array index. |
- Exceptions
-
JSONException | If parameter x cannot be converted to a numeric type or this->type() != JSON_ARRAY. |
- Returns
- A constant reference to JSON value stored under given index.
Definition at line 816 of file dxjson.h.
JSON & JSON::operator[] |
( |
const size_t & |
indx | ) |
|
JSON & JSON::operator[] |
( |
const std::string & |
s | ) |
|
JSON & JSON::operator[] |
( |
const JSON & |
j | ) |
|
JSON & JSON::operator[] |
( |
const char * |
str | ) |
|
template<typename T >
JSON& dx::JSON::operator[] |
( |
const T & |
x | ) |
|
|
inline |
static JSON dx::JSON::parse |
( |
const std::string & |
str | ) |
|
|
inlinestatic |
Creates a new JSON object from a serialized representation. See notes for read() (applies here as well)
- Parameters
-
str | The serialized json object. |
- Returns
Definition at line 167 of file dxjson.h.
void JSON::push_back |
( |
const JSON & |
j | ) |
|
Appends a JSON value at end of current JSON_ARRAY object.
- Exceptions
-
- Parameters
-
j | The value to be appended to array. |
Definition at line 632 of file dxjson.cpp.
void JSON::read |
( |
std::istream & |
in | ) |
|
Reads and populates current JSON object from specified input stream containing a valid serialized represntation of JSON value.
- Note
- Previous contents will be cleared.
- It's not necessary that the JSON value being read is serialization of an array or hash only, i.e., serialization of string, number, boolean, and null can be read as well.
- JSON value started by first character of stream is read into object and once the value finishes, rest of the stream's content is not looked into. For example:
- If stream contains: '{"hello": 12}blah', the function will read a JSON_OBJECT({"hello": 12}) and return (without looking ahead at 'blah')
- If stream contains: '12Hello', then function will read a JSON_INTEGER (12) and return (without looking ahead at 'Hello')
- If stream contains: 'null12', then function will read a JSON_NULL and return (without looking ahead at '12')
- If stream contains: 'truenull' then function will read a JSON_BOOLEAN(true) (without looking ahead at 'null').
- If stream contains: '"hello"World' then function will read a JSON_STRING("hello") (without looking at 'World')
- If stream contains: 'truHtrue' then function will throw an error, since characters 'truHtrue' do not represent any legal JSON value starting from first location.
- Parameters
-
in | Input stream object (for reading the serialized JSON) |
- Exceptions
-
JSONException | If string being read is illegal JSON, or error occured while reading the stream. |
- See also
- write()
-
readFromString()
Definition at line 678 of file dxjson.cpp.
Referenced by readFromString().
void JSON::readFromString |
( |
const std::string & |
jstr | ) |
|
Populates current JSON object from the given stringified json value. See notes for read() (applies here as well).
- Parameters
-
jstr | String reprenting a valid JSON object |
- Exceptions
-
- See also
- read()
-
toString()
Definition at line 466 of file dxjson.cpp.
Referenced by parse().
void JSON::resize_array |
( |
size_t |
desired_size | ) |
|
Resizes an JSON_ARRAY. If current size of array = curr_size, and desired size provided by user = desired_size, then
Case curr_size < desired_size: (desired_size - curr_size) number of JSON_UNDEFINED elements are pushed at the end of JSON_ARRAY object.
Case curr_size > desired_size: Last (curr_size - desired_size) number of JSON elements are deleted from array
Case curr_size == desired_size: No effect
After executing this function, size() == desired_size
- Parameters
-
desired_size | The desired size of new array |
Definition at line 991 of file dxjson.cpp.
size_t JSON::size |
( |
| ) |
const |
Returns total number of element in a JSON_ARRAY or JSON_HASH.
- Exceptions
-
JSONException | If called on a object which is not of type JSON_ARRAY or JSON_HASH |
- Returns
- Total number of keys (if a JSON_OBJECT), and total number of values (if JSON_ARRAY).
- See also
- length()
Definition at line 611 of file dxjson.cpp.
Referenced by erase(), and has().
std::string JSON::toString |
( |
bool |
onlyTopLevel = false | ) |
const |
Returns the stringified representation of JSON object.
- Parameters
-
onlyTopLevel | If set to true, then only JSON objects of type JSON_OBJECT or JSON_ARRAY can call this function. |
- Note
- If called on a JSON_STRING object directly, the string would be enclosed in quotes.
- Returns
- A string reprentation of current JSON object.
- See also
- write()
-
readFromString()
Definition at line 640 of file dxjson.cpp.
Returns the type of current JSON object.
- Returns
- Type (a variable of type enum JSONValue) of current JSON object.
Definition at line 450 of file dxjson.h.
Referenced by array_begin(), array_end(), array_rbegin(), array_rend(), erase(), has(), JSON(), object_begin(), object_end(), operator=(), operator==(), operator[](), push_back(), resize_array(), size(), toString(), and write().
void JSON::write |
( |
std::ostream & |
out | ) |
const |
Writes the serialized JSON object to the output stream
- Parameters
-
out | Output stream object, to which the serialized object will be written to |
- Exceptions
-
- See also
- read()
-
toString()
Definition at line 457 of file dxjson.cpp.
Referenced by toString().
This will store pointer to actual JSON value
Definition at line 152 of file dxjson.h.
Referenced by array_begin(), array_end(), array_rbegin(), array_rend(), erase(), getEpsilon(), has(), JSON(), object_begin(), object_end(), operator=(), operator==(), operator[](), push_back(), resize_array(), size(), and write().
The documentation for this class was generated from the following files: