cesium-native 0.43.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. | |
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 75 of file JsonValue.h.
using CesiumUtility::JsonValue::Array = std::vector<JsonValue> |
The type to represent an Array
JSON value.
Definition at line 100 of file JsonValue.h.
using CesiumUtility::JsonValue::Bool = bool |
The type to represent a Bool
JSON value.
Definition at line 85 of file JsonValue.h.
using CesiumUtility::JsonValue::Null = std::nullptr_t |
The type to represent a null
JSON value.
Definition at line 80 of file JsonValue.h.
using CesiumUtility::JsonValue::Object = std::map<std::string, JsonValue> |
The type to represent an Object
JSON value.
Definition at line 95 of file JsonValue.h.
using CesiumUtility::JsonValue::String = std::string |
The type to represent a String
JSON value.
Definition at line 90 of file JsonValue.h.
|
inlinenoexcept |
Default constructor.
Definition at line 105 of file JsonValue.h.
|
inlinenoexcept |
Creates a null
JSON value.
Definition at line 110 of file JsonValue.h.
|
inlinenoexcept |
Creates a Number
JSON value.
NaN and ±Infinity are represented as JsonValue::Null
.
Definition at line 117 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value (Widening conversion from std::int8_t).
Definition at line 129 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value (Widening conversion from std::uint8_t).
Definition at line 135 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value (Widening conversion from std::int16_t).
Definition at line 141 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value (Widening conversion from std::uint16_t).
Definition at line 147 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value (Widening conversion from std::int32_t).
Definition at line 153 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value (Widening conversion from std::uint32_t).
Definition at line 159 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::int64_t
JSON value.
Definition at line 164 of file JsonValue.h.
|
inlinenoexcept |
Creates a std::uint64_t
JSON value.
Definition at line 169 of file JsonValue.h.
|
inlinenoexcept |
Creates a Bool
JSON value.
Definition at line 174 of file JsonValue.h.
|
inline |
Creates a String
JSON value.
Definition at line 179 of file JsonValue.h.
|
inlinenoexcept |
Creates a String
JSON value.
Definition at line 184 of file JsonValue.h.
|
inline |
Creates a String
JSON value.
Definition at line 189 of file JsonValue.h.
|
inline |
Creates an Object
JSON value with the given properties.
Definition at line 194 of file JsonValue.h.
|
inline |
Creates an Object
JSON value with the given properties.
Definition at line 199 of file JsonValue.h.
|
inline |
Creates an Array
JSON value with the given elements.
Definition at line 204 of file JsonValue.h.
|
inlinenoexcept |
Creates an Array
JSON value with the given elements.
Definition at line 209 of file JsonValue.h.
|
inline |
Creates an JSON value from the given initializer list.
Definition at line 214 of file JsonValue.h.
|
inline |
Creates an JSON value from the given initializer list.
Definition at line 220 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 450 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 471 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the bool from the value or returns defaultValue.
Definition at line 508 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 480 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the double from the value or returns defaultValue.
Definition at line 536 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 500 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the int64_t from the value or returns defaultValue.
Definition at line 564 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 430 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 373 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 404 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 300 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 333 of file JsonValue.h.
|
inlinenoexcept |
Returns the size in bytes of this JsonValue
.
Definition at line 648 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 440 of file JsonValue.h.
|
inlinenodiscard |
Gets the string from the value or returns defaultValue.
Definition at line 522 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 490 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Gets the uint64_t from the value or returns defaultValue.
Definition at line 550 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 274 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 251 of file JsonValue.h.
|
inlinenodiscard |
Determines if this value is an Object and has the given key.
key | The key. |
Definition at line 351 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is an Array
value.
Definition at line 613 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a Bool
value.
Definition at line 592 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a double
value.
Definition at line 620 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a std::int64_t
value.
Definition at line 634 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a null
value.
Definition at line 576 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 585 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is an Object
value.
Definition at line 606 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a String
value.
Definition at line 599 of file JsonValue.h.
|
inlinenodiscardnoexcept |
Returns whether this value is a std::uint64_t
value.
Definition at line 627 of file JsonValue.h.
|
inlinenoexcept |
Returns true
if two values are equal.
Definition at line 641 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 710 of file JsonValue.h.