From 003db7332d9fded2203c49d17534d37c23e3754e Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 10 Jul 2022 00:56:39 +0200 Subject: [PATCH] Util: Add fromJson() functions for Object Value types --- src/util/json/fromjson.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/json/fromjson.h b/src/util/json/fromjson.h index 410d094..1729bd1 100644 --- a/src/util/json/fromjson.h +++ b/src/util/json/fromjson.h @@ -80,6 +80,26 @@ void fromJson(const Json& json, std::vector& array) }); } +template +void fromJson(const Json& json, std::map& object) +{ + assert(json.type() == Json::Type::Object); + object.clear(); + for (const auto& [name, value] : json.asObject().members()) { + object.emplace(name, value.template get()); + } +} + +template +void fromJson(const Json& json, std::unordered_map& object) +{ + assert(json.type() == Json::Type::Object); + object.clear(); + for (const auto& [name, value] : json.asObject().members()) { + object.emplace(name, value.template get()); + } +} + struct fromJsonFunction { template auto operator()(const Json& json, T&& value) const