Browse Source

Util: Add fromJson() functions for Object Value types

master
Riyyi 2 years ago
parent
commit
003db7332d
  1. 20
      src/util/json/fromjson.h

20
src/util/json/fromjson.h

@ -80,6 +80,26 @@ void fromJson(const Json& json, std::vector<T>& array)
});
}
template<typename Json, typename T>
void fromJson(const Json& json, std::map<std::string, T>& object)
{
assert(json.type() == Json::Type::Object);
object.clear();
for (const auto& [name, value] : json.asObject().members()) {
object.emplace(name, value.template get<T>());
}
}
template<typename Json, typename T>
void fromJson(const Json& json, std::unordered_map<std::string, T>& object)
{
assert(json.type() == Json::Type::Object);
object.clear();
for (const auto& [name, value] : json.asObject().members()) {
object.emplace(name, value.template get<T>());
}
}
struct fromJsonFunction {
template<typename Json, typename T>
auto operator()(const Json& json, T&& value) const

Loading…
Cancel
Save