mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Common: add json utility functions 'ReadStringFromJson' and 'ReadBoolFromJson' to match 'ReadNumericFromJson' functionality for other data types, similarly support other data types for 'ToJsonArray'
This commit is contained in:
@ -18,3 +18,23 @@ void FromJson(const picojson::object& obj, Common::Vec3& vec)
|
||||
vec.y = ReadNumericFromJson<float>(obj, "y").value_or(0.0f);
|
||||
vec.z = ReadNumericFromJson<float>(obj, "z").value_or(0.0f);
|
||||
}
|
||||
|
||||
std::optional<std::string> ReadStringFromJson(const picojson::object& obj, const std::string& key)
|
||||
{
|
||||
const auto it = obj.find(key);
|
||||
if (it == obj.end())
|
||||
return std::nullopt;
|
||||
if (!it->second.is<std::string>())
|
||||
return std::nullopt;
|
||||
return it->second.to_str();
|
||||
}
|
||||
|
||||
std::optional<bool> ReadBoolFromJson(const picojson::object& obj, const std::string& key)
|
||||
{
|
||||
const auto it = obj.find(key);
|
||||
if (it == obj.end())
|
||||
return std::nullopt;
|
||||
if (!it->second.is<bool>())
|
||||
return std::nullopt;
|
||||
return it->second.get<bool>();
|
||||
}
|
||||
|
Reference in New Issue
Block a user