Skip to content

Commit 151e606

Browse files
Made sure that to_map returns a result
1 parent 5fb4d6a commit 151e606

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

include/rfl/flexbuf/Reader.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct Reader {
111111
return _var.AsVector();
112112
}
113113

114-
std::vector<std::pair<std::string, InputVarType>> to_map(
114+
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
115115
const InputObjectType& _obj) const noexcept {
116116
std::vector<std::pair<std::string, InputVarType>> m;
117117

include/rfl/json/Reader.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct Reader {
113113
return f_arr;
114114
}
115115

116-
std::vector<std::pair<std::string, InputVarType>> to_map(
116+
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
117117
const InputObjectType _obj) const noexcept {
118118
std::vector<std::pair<std::string, InputVarType>> m;
119119
yyjson_obj_iter iter;

include/rfl/parsing/FieldVariantParser.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct FieldVariantParser {
4848
return find_matching_alternative(_r, disc_value, var);
4949
};
5050

51-
return _r.to_object(_var).transform(to_map).and_then(to_result);
51+
return _r.to_object(_var).and_then(to_map).and_then(to_result);
5252
}
5353

5454
template <class P>

include/rfl/parsing/IsReader.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ concept IsReader = requires(R r, std::string name,
6161
/// a vector.
6262
{
6363
r.to_map(obj)
64-
} -> std::same_as<
65-
std::vector<std::pair<std::string, typename R::InputVarType>>>;
64+
} -> std::same_as<rfl::Result<
65+
std::vector<std::pair<std::string, typename R::InputVarType>>>>;
6666

6767
/// Casts var as an InputObjectType.
6868
{

include/rfl/parsing/MapParser.hpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,23 @@ struct MapParser {
117117
.value();
118118
}
119119

120-
static Result<MapType> make_map(const R& _r, const auto& _obj) noexcept {
121-
auto m = _r.to_map(_obj);
120+
static Result<MapType> iterate_map(const R& _r, const auto& _map) noexcept {
122121
MapType res;
123122
try {
124-
for (auto& p : m) {
123+
for (auto& p : _map) {
125124
res.insert(get_pair(_r, p));
126125
}
127126
} catch (std::exception& e) {
128127
return Error(e.what());
129128
}
130129
return res;
130+
};
131+
132+
static Result<MapType> make_map(const R& _r, const auto& _obj) noexcept {
133+
const auto iterate = [&](const auto& _map) {
134+
return iterate_map(_r, _map);
135+
};
136+
return _r.to_map(_obj).and_then(iterate);
131137
}
132138
};
133139

include/rfl/xml/Reader.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct Reader {
154154
return f_arr;
155155
}
156156

157-
std::vector<std::pair<std::string, InputVarType>> to_map(
157+
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
158158
const InputObjectType _obj) const noexcept {
159159
std::vector<std::pair<std::string, InputVarType>> m;
160160
for (auto child = _obj.node_.first_child(); child;

include/rfl/yaml/Reader.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct Reader {
104104
return f_arr;
105105
}
106106

107-
std::vector<std::pair<std::string, InputVarType>> to_map(
107+
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
108108
const InputObjectType& _obj) const noexcept {
109109
std::vector<std::pair<std::string, InputVarType>> m;
110110
for (const auto& p : _obj.node_) {

0 commit comments

Comments
 (0)