cesium-native
0.41.0
|
A generic implementation of a value in a JSON structure. More...
#include <CesiumUtility/JsonValue.h>
Public Types | |
using | Null = std::nullptr_t |
The type to represent a null JSON value. | |
using | Bool = bool |
The type to represent a Bool JSON value. | |
using | String = std::string |
The type to represent a String JSON value. | |
using | Object = std::map< std::string, JsonValue > |
The type to represent an Object JSON value. | |
using | Array = std::vector< JsonValue > |
The type to represent an Array JSON value. | |
Public Member Functions | |
JsonValue () noexcept | |
Default constructor. | |
JsonValue (std::nullptr_t) noexcept | |
Creates a null JSON value. | |
JsonValue (double v) noexcept | |
Creates a Number JSON value. More... | |
JsonValue (std::int8_t v) noexcept | |
Creates a std::int64_t JSON value (Widening conversion from std::int8_t). | |
JsonValue (std::uint8_t v) noexcept | |
Creates a std::uint64_t JSON value (Widening conversion from std::uint8_t). | |
JsonValue (std::int16_t v) noexcept | |
Creates a std::int64_t JSON value (Widening conversion from std::int16_t). | |
JsonValue (std::uint16_t v) noexcept | |
Creates a std::uint64_t JSON value (Widening conversion from std::uint16_t). | |
JsonValue (std::int32_t v) noexcept | |
Creates a std::int64_t JSON value (Widening conversion from std::int32_t). | |
JsonValue (std::uint32_t v) noexcept | |
Creates a std::uint64_t JSON value (Widening conversion from std::uint32_t). | |
JsonValue (std::int64_t v) noexcept | |
Creates a std::int64_t JSON value. | |
JsonValue (std::uint64_t v) noexcept | |
Creates a std::uint64_t JSON value. | |
JsonValue (bool v) noexcept | |
Creates a Bool JSON value. | |
JsonValue (const std::string &v) | |
Creates a String JSON value. | |
JsonValue (std::string &&v) noexcept | |
Creates a String JSON value. | |
JsonValue (const char *v) | |
Creates a String JSON value. | |
JsonValue (const std::map< std::string, JsonValue > &v) | |
Creates an Object JSON value with the given properties. | |
JsonValue (std::map< std::string, JsonValue > &&v) | |
Creates an Object JSON value with the given properties. | |
JsonValue (const std::vector< JsonValue > &v) | |
Creates an Array JSON value with the given elements. | |
JsonValue (std::vector< JsonValue > &&v) noexcept | |
Creates an Array JSON value with the given elements. | |
JsonValue (std::initializer_list< JsonValue > v) | |
Creates an JSON value from the given initializer list. | |
JsonValue (std::initializer_list< std::pair< const std::string, JsonValue >> v) | |
Creates an JSON value from the given initializer list. | |
const JsonValue * | getValuePtrForKey (const std::string &key) const |
JsonValue * | getValuePtrForKey (const std::string &key) |
template<typename T > | |
const T * | getValuePtrForKey (const std::string &key) const |
Gets a typed value corresponding to the given key in the object represented by this instance. More... | |
template<typename T > | |
T * | getValuePtrForKey (const std::string &key) |
Gets a typed value corresponding to the given key in the object represented by this instance. More... | |
template<typename To , typename std::enable_if< std::is_integral< To >::value||std::is_floating_point< To >::value >::type * = nullptr> | |
To | getSafeNumericalValueForKey (const std::string &key) const |
Converts the numerical value corresponding to the given key to the provided numerical template type. More... | |
template<typename To , typename std::enable_if< std::is_integral< To >::value||std::is_floating_point< To >::value >::type * = nullptr> | |
To | getSafeNumericalValueOrDefaultForKey (const std::string &key, To defaultValue) const |
Converts the numerical value corresponding to the given key to the provided numerical template type. More... | |
bool | hasKey (const std::string &key) const |
Determines if this value is an Object and has the given key. More... | |
template<typename To , typename std::enable_if< std::is_integral< To >::value||std::is_floating_point< To >::value >::type * = nullptr> | |
To | getSafeNumber () const |
Gets the numerical quantity from the value casted to the To type. This function should be used over getDouble() / getUint64() / getInt64() if you plan on casting that type into another smaller type or different type. More... | |
template<typename To , typename std::enable_if< std::is_integral< To >::value||std::is_floating_point< To >::value >::type * = nullptr> | |
To | getSafeNumberOrDefault (To defaultValue) const noexcept |
Gets the numerical quantity from the value casted to the To type or returns defaultValue if unable to do so. More... | |
const JsonValue::Object & | getObject () const |
Gets the object from the value. More... | |
const JsonValue::String & | getString () const |
Gets the string from the value. More... | |
const JsonValue::Array & | getArray () const |
Gets the array from the value. More... | |
std::vector< std::string > | getArrayOfStrings (const std::string &defaultString) const |
Gets an array of strings from the value. More... | |
bool | getBool () const |
Gets the bool from the value. More... | |
double | getDouble () const |
Gets the double from the value. More... | |
std::uint64_t | getUint64 () const |
Gets the std::uint64_t from the value. More... | |
std::int64_t | getInt64 () const |
Gets the std::int64_t from the value. More... | |
bool | getBoolOrDefault (bool defaultValue) const noexcept |
Gets the bool from the value or returns defaultValue. More... | |
const JsonValue::String | getStringOrDefault (String defaultValue) const |
Gets the string from the value or returns defaultValue. More... | |
double | getDoubleOrDefault (double defaultValue) const noexcept |
Gets the double from the value or returns defaultValue. More... | |
std::uint64_t | getUint64OrDefault (std::uint64_t defaultValue) const noexcept |
Gets the uint64_t from the value or returns defaultValue. More... | |
std::int64_t | getInt64OrDefault (std::int64_t defaultValue) const noexcept |
Gets the int64_t from the value or returns defaultValue. More... | |
bool | isNull () const noexcept |
Returns whether this value is a null value. | |
bool | isNumber () const noexcept |
Returns whether this value is a double , std::uint64_t or std::int64_t . Use this function in conjunction with getNumber for safely casting to arbitrary types. | |
bool | isBool () const noexcept |
Returns whether this value is a Bool value. | |
bool | isString () const noexcept |
Returns whether this value is a String value. | |
bool | isObject () const noexcept |
Returns whether this value is an Object value. | |
bool | isArray () const noexcept |
Returns whether this value is an Array value. | |
bool | isDouble () const noexcept |
Returns whether this value is a double value. | |
bool | isUint64 () const noexcept |
Returns whether this value is a std::uint64_t value. | |
bool | isInt64 () const noexcept |
Returns whether this value is a std::int64_t value. | |
Public Attributes | |
std::variant< Null, double, std::uint64_t, std::int64_t, Bool, String, Object, Array > | value |
The actual value. More... | |
A generic implementation of a value in a JSON structure.
Instances of this class are used to represent the common extras
field of glTF elements that extend the the ExtensibleObject class.
Definition at line 67 of file JsonValue.h.
|
inlinenoexcept |
Creates a Number
JSON value.
NaN and ±Infinity are represented as JsonValue::Null.
Definition at line 109 of file JsonValue.h.
|
inline |
Gets the array from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::Array |
Definition at line 435 of file JsonValue.h.
std::vector<std::string> CesiumUtility::JsonValue::getArrayOfStrings | ( | const std::string & | defaultString | ) | const |
Gets an array of strings from the value.
defaultString | The default string to include in the array for an element that is not a string. |
|
inline |
Gets the bool from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::Bool |
Definition at line 456 of file JsonValue.h.
|
inlinenoexcept |
Gets the bool from the value or returns defaultValue.
Definition at line 493 of file JsonValue.h.
|
inline |
Gets the double from the value.
std::bad_variant_access | if the underlying type is not a double |
Definition at line 465 of file JsonValue.h.
|
inlinenoexcept |
Gets the double from the value or returns defaultValue.
Definition at line 521 of file JsonValue.h.
|
inline |
Gets the std::int64_t from the value.
std::bad_variant_access | if the underlying type is not a std::int64_t |
Definition at line 485 of file JsonValue.h.
|
inlinenoexcept |
Gets the int64_t from the value or returns defaultValue.
Definition at line 549 of file JsonValue.h.
|
inline |
Gets the object from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::Object |
Definition at line 415 of file JsonValue.h.
|
inline |
Gets the numerical quantity from the value casted to the To
type. This function should be used over getDouble()
/ getUint64()
/ getInt64()
if you plan on casting that type into another smaller type or different type.
If | the underlying value is not a numerical type or it cannot be converted without precision loss. |
Definition at line 358 of file JsonValue.h.
|
inlinenoexcept |
Gets the numerical quantity from the value casted to the To
type or returns defaultValue if unable to do so.
defaultValue
if it cannot be converted safely. Definition at line 389 of file JsonValue.h.
|
inline |
Converts the numerical value corresponding to the given key to the provided numerical template type.
If this instance is not a JsonValue::Object, throws std::bad_variant_access
. If the key does not exist in this object, throws JsonValueMissingKey
. If the named value does not have a numerical type T, throws JsonValueNotRealValue
, if the named value cannot be converted from double
/ std::uint64_t
/ std::int64_t
without precision loss, throws gsl::narrowing_error
To | The expected type of the value. |
key | The key for which to retrieve the value from this object. |
If | unable to convert the converted value for one of the aforementioned reasons. |
Definition at line 286 of file JsonValue.h.
|
inline |
Converts the numerical value corresponding to the given key to the provided numerical template type.
If this instance is not a JsonValue::Object, the key does not exist in this object, or the named value does not have a numerical type that can be represented as T without precision loss, then the default value is returned.
To | The expected type of the value. |
key | The key for which to retrieve the value from this object. |
If | unable to convert the converted value for one of the aforementioned reasons. |
Definition at line 317 of file JsonValue.h.
|
inline |
Gets the string from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::String |
Definition at line 425 of file JsonValue.h.
|
inline |
Gets the string from the value or returns defaultValue.
Definition at line 507 of file JsonValue.h.
|
inline |
Gets the std::uint64_t from the value.
std::bad_variant_access | if the underlying type is not a std::uint64_t |
Definition at line 475 of file JsonValue.h.
|
inlinenoexcept |
Gets the uint64_t from the value or returns defaultValue.
Definition at line 535 of file JsonValue.h.
|
inline |
Gets a typed value corresponding to the given key in the object represented by this instance.
If this instance is not a JsonValue::Object, returns nullptr
. If the key does not exist in this object, returns nullptr
. If the named value does not have the type T, returns nullptr.
T | The expected type of the value. |
key | The key for which to retrieve the value from this object. |
Definition at line 257 of file JsonValue.h.
|
inline |
Gets a typed value corresponding to the given key in the object represented by this instance.
If this instance is not a JsonValue::Object, returns nullptr
. If the key does not exist in this object, returns nullptr
. If the named value does not have the type T, returns nullptr.
T | The expected type of the value. |
key | The key for which to retrieve the value from this object. |
Definition at line 234 of file JsonValue.h.
|
inline |
Determines if this value is an Object and has the given key.
key | The key. |
Definition at line 335 of file JsonValue.h.
std::variant< Null, double, std::uint64_t, std::int64_t, Bool, String, Object, Array> CesiumUtility::JsonValue::value |
The actual value.
The type of the value may be queried with the isNull
, isDouble
, isBool
, isString
, isObject
, isUint64
, isInt64
, isNumber
, and isArray
functions.
The actual value may be obtained with the getNumber
, getBool
, and getString
functions for the respective types. For Object
values, the properties may be accessed with the getValueForKey
functions.
Definition at line 644 of file JsonValue.h.