|
xrpld
|
Represents a JSON value. More...
#include <json_value.h>

Classes | |
| class | CZString |
| union | ValueHolder |
Public Types | |
| using | Members = std::vector<std::string> |
| using | iterator = ValueIterator |
| using | const_iterator = ValueConstIterator |
| using | UInt = json::UInt |
| using | Int = json::Int |
| using | ArrayIndex = UInt |
| using | ObjectValues = std::map<CZString, Value> |
Public Member Functions | |
| Value (ValueType type=ValueType::Null) | |
| Create a default Value of the given type. | |
| Value (Int value) | |
| Value (UInt value) | |
| Value (double value) | |
| Value (char const *value) | |
| Value (xrpl::Number const &value) | |
| Value (StaticString const &value) | |
| Constructs a value from a static string. | |
| Value (std::string const &value) | |
| Value (bool value) | |
| Value (Value const &other) | |
| ~Value () | |
| Value & | operator= (Value const &other) |
| Value & | operator= (Value &&other) |
| Value (Value &&other) noexcept | |
| void | swap (Value &other) noexcept |
| Swap values. | |
| ValueType | type () const |
| char const * | asCString () const |
| std::string | asString () const |
| Returns the unquoted string value. | |
| Int | asInt () const |
| UInt | asUInt () const |
| double | asDouble () const |
| bool | asBool () const |
| UInt | asAbsUInt () const |
| Correct absolute value from int or unsigned int. | |
| bool | isNull () const |
| isNull() tests to see if this field is null. | |
| bool | isBool () const |
| bool | isInt () const |
| bool | isUInt () const |
| bool | isIntegral () const |
| bool | isDouble () const |
| bool | isNumeric () const |
| bool | isString () const |
| bool | isArray () const |
| bool | isArrayOrNull () const |
| bool | isObject () const |
| bool | isObjectOrNull () const |
| bool | isConvertibleTo (ValueType other) const |
| UInt | size () const |
| Number of values in array or object. | |
| operator bool () const | |
| Returns false if this is an empty array, empty object, empty string, or null. | |
| void | clear () |
| Remove all object members and array elements. | |
| Value & | operator[] (UInt index) |
| Access an array element (zero based index ). | |
| Value const & | operator[] (UInt index) const |
| Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.). | |
| Value | get (UInt index, Value const &defaultValue) const |
| If the array contains at least index+1 elements, returns the element value, otherwise returns defaultValue. | |
| bool | isValidIndex (UInt index) const |
| Return true if index < size(). | |
| Value & | append (Value const &value) |
| Append value to array at the end. | |
| Value & | append (Value &&value) |
| Value & | operator[] (char const *key) |
| Access an object value by name, create a null member if it does not exist. | |
| Value const & | operator[] (char const *key) const |
| Access an object value by name, returns null if there is no member with that name. | |
| Value & | operator[] (std::string const &key) |
| Access an object value by name, create a null member if it does not exist. | |
| Value const & | operator[] (std::string const &key) const |
| Access an object value by name, returns null if there is no member with that name. | |
| Value & | operator[] (StaticString const &key) |
| Access an object value by name, create a null member if it does not exist. | |
| Value const & | operator[] (StaticString const &key) const |
| Value | get (char const *key, Value const &defaultValue) const |
| Return the member named key if it exist, defaultValue otherwise. | |
| Value | get (std::string const &key, Value const &defaultValue) const |
| Return the member named key if it exist, defaultValue otherwise. | |
| Value | removeMember (char const *key) |
| Remove and return the named member. | |
| Value | removeMember (std::string const &key) |
| Same as removeMember(const char*). | |
| bool | isMember (char const *key) const |
| Return true if the object has a member named key. | |
| bool | isMember (std::string const &key) const |
| Return true if the object has a member named key. | |
| bool | isMember (StaticString const &key) const |
| Return true if the object has a member named key. | |
| Members | getMemberNames () const |
| Return a list of the member names. | |
| std::string | toStyledString () const |
| const_iterator | begin () const |
| const_iterator | end () const |
| iterator | begin () |
| iterator | end () |
Static Public Attributes | |
| static Value const | kNull |
| static constexpr Int | kMinInt = std::numeric_limits<Int>::min() |
| static constexpr Int | kMaxInt = std::numeric_limits<Int>::max() |
| static constexpr UInt | kMaxUInt = std::numeric_limits<UInt>::max() |
Private Member Functions | |
| Value & | resolveReference (char const *key, bool isStatic) |
Private Attributes | |
| union json::Value::ValueHolder | value_ |
| ValueType | type_: 8 |
| int | allocated_: 1 {} |
Friends | |
| class | ValueIteratorBase |
| bool | operator== (Value const &x, Value const &y) |
| bool | operator< (Value const &x, Value const &y) |
Represents a JSON value.
This class is a discriminated union wrapper that can represent a:
The type of the held value is represented by a ValueType and can be obtained using type().
values of an ValueType::Object or ValueType::Array can be accessed using operator[]() methods. Non const methods will automatically create the a ValueType::Null element if it does not exist. The sequence of an ValueType::Array will be automatically resize and initialized with ValueType::Null. resize() can be used to enlarge or truncate an ValueType::Array.
The get() methods can be used to obtain a default value in the case the required element does not exist.
It is possible to iterate over the list of a ValueType::Object values using the getMemberNames() method.
Definition at line 129 of file json_value.h.
| using json::Value::Members = std::vector<std::string> |
Definition at line 134 of file json_value.h.
| using json::Value::iterator = ValueIterator |
Definition at line 135 of file json_value.h.
Definition at line 136 of file json_value.h.
| using json::Value::UInt = json::UInt |
Definition at line 137 of file json_value.h.
| using json::Value::Int = json::Int |
Definition at line 138 of file json_value.h.
| using json::Value::ArrayIndex = UInt |
Definition at line 139 of file json_value.h.
| using json::Value::ObjectValues = std::map<CZString, Value> |
Definition at line 175 of file json_value.h.
| json::Value::Value | ( | ValueType | type = ValueType::Null | ) |
Create a default Value of the given type.
This is a very useful constructor. To create an empty array, pass ValueType::Array. To create an empty object, pass ValueType::Object. Another Value can then be set to this one by assignment. This is useful since clear() and resize() will not alter types.
Examples:
Definition at line 171 of file json_value.cpp.
| json::Value::Value | ( | Int | value | ) |
Definition at line 207 of file json_value.cpp.
| json::Value::Value | ( | UInt | value | ) |
Definition at line 212 of file json_value.cpp.
| json::Value::Value | ( | double | value | ) |
Definition at line 217 of file json_value.cpp.
| json::Value::Value | ( | char const * | value | ) |
Definition at line 222 of file json_value.cpp.
| json::Value::Value | ( | xrpl::Number const & | value | ) |
Definition at line 227 of file json_value.cpp.
| json::Value::Value | ( | StaticString const & | value | ) |
Constructs a value from a static string.
Like other value string constructor but do not duplicate the string for internal storage. The given string must remain alive after the call to this constructor. Example of usage:
Definition at line 239 of file json_value.cpp.
| json::Value::Value | ( | std::string const & | value | ) |
Definition at line 233 of file json_value.cpp.
| json::Value::Value | ( | bool | value | ) |
Definition at line 244 of file json_value.cpp.
| json::Value::Value | ( | Value const & | other | ) |
Definition at line 249 of file json_value.cpp.
| json::Value::~Value | ( | ) |
Definition at line 286 of file json_value.cpp.
|
noexcept |
Definition at line 324 of file json_value.cpp.
Definition at line 317 of file json_value.cpp.
Definition at line 332 of file json_value.cpp.
|
noexcept |
Swap values.
Definition at line 340 of file json_value.cpp.
|
nodiscard |
Definition at line 354 of file json_value.cpp.
|
nodiscard |
Definition at line 476 of file json_value.cpp.
|
nodiscard |
Returns the unquoted string value.
Definition at line 483 of file json_value.cpp.
|
nodiscard |
Definition at line 519 of file json_value.cpp.
|
nodiscard |
Definition at line 620 of file json_value.cpp.
|
nodiscard |
Definition at line 663 of file json_value.cpp.
|
nodiscard |
Definition at line 697 of file json_value.cpp.
|
nodiscard |
Correct absolute value from int or unsigned int.
Definition at line 562 of file json_value.cpp.
|
nodiscard |
isNull() tests to see if this field is null.
Don't use this method to test for emptiness: use empty().
Definition at line 1079 of file json_value.cpp.
|
nodiscard |
Definition at line 1085 of file json_value.cpp.
|
nodiscard |
Definition at line 1091 of file json_value.cpp.
|
nodiscard |
Definition at line 1097 of file json_value.cpp.
|
nodiscard |
Definition at line 1103 of file json_value.cpp.
|
nodiscard |
Definition at line 1109 of file json_value.cpp.
|
nodiscard |
Definition at line 1115 of file json_value.cpp.
|
nodiscard |
Definition at line 1121 of file json_value.cpp.
|
nodiscard |
Definition at line 1127 of file json_value.cpp.
|
nodiscard |
Definition at line 1133 of file json_value.cpp.
|
nodiscard |
Definition at line 1139 of file json_value.cpp.
|
nodiscard |
Definition at line 1145 of file json_value.cpp.
|
nodiscard |
Definition at line 731 of file json_value.cpp.
|
nodiscard |
Number of values in array or object.
Definition at line 788 of file json_value.cpp.
|
explicit |
Returns false if this is an empty array, empty object, empty string, or null.
Definition at line 822 of file json_value.cpp.
| void json::Value::clear | ( | ) |
Remove all object members and array elements.
Definition at line 838 of file json_value.cpp.
Access an array element (zero based index ).
If the array contains less than index element, then null value are inserted in the array so that its size is index+1. (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.)
Definition at line 857 of file json_value.cpp.
Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.).
Definition at line 878 of file json_value.cpp.
If the array contains at least index+1 elements, returns the element value, otherwise returns defaultValue.
Definition at line 928 of file json_value.cpp.
|
nodiscard |
Return true if index < size().
Definition at line 935 of file json_value.cpp.
Append value to array at the end.
Equivalent to jsonvalue[jsonvalue.size()] = value;
Definition at line 984 of file json_value.cpp.
Definition at line 990 of file json_value.cpp.
| Value & json::Value::operator[] | ( | char const * | key | ) |
Access an object value by name, create a null member if it does not exist.
Definition at line 897 of file json_value.cpp.
| Value const & json::Value::operator[] | ( | char const * | key | ) | const |
Access an object value by name, returns null if there is no member with that name.
Definition at line 941 of file json_value.cpp.
| Value & json::Value::operator[] | ( | std::string const & | key | ) |
Access an object value by name, create a null member if it does not exist.
Definition at line 960 of file json_value.cpp.
| Value const & json::Value::operator[] | ( | std::string const & | key | ) | const |
Access an object value by name, returns null if there is no member with that name.
Definition at line 966 of file json_value.cpp.
| Value & json::Value::operator[] | ( | StaticString const & | key | ) |
Access an object value by name, create a null member if it does not exist.
If the object as no entry for that name, then the member name used to store the new entry is not duplicated. Example of use:
Definition at line 972 of file json_value.cpp.
| Value const & json::Value::operator[] | ( | StaticString const & | key | ) | const |
Definition at line 978 of file json_value.cpp.
Return the member named key if it exist, defaultValue otherwise.
Definition at line 996 of file json_value.cpp.
|
nodiscard |
Return the member named key if it exist, defaultValue otherwise.
Definition at line 1003 of file json_value.cpp.
| Value json::Value::removeMember | ( | char const * | key | ) |
Remove and return the named member.
Do nothing if it did not exist.
Definition at line 1009 of file json_value.cpp.
| Value json::Value::removeMember | ( | std::string const & | key | ) |
Same as removeMember(const char*).
Definition at line 1030 of file json_value.cpp.
| bool json::Value::isMember | ( | char const * | key | ) | const |
Return true if the object has a member named key.
Definition at line 1036 of file json_value.cpp.
|
nodiscard |
Return true if the object has a member named key.
Definition at line 1046 of file json_value.cpp.
|
nodiscard |
Return true if the object has a member named key.
Definition at line 1052 of file json_value.cpp.
|
nodiscard |
Return a list of the member names.
If null, return an empty list.
Definition at line 1058 of file json_value.cpp.
|
nodiscard |
Definition at line 1151 of file json_value.cpp.
|
nodiscard |
Definition at line 1158 of file json_value.cpp.
|
nodiscard |
Definition at line 1176 of file json_value.cpp.
| Value::iterator json::Value::begin | ( | ) |
Definition at line 1194 of file json_value.cpp.
| Value::iterator json::Value::end | ( | ) |
Definition at line 1211 of file json_value.cpp.
|
private |
Definition at line 903 of file json_value.cpp.
|
friend |
Definition at line 131 of file json_value.h.
Definition at line 428 of file json_value.cpp.
Definition at line 372 of file json_value.cpp.
|
static |
Definition at line 141 of file json_value.h.
|
staticconstexpr |
Definition at line 142 of file json_value.h.
|
staticconstexpr |
Definition at line 143 of file json_value.h.
|
staticconstexpr |
Definition at line 144 of file json_value.h.
|
private |
|
private |
Definition at line 424 of file json_value.h.
|
private |
Definition at line 425 of file json_value.h.