mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-04 01:06:19 +08:00
Made sure that to_map returns a result
This commit is contained in:
@@ -111,7 +111,7 @@ struct Reader {
|
||||
return _var.AsVector();
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, InputVarType>> to_map(
|
||||
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
|
||||
const InputObjectType& _obj) const noexcept {
|
||||
std::vector<std::pair<std::string, InputVarType>> m;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ struct Reader {
|
||||
return f_arr;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, InputVarType>> to_map(
|
||||
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
|
||||
const InputObjectType _obj) const noexcept {
|
||||
std::vector<std::pair<std::string, InputVarType>> m;
|
||||
yyjson_obj_iter iter;
|
||||
|
||||
@@ -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 <class P>
|
||||
|
||||
@@ -61,8 +61,8 @@ concept IsReader = requires(R r, std::string name,
|
||||
/// a vector.
|
||||
{
|
||||
r.to_map(obj)
|
||||
} -> std::same_as<
|
||||
std::vector<std::pair<std::string, typename R::InputVarType>>>;
|
||||
} -> std::same_as<rfl::Result<
|
||||
std::vector<std::pair<std::string, typename R::InputVarType>>>>;
|
||||
|
||||
/// Casts var as an InputObjectType.
|
||||
{
|
||||
|
||||
@@ -117,17 +117,23 @@ struct MapParser {
|
||||
.value();
|
||||
}
|
||||
|
||||
static Result<MapType> make_map(const R& _r, const auto& _obj) noexcept {
|
||||
auto m = _r.to_map(_obj);
|
||||
static Result<MapType> 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<MapType> 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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ struct Reader {
|
||||
return f_arr;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, InputVarType>> to_map(
|
||||
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
|
||||
const InputObjectType _obj) const noexcept {
|
||||
std::vector<std::pair<std::string, InputVarType>> m;
|
||||
for (auto child = _obj.node_.first_child(); child;
|
||||
|
||||
@@ -104,7 +104,7 @@ struct Reader {
|
||||
return f_arr;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, InputVarType>> to_map(
|
||||
rfl::Result<std::vector<std::pair<std::string, InputVarType>>> to_map(
|
||||
const InputObjectType& _obj) const noexcept {
|
||||
std::vector<std::pair<std::string, InputVarType>> m;
|
||||
for (const auto& p : _obj.node_) {
|
||||
|
||||
Reference in New Issue
Block a user