From 151e606264af61c3ab012eb6653e0d349e325ebf Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Wed, 17 Jan 2024 05:31:23 +0100 Subject: [PATCH] Made sure that to_map returns a result --- include/rfl/flexbuf/Reader.hpp | 2 +- include/rfl/json/Reader.hpp | 2 +- include/rfl/parsing/FieldVariantParser.hpp | 2 +- include/rfl/parsing/IsReader.hpp | 4 ++-- include/rfl/parsing/MapParser.hpp | 12 +++++++++--- include/rfl/xml/Reader.hpp | 2 +- include/rfl/yaml/Reader.hpp | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/rfl/flexbuf/Reader.hpp b/include/rfl/flexbuf/Reader.hpp index f5a5b496..5c045fc2 100644 --- a/include/rfl/flexbuf/Reader.hpp +++ b/include/rfl/flexbuf/Reader.hpp @@ -111,7 +111,7 @@ struct Reader { return _var.AsVector(); } - std::vector> to_map( + rfl::Result>> to_map( const InputObjectType& _obj) const noexcept { std::vector> m; diff --git a/include/rfl/json/Reader.hpp b/include/rfl/json/Reader.hpp index bd80fc05..0118e700 100644 --- a/include/rfl/json/Reader.hpp +++ b/include/rfl/json/Reader.hpp @@ -113,7 +113,7 @@ struct Reader { return f_arr; } - std::vector> to_map( + rfl::Result>> to_map( const InputObjectType _obj) const noexcept { std::vector> m; yyjson_obj_iter iter; diff --git a/include/rfl/parsing/FieldVariantParser.hpp b/include/rfl/parsing/FieldVariantParser.hpp index 749f3f23..fa8b2dc2 100644 --- a/include/rfl/parsing/FieldVariantParser.hpp +++ b/include/rfl/parsing/FieldVariantParser.hpp @@ -48,7 +48,7 @@ struct FieldVariantParser { return find_matching_alternative(_r, disc_value, var); }; - return _r.to_object(_var).transform(to_map).and_then(to_result); + return _r.to_object(_var).and_then(to_map).and_then(to_result); } template diff --git a/include/rfl/parsing/IsReader.hpp b/include/rfl/parsing/IsReader.hpp index 383aff8d..5931134b 100644 --- a/include/rfl/parsing/IsReader.hpp +++ b/include/rfl/parsing/IsReader.hpp @@ -61,8 +61,8 @@ concept IsReader = requires(R r, std::string name, /// a vector. { r.to_map(obj) - } -> std::same_as< - std::vector>>; + } -> std::same_as>>>; /// Casts var as an InputObjectType. { diff --git a/include/rfl/parsing/MapParser.hpp b/include/rfl/parsing/MapParser.hpp index 368709dd..6361fd47 100644 --- a/include/rfl/parsing/MapParser.hpp +++ b/include/rfl/parsing/MapParser.hpp @@ -117,17 +117,23 @@ struct MapParser { .value(); } - static Result make_map(const R& _r, const auto& _obj) noexcept { - auto m = _r.to_map(_obj); + static Result iterate_map(const R& _r, const auto& _map) noexcept { MapType res; try { - for (auto& p : m) { + for (auto& p : _map) { res.insert(get_pair(_r, p)); } } catch (std::exception& e) { return Error(e.what()); } return res; + }; + + static Result make_map(const R& _r, const auto& _obj) noexcept { + const auto iterate = [&](const auto& _map) { + return iterate_map(_r, _map); + }; + return _r.to_map(_obj).and_then(iterate); } }; diff --git a/include/rfl/xml/Reader.hpp b/include/rfl/xml/Reader.hpp index 25fde797..2ffb2998 100644 --- a/include/rfl/xml/Reader.hpp +++ b/include/rfl/xml/Reader.hpp @@ -154,7 +154,7 @@ struct Reader { return f_arr; } - std::vector> to_map( + rfl::Result>> to_map( const InputObjectType _obj) const noexcept { std::vector> m; for (auto child = _obj.node_.first_child(); child; diff --git a/include/rfl/yaml/Reader.hpp b/include/rfl/yaml/Reader.hpp index 91fcac84..e1b6b6b2 100644 --- a/include/rfl/yaml/Reader.hpp +++ b/include/rfl/yaml/Reader.hpp @@ -104,7 +104,7 @@ struct Reader { return f_arr; } - std::vector> to_map( + rfl::Result>> to_map( const InputObjectType& _obj) const noexcept { std::vector> m; for (const auto& p : _obj.node_) {