cesium-native 0.44.2
|
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. | |
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 |
Attempts to obtain a pointer to a JsonValue for the given key on this object. | |
JsonValue * | getValuePtrForKey (const std::string &key) |
Attempts to obtain a pointer to a JsonValue for the given key on this object. | |
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. | |
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. | |
template<typename To , typename std::enable_if< std::is_integral< To >::value||std::is_floating_point< To >::value >::type * = nullptr> | |
std::optional< To > | getSafeNumericalValueForKey (const std::string &key) const |
Converts the numerical value corresponding to the given key to the provided numerical template type. | |
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. | |
bool | hasKey (const std::string &key) const |
Determines if this value is an Object and has the given key. | |
template<typename To , typename std::enable_if< std::is_integral< To >::value||std::is_floating_point< To >::value >::type * = nullptr> | |
std::optional< 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. | |
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. | |
const JsonValue::Object & | getObject () const |
Gets the object from the value. | |
const JsonValue::String & | getString () const |
Gets the string from the value. | |
const JsonValue::Array & | getArray () const |
Gets the array from the value. | |
std::vector< std::string > | getArrayOfStrings (const std::string &defaultString) const |
Gets an array of strings from the value. | |
bool | getBool () const |
Gets the bool from the value. | |
double | getDouble () const |
Gets the double from the value. | |
std::uint64_t | getUint64 () const |
Gets the std::uint64_t from the value. | |
std::int64_t | getInt64 () const |
Gets the std::int64_t from the value. | |
bool | getBoolOrDefault (bool defaultValue) const noexcept |
Gets the bool from the value or returns defaultValue. | |
const JsonValue::String | getStringOrDefault (String defaultValue) const |
Gets the string from the value or returns defaultValue. | |
double | getDoubleOrDefault (double defaultValue) const noexcept |
Gets the double from the value or returns defaultValue. | |
std::uint64_t | getUint64OrDefault (std::uint64_t defaultValue) const noexcept |
Gets the uint64_t from the value or returns defaultValue. | |
std::int64_t | getInt64OrDefault (std::int64_t defaultValue) const noexcept |
Gets the int64_t from the value or returns defaultValue. | |
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. | |
bool | operator== (const JsonValue &rhs) const noexcept |
Returns true if two values are equal. | |
int64_t | getSizeBytes () const noexcept |
Returns the size in bytes of this JsonValue . | |
Public Attributes | |
std::variant< Null, double, std::uint64_t, std::int64_t, Bool, String, Object, Array > | value |
The actual value. | |
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 53 of file JsonValue.h.
using CesiumUtility::JsonValue::Array = std::vector<JsonValue> |
The type to represent an Array
JSON value.
Definition at line 78 of file JsonValue.h.
using CesiumUtility::JsonValue::Bool = bool |
The type to represent a Bool
JSON value.
Definition at line 63 of file JsonValue.h.
using CesiumUtility::JsonValue::Null = std::nullptr_t |
The type to represent a null
JSON value.
Definition at line 58 of file JsonValue.h.
using CesiumUtility::JsonValue::Object = std::map<std::string, JsonValue> |
The type to represent an Object
JSON value.
Definition at line 73 of file JsonValue.h.
using CesiumUtility::JsonValue::String = std::string |
The type to represent a String
JSON value.
Definition at line 68 of file JsonValue.h.
|
inlinenoexcept |
Default constructor.
Definition at line 83 of file JsonValue.h.
|
inlinenoexcept |
Creates a null
JSON value.
Definition at line 88 of file JsonValue.h.
|
inlinenoexcept |
Creates a Number
JSON value.
NaN and ±Infinity are represented as JsonValue::Null
.
Definition at line 95 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value (Widening conversion from std::int8_t).
Definition at line 107 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value (Widening conversion from std::uint8_t).
Definition at line 113 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value (Widening conversion from std::int16_t).
Definition at line 119 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value (Widening conversion from std::uint16_t).
Definition at line 125 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value (Widening conversion from std::int32_t).
Definition at line 131 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value (Widening conversion from std::uint32_t).
Definition at line 137 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value.
Definition at line 142 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value.
Definition at line 147 of file JsonValue.h.
|
inlinenoexcept |
Creates a Bool
JSON value.
Definition at line 152 of file JsonValue.h.
|
inline |
Creates a String
JSON value.
Definition at line 157 of file JsonValue.h.
|
inlinenoexcept |
Creates a String
JSON value.
Definition at line 162 of file JsonValue.h.
|
inline |
Creates a String
JSON value.
Definition at line 167 of file JsonValue.h.
|
inline |
Creates an Object
JSON value with the given properties.
Definition at line 172 of file JsonValue.h.
|
inline |
Creates an Object
JSON value with the given properties.
Definition at line 177 of file JsonValue.h.
|
inline |
Creates an Array
JSON value with the given elements.
Definition at line 182 of file JsonValue.h.
|
inlinenoexcept |
Creates an Array
JSON value with the given elements.
Definition at line 187 of file JsonValue.h.
|
inline |
Creates an JSON value from the given initializer list.
Definition at line 192 of file JsonValue.h.
|
inline |
Creates an JSON value from the given initializer list.
Definition at line 198 of file JsonValue.h.
|
inlinenodiscard |
Gets the array from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::Array |
Definition at line 428 of file JsonValue.h.
|
nodiscard |
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. |
|
inlinenodiscard |
Gets the bool from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::Bool |
Definition at line 449 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the bool from the value or returns defaultValue.
Definition at line 486 of file JsonValue.h.
|
inlinenodiscard |
Gets the double from the value.
std::bad_variant_access | if the underlying type is not a double |
Definition at line 458 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the double from the value or returns defaultValue.
Definition at line 514 of file JsonValue.h.
|
inlinenodiscard |
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 478 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the int64_t from the value or returns defaultValue.
Definition at line 542 of file JsonValue.h.
|
inlinenodiscard |
Gets the object from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::Object |
Definition at line 408 of file JsonValue.h.
|
inlinenodiscard |
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.
Definition at line 351 of file JsonValue.h.
|
inlinenodiscardnoexcept |
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 382 of file JsonValue.h.
|
inlinenodiscard |
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, the named value does not have a numerical type, or if the named value cannot be converted from double
/ std::uint64_t
/ std::int64_t
without precision loss, returns std::nullopt
.
To | The expected type of the value. |
key | The key for which to retrieve the value from this object. |
Definition at line 278 of file JsonValue.h.
|
inlinenodiscard |
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. |
defaultValue | The value that will be returned if a numerical value can't be obtained. |
If | unable to convert the converted value for one of the aforementioned reasons. |
Definition at line 311 of file JsonValue.h.
|
inlinenoexcept |
Returns the size in bytes of this JsonValue
.
Definition at line 626 of file JsonValue.h.
|
inlinenodiscard |
Gets the string from the value.
std::bad_variant_access | if the underlying type is not a JsonValue::String |
Definition at line 418 of file JsonValue.h.
|
inlinenodiscard |
Gets the string from the value or returns defaultValue.
Definition at line 500 of file JsonValue.h.
|
inlinenodiscard |
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 468 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the uint64_t from the value or returns defaultValue.
Definition at line 528 of file JsonValue.h.
|
nodiscard |
|
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 252 of file JsonValue.h.
|
nodiscard |
|
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 229 of file JsonValue.h.
|
inlinenodiscard |
Determines if this value is an Object and has the given key.
key | The key. |
Definition at line 329 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is an Array
value.
Definition at line 591 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a Bool
value.
Definition at line 570 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a double
value.
Definition at line 598 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a std::int64_t
value.
Definition at line 612 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a null
value.
Definition at line 554 of file JsonValue.h.
|
inlinenodiscardnoexcept |
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.
Definition at line 563 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is an Object
value.
Definition at line 584 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a String
value.
Definition at line 577 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a std::uint64_t
value.
Definition at line 605 of file JsonValue.h.
|
inlinenoexcept |
Returns true
if two values are equal.
Definition at line 619 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 688 of file JsonValue.h.