cesium-native 0.43.0
Loading...
Searching...
No Matches
CesiumUtility::JsonHelpers Class Referencefinal

A collection of helper functions to make reading JSON simpler. More...

#include <CesiumUtility/JsonHelpers.h>

Static Public Member Functions

static std::optional< double > getScalarProperty (const rapidjson::Value &tileJson, const std::string &key)
 Attempts to read the value at key of tileJson as a double, returning std::nullopt if it wasn't found or couldn't be read as a double.
 
static std::optional< glm::dmat4x4 > getTransformProperty (const rapidjson::Value &tileJson, const std::string &key)
 Attempts to read the value at key of tileJson as a glm::dmat4x4, returning std::nullopt if it wasn't found or couldn't be read as a glm::dmat4x4.
 
static std::optional< std::vector< double > > getDoubles (const rapidjson::Value &json, int32_t expectedSize, const std::string &key)
 Obtains an array of numbers from the given JSON.
 
static std::string getStringOrDefault (const rapidjson::Value &json, const std::string &key, const std::string &defaultValue)
 Attempts to obtain a string from the given key on the JSON object, returning a default value if this isn't possible.
 
static std::string getStringOrDefault (const rapidjson::Value &json, const std::string &defaultValue)
 Attempts to read json as a string, returning a default value if this isn't possible.
 
static double getDoubleOrDefault (const rapidjson::Value &json, const std::string &key, double defaultValue)
 Attempts to obtain a double from the given key on the JSON object, returning a default value if this isn't possible.
 
static double getDoubleOrDefault (const rapidjson::Value &json, double defaultValue)
 Attempts to read json as a double, returning a default value if this isn't possible.
 
static uint32_t getUint32OrDefault (const rapidjson::Value &json, const std::string &key, uint32_t defaultValue)
 Attempts to obtain a uint32_t from the given key on the JSON object, returning a default value if this isn't possible.
 
static uint32_t getUint32OrDefault (const rapidjson::Value &json, uint32_t defaultValue)
 Attempts to read json as a uint32_t, returning a default value if this isn't possible.
 
static int32_t getInt32OrDefault (const rapidjson::Value &json, const std::string &key, int32_t defaultValue)
 Attempts to obtain a int32_t from the given key on the JSON object, returning a default value if this isn't possible.
 
static int32_t getInt32OrDefault (const rapidjson::Value &json, int32_t defaultValue)
 Attempts to read json as a int32_t, returning a default value if this isn't possible.
 
static uint64_t getUint64OrDefault (const rapidjson::Value &json, const std::string &key, uint64_t defaultValue)
 Attempts to obtain a uint64_t from the given key on the JSON object, returning a default value if this isn't possible.
 
static uint64_t getUint64OrDefault (const rapidjson::Value &json, uint64_t defaultValue)
 Attempts to read json as a uint64_t, returning a default value if this isn't possible.
 
static int64_t getInt64OrDefault (const rapidjson::Value &json, const std::string &key, int64_t defaultValue)
 Attempts to obtain a int64_t from the given key on the JSON object, returning a default value if this isn't possible.
 
static int64_t getInt64OrDefault (const rapidjson::Value &json, int64_t defaultValue)
 Attempts to read json as a int64_t, returning a default value if this isn't possible.
 
static bool getBoolOrDefault (const rapidjson::Value &json, const std::string &key, bool defaultValue)
 Attempts to obtain a bool from the given key on the JSON object, returning a default value if this isn't possible.
 
static bool getBoolOrDefault (const rapidjson::Value &json, bool defaultValue)
 Attempts to read json as a bool, returning a default value if this isn't possible.
 
static std::vector< std::string > getStrings (const rapidjson::Value &json, const std::string &key)
 Attempts to read an array of strings from the property key of json, returning an empty vector if this isn't possible.
 
static std::vector< int64_t > getInt64s (const rapidjson::Value &json, const std::string &key)
 Attempts to read an int64_t array from the property key of json, returning an empty vector if this isn't possible.
 

Detailed Description

A collection of helper functions to make reading JSON simpler.

Definition at line 15 of file JsonHelpers.h.

Member Function Documentation

◆ getBoolOrDefault() [1/2]

static bool CesiumUtility::JsonHelpers::getBoolOrDefault ( const rapidjson::Value & json,
bool defaultValue )
static

Attempts to read json as a bool, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a bool.
defaultValueThe default value to return if json couldn't be read as a bool.

◆ getBoolOrDefault() [2/2]

static bool CesiumUtility::JsonHelpers::getBoolOrDefault ( const rapidjson::Value & json,
const std::string & key,
bool defaultValue )
static

Attempts to obtain a bool from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the bool.
defaultValueThe default value to return if the bool property key of json couldn't be read.

◆ getDoubleOrDefault() [1/2]

static double CesiumUtility::JsonHelpers::getDoubleOrDefault ( const rapidjson::Value & json,
const std::string & key,
double defaultValue )
static

Attempts to obtain a double from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the double.
defaultValueThe default value to return if the double property key of json couldn't be read.

◆ getDoubleOrDefault() [2/2]

static double CesiumUtility::JsonHelpers::getDoubleOrDefault ( const rapidjson::Value & json,
double defaultValue )
static

Attempts to read json as a double, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a double.
defaultValueThe default value to return if json couldn't be read as a double.

◆ getDoubles()

static std::optional< std::vector< double > > CesiumUtility::JsonHelpers::getDoubles ( const rapidjson::Value & json,
int32_t expectedSize,
const std::string & key )
static

Obtains an array of numbers from the given JSON.

If the property is not found, or is not an array, or does contain elements that are not numbers, then std::nullopt is returned.

If the given expected size is not negative, and the actual size of the array does not match the expected size, then nullopt is returned.

Parameters
jsonThe JSON object.
expectedSizeThe expected size of the array.
keyThe key (property name) of the array.
Returns
The array, or nullopt.

◆ getInt32OrDefault() [1/2]

static int32_t CesiumUtility::JsonHelpers::getInt32OrDefault ( const rapidjson::Value & json,
const std::string & key,
int32_t defaultValue )
static

Attempts to obtain a int32_t from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the int32_t.
defaultValueThe default value to return if the int32_t property key of json couldn't be read.

◆ getInt32OrDefault() [2/2]

static int32_t CesiumUtility::JsonHelpers::getInt32OrDefault ( const rapidjson::Value & json,
int32_t defaultValue )
static

Attempts to read json as a int32_t, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a int32_t.
defaultValueThe default value to return if json couldn't be read as a int32_t.

◆ getInt64OrDefault() [1/2]

static int64_t CesiumUtility::JsonHelpers::getInt64OrDefault ( const rapidjson::Value & json,
const std::string & key,
int64_t defaultValue )
static

Attempts to obtain a int64_t from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the int64_t.
defaultValueThe default value to return if the int64_t property key of json couldn't be read.

◆ getInt64OrDefault() [2/2]

static int64_t CesiumUtility::JsonHelpers::getInt64OrDefault ( const rapidjson::Value & json,
int64_t defaultValue )
static

Attempts to read json as a int64_t, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a int64_t.
defaultValueThe default value to return if json couldn't be read as a int64_t.

◆ getInt64s()

static std::vector< int64_t > CesiumUtility::JsonHelpers::getInt64s ( const rapidjson::Value & json,
const std::string & key )
static

Attempts to read an int64_t array from the property key of json, returning an empty vector if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the int64_t array.

◆ getScalarProperty()

static std::optional< double > CesiumUtility::JsonHelpers::getScalarProperty ( const rapidjson::Value & tileJson,
const std::string & key )
static

Attempts to read the value at key of tileJson as a double, returning std::nullopt if it wasn't found or couldn't be read as a double.

Parameters
tileJsonThe JSON object to obtain the scalar property from.
keyThe key of the scalar property to obtain.

◆ getStringOrDefault() [1/2]

static std::string CesiumUtility::JsonHelpers::getStringOrDefault ( const rapidjson::Value & json,
const std::string & defaultValue )
static

Attempts to read json as a string, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a string.
defaultValueThe default value to return if json couldn't be read as a string.

◆ getStringOrDefault() [2/2]

static std::string CesiumUtility::JsonHelpers::getStringOrDefault ( const rapidjson::Value & json,
const std::string & key,
const std::string & defaultValue )
static

Attempts to obtain a string from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the string.
defaultValueThe default value to return if the string property key of json couldn't be read.

◆ getStrings()

static std::vector< std::string > CesiumUtility::JsonHelpers::getStrings ( const rapidjson::Value & json,
const std::string & key )
static

Attempts to read an array of strings from the property key of json, returning an empty vector if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the string array.

◆ getTransformProperty()

static std::optional< glm::dmat4x4 > CesiumUtility::JsonHelpers::getTransformProperty ( const rapidjson::Value & tileJson,
const std::string & key )
static

Attempts to read the value at key of tileJson as a glm::dmat4x4, returning std::nullopt if it wasn't found or couldn't be read as a glm::dmat4x4.

Parameters
tileJsonThe JSON object to obtain the transform property from.
keyThe key of the transform property.

◆ getUint32OrDefault() [1/2]

static uint32_t CesiumUtility::JsonHelpers::getUint32OrDefault ( const rapidjson::Value & json,
const std::string & key,
uint32_t defaultValue )
static

Attempts to obtain a uint32_t from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the uint32_t.
defaultValueThe default value to return if the uint32_t property key of json couldn't be read.

◆ getUint32OrDefault() [2/2]

static uint32_t CesiumUtility::JsonHelpers::getUint32OrDefault ( const rapidjson::Value & json,
uint32_t defaultValue )
static

Attempts to read json as a uint32_t, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a uint32_t.
defaultValueThe default value to return if json couldn't be read as a uint32_t.

◆ getUint64OrDefault() [1/2]

static uint64_t CesiumUtility::JsonHelpers::getUint64OrDefault ( const rapidjson::Value & json,
const std::string & key,
uint64_t defaultValue )
static

Attempts to obtain a uint64_t from the given key on the JSON object, returning a default value if this isn't possible.

Parameters
jsonThe JSON object.
keyThe key (property name) of the uint64_t.
defaultValueThe default value to return if the uint64_t property key of json couldn't be read.

◆ getUint64OrDefault() [2/2]

static uint64_t CesiumUtility::JsonHelpers::getUint64OrDefault ( const rapidjson::Value & json,
uint64_t defaultValue )
static

Attempts to read json as a uint64_t, returning a default value if this isn't possible.

Parameters
jsonThe JSON value that might be a uint64_t.
defaultValueThe default value to return if json couldn't be read as a uint64_t.

The documentation for this class was generated from the following file: