Jazz2::Utils::JsonAccess namespace

Reads values from JSON that came from outside the game, without trusting their types.

jsoncpp is built without exceptions, so a conversion to a type the value doesn't have — e.g. asInt() on a string — ends the process. Hand-edited settings, rules files next to tile sets and descriptions in level scripts are all read through these, a value of an unexpected type gives the default instead.

Functions

auto Member(const Json::Value& value, const char* key) -> const Json::Value&
Returns a member of an object, or a null value if it's not an object or has no such member.
auto ToInt(const Json::Value& value, std::int32_t defaultValue) -> std::int32_t
Returns an integer value, or the default if it's not a number in range.
auto ToUInt(const Json::Value& value, std::uint32_t defaultValue) -> std::uint32_t
Returns an unsigned integer value, or the default if it's not a number in range.
auto ToFloat(const Json::Value& value, float defaultValue) -> float
Returns a floating-point value, or the default if it's not a finite number.
auto ToBool(const Json::Value& value, bool defaultValue) -> bool
Returns a boolean value, or the default if it's not a boolean.
auto ToString(const Json::Value& value, StringView defaultValue = {}) -> String
Returns a string value, or the default if it's not a string.
auto GetInt(const Json::Value& object, const char* key, std::int32_t defaultValue) -> std::int32_t
Returns an integer member of an object, or the default.
auto GetUInt(const Json::Value& object, const char* key, std::uint32_t defaultValue) -> std::uint32_t
Returns an unsigned integer member of an object, or the default.
auto GetFloat(const Json::Value& object, const char* key, float defaultValue) -> float
Returns a floating-point member of an object, or the default.
auto GetBool(const Json::Value& object, const char* key, bool defaultValue) -> bool
Returns a boolean member of an object, or the default.
auto GetString(const Json::Value& object, const char* key, StringView defaultValue = {}) -> String
Returns a string member of an object, or the default.