rippled
|
Represents a JSON value. More...
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=nullValue) | |
Create a default Value of the given type. More... | |
Value (Int value) | |
Value (UInt value) | |
Value (double value) | |
Value (const char *value) | |
Value (const StaticString &value) | |
Constructs a value from a static string. More... | |
Value (std::string const &value) | |
Value (bool value) | |
Value (const Value &other) | |
~Value () | |
Value & | operator= (Value const &other) |
Value & | operator= (Value &&other) |
Value (Value &&other) noexcept | |
void | swap (Value &other) noexcept |
Swap values. More... | |
ValueType | type () const |
const char * | asCString () const |
std::string | asString () const |
Returns the unquoted string value. More... | |
Int | asInt () const |
UInt | asUInt () const |
double | asDouble () const |
bool | asBool () const |
bool | isNull () const |
isNull() tests to see if this field is null. More... | |
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. More... | |
operator bool () const | |
Returns false if this is an empty array, empty object, empty string, or null. More... | |
void | clear () |
Remove all object members and array elements. More... | |
Value & | operator[] (UInt index) |
Access an array element (zero based index ). More... | |
const Value & | 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.) More... | |
Value | get (UInt index, const Value &defaultValue) const |
If the array contains at least index+1 elements, returns the element value, otherwise returns defaultValue. More... | |
bool | isValidIndex (UInt index) const |
Return true if index < size(). More... | |
Value & | append (const Value &value) |
Append value to array at the end. More... | |
Value & | append (Value &&value) |
Value & | operator[] (const char *key) |
Access an object value by name, create a null member if it does not exist. More... | |
const Value & | operator[] (const char *key) const |
Access an object value by name, returns null if there is no member with that name. More... | |
Value & | operator[] (std::string const &key) |
Access an object value by name, create a null member if it does not exist. More... | |
const Value & | operator[] (std::string const &key) const |
Access an object value by name, returns null if there is no member with that name. More... | |
Value & | operator[] (const StaticString &key) |
Access an object value by name, create a null member if it does not exist. More... | |
Value | get (const char *key, const Value &defaultValue) const |
Return the member named key if it exist, defaultValue otherwise. More... | |
Value | get (std::string const &key, const Value &defaultValue) const |
Return the member named key if it exist, defaultValue otherwise. More... | |
Value | removeMember (const char *key) |
Remove and return the named member. More... | |
Value | removeMember (std::string const &key) |
Same as removeMember(const char*) More... | |
bool | isMember (const char *key) const |
Return true if the object has a member named key. More... | |
bool | isMember (std::string const &key) const |
Return true if the object has a member named key. More... | |
Members | getMemberNames () const |
Return a list of the member names. More... | |
std::string | toStyledString () const |
const_iterator | begin () const |
const_iterator | end () const |
iterator | begin () |
iterator | end () |
Static Public Attributes | |
static const Value | null |
static const Int | minInt = Int(~(UInt(-1) / 2)) |
static const Int | maxInt = Int(UInt(-1) / 2) |
static const UInt | maxUInt = UInt(-1) |
Private Member Functions | |
Value & | resolveReference (const char *key, bool isStatic) |
Private Attributes | |
union Json::Value::ValueHolder | value_ |
ValueType | type_: 8 |
int | allocated_: 1 |
Friends | |
class | ValueIteratorBase |
bool | operator== (const Value &, const Value &) |
bool | operator< (const Value &, const Value &) |
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 objectValue or arrayValue can be accessed using operator[]() methods. Non const methods will automatically create the a nullValue element if it does not exist. The sequence of an arrayValue will be automatically resize and initialized with nullValue. resize() can be used to enlarge or truncate an arrayValue.
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 objectValue values using the getMemberNames() method.
Definition at line 145 of file json_value.h.
using Json::Value::Members = std::vector<std::string> |
Definition at line 150 of file json_value.h.
using Json::Value::iterator = ValueIterator |
Definition at line 151 of file json_value.h.
Definition at line 152 of file json_value.h.
using Json::Value::UInt = Json::UInt |
Definition at line 153 of file json_value.h.
using Json::Value::Int = Json::Int |
Definition at line 154 of file json_value.h.
using Json::Value::ArrayIndex = UInt |
Definition at line 155 of file json_value.h.
using Json::Value::ObjectValues = std::map<CZString, Value> |
Definition at line 194 of file json_value.h.
Create a default Value of the given type.
This is a very useful constructor. To create an empty array, pass arrayValue. To create an empty object, pass objectValue. 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 180 of file json_value.cpp.
Json::Value::Value | ( | Int | value | ) |
Definition at line 214 of file json_value.cpp.
Json::Value::Value | ( | UInt | value | ) |
Definition at line 219 of file json_value.cpp.
Json::Value::Value | ( | double | value | ) |
Definition at line 224 of file json_value.cpp.
Json::Value::Value | ( | const char * | value | ) |
Definition at line 229 of file json_value.cpp.
Json::Value::Value | ( | const StaticString & | 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 240 of file json_value.cpp.
Json::Value::Value | ( | std::string const & | value | ) |
Definition at line 234 of file json_value.cpp.
Json::Value::Value | ( | bool | value | ) |
Definition at line 245 of file json_value.cpp.
Json::Value::Value | ( | const Value & | other | ) |
Definition at line 250 of file json_value.cpp.
Json::Value::~Value | ( | ) |
Definition at line 284 of file json_value.cpp.
|
noexcept |
Definition at line 320 of file json_value.cpp.
Definition at line 313 of file json_value.cpp.
Definition at line 328 of file json_value.cpp.
|
noexcept |
Swap values.
Definition at line 336 of file json_value.cpp.
ValueType Json::Value::type | ( | ) | const |
Definition at line 350 of file json_value.cpp.
const char * Json::Value::asCString | ( | ) | const |
Definition at line 462 of file json_value.cpp.
std::string Json::Value::asString | ( | ) | const |
Returns the unquoted string value.
Definition at line 469 of file json_value.cpp.
Value::Int Json::Value::asInt | ( | ) | const |
Definition at line 503 of file json_value.cpp.
Value::UInt Json::Value::asUInt | ( | ) | const |
Definition at line 545 of file json_value.cpp.
double Json::Value::asDouble | ( | ) | const |
Definition at line 587 of file json_value.cpp.
bool Json::Value::asBool | ( | ) | const |
Definition at line 619 of file json_value.cpp.
bool Json::Value::isNull | ( | ) | const |
isNull() tests to see if this field is null.
Don't use this method to test for emptiness: use empty().
Definition at line 967 of file json_value.cpp.
bool Json::Value::isBool | ( | ) | const |
Definition at line 973 of file json_value.cpp.
bool Json::Value::isInt | ( | ) | const |
Definition at line 979 of file json_value.cpp.
bool Json::Value::isUInt | ( | ) | const |
Definition at line 985 of file json_value.cpp.
bool Json::Value::isIntegral | ( | ) | const |
Definition at line 991 of file json_value.cpp.
bool Json::Value::isDouble | ( | ) | const |
Definition at line 997 of file json_value.cpp.
bool Json::Value::isNumeric | ( | ) | const |
Definition at line 1003 of file json_value.cpp.
bool Json::Value::isString | ( | ) | const |
Definition at line 1009 of file json_value.cpp.
bool Json::Value::isArray | ( | ) | const |
Definition at line 1015 of file json_value.cpp.
bool Json::Value::isArrayOrNull | ( | ) | const |
Definition at line 1021 of file json_value.cpp.
bool Json::Value::isObject | ( | ) | const |
Definition at line 1027 of file json_value.cpp.
bool Json::Value::isObjectOrNull | ( | ) | const |
Definition at line 1033 of file json_value.cpp.
bool Json::Value::isConvertibleTo | ( | ValueType | other | ) | const |
Definition at line 651 of file json_value.cpp.
Value::UInt Json::Value::size | ( | ) | const |
Number of values in array or object.
Definition at line 706 of file json_value.cpp.
|
explicit |
Returns false if this is an empty array, empty object, empty string, or null.
Definition at line 738 of file json_value.cpp.
void Json::Value::clear | ( | ) |
Remove all object members and array elements.
Definition at line 753 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 771 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 790 of file json_value.cpp.
If the array contains at least index+1 elements, returns the element value, otherwise returns defaultValue.
Definition at line 834 of file json_value.cpp.
bool Json::Value::isValidIndex | ( | UInt | index | ) | const |
Return true if index < size().
Definition at line 841 of file json_value.cpp.
Append value to array at the end.
Equivalent to jsonvalue[jsonvalue.size()] = value;
Definition at line 882 of file json_value.cpp.
Definition at line 888 of file json_value.cpp.
Value & Json::Value::operator[] | ( | const char * | key | ) |
Access an object value by name, create a null member if it does not exist.
Definition at line 807 of file json_value.cpp.
const Value & Json::Value::operator[] | ( | const char * | key | ) | const |
Access an object value by name, returns null if there is no member with that name.
Definition at line 847 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 864 of file json_value.cpp.
const Value & 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 870 of file json_value.cpp.
Value & Json::Value::operator[] | ( | const StaticString & | 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 876 of file json_value.cpp.
Return the member named key if it exist, defaultValue otherwise.
Definition at line 894 of file json_value.cpp.
Value Json::Value::get | ( | std::string const & | key, |
const Value & | defaultValue | ||
) | const |
Return the member named key if it exist, defaultValue otherwise.
Definition at line 901 of file json_value.cpp.
Value Json::Value::removeMember | ( | const char * | key | ) |
Remove and return the named member.
Do nothing if it did not exist.
Definition at line 907 of file json_value.cpp.
Value Json::Value::removeMember | ( | std::string const & | key | ) |
Same as removeMember(const char*)
Definition at line 926 of file json_value.cpp.
bool Json::Value::isMember | ( | const char * | key | ) | const |
Return true if the object has a member named key.
Definition at line 932 of file json_value.cpp.
bool Json::Value::isMember | ( | std::string const & | key | ) | const |
Return true if the object has a member named key.
Definition at line 942 of file json_value.cpp.
Value::Members Json::Value::getMemberNames | ( | ) | const |
Return a list of the member names.
If null, return an empty list.
Definition at line 948 of file json_value.cpp.
std::string Json::Value::toStyledString | ( | ) | const |
Definition at line 1039 of file json_value.cpp.
Value::iterator Json::Value::begin | ( | ) | const |
Definition at line 1046 of file json_value.cpp.
Value::iterator Json::Value::end | ( | ) | const |
Definition at line 1064 of file json_value.cpp.
iterator Json::Value::begin | ( | ) |
iterator Json::Value::end | ( | ) |
|
private |
Definition at line 813 of file json_value.cpp.
|
friend |
Definition at line 147 of file json_value.h.
Definition at line 416 of file json_value.cpp.
Definition at line 367 of file json_value.cpp.
|
static |
Definition at line 157 of file json_value.h.
Definition at line 158 of file json_value.h.
Definition at line 159 of file json_value.h.
Definition at line 160 of file json_value.h.
|
private |
|
private |
Definition at line 432 of file json_value.h.
|
private |
Definition at line 433 of file json_value.h.