Skip to content

Commit

Permalink
use range for-loop and error check when it is invalid merge key usage
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Ribizel <mail@ribizel.de>
  • Loading branch information
yhmtsai and upsj committed Feb 18, 2025
1 parent 51b251c commit 2af64bd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions include/ginkgo/extensions/config/yaml_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ inline gko::config::pnode parse_yaml(const YAML::Node& input)
auto parse_map = [](const auto& map) {
gko::config::pnode::map_type nodes;
// use [] to get override behavior
for (YAML::const_iterator it = map.begin(); it != map.end(); ++it) {
std::string key = it->first.as<std::string>();
for (const auto& yaml_item : map) {
std::string key = yaml_item.first.template as<std::string>();
// yaml-cpp keeps the alias without resolving it when parsing.
// We resolve them here.
if (key == "<<") {
auto node = parse_yaml(it->second);
auto node = parse_yaml(yaml_item.second);
if (node.get_tag() == gko::config::pnode::tag_t::array) {
for (const auto& arr : node.get_array()) {
if (arr.get_tag() != gko::config::pnode::tag_t::map) {
throw std::runtime_error(
"YAML only accepts merge key << to merge item "
"from map not " +
YAML::Dump(yaml_item.second));
}
for (const auto& item : arr.get_map()) {
nodes[item.first] = item.second;
}
Expand All @@ -52,11 +58,11 @@ inline gko::config::pnode parse_yaml(const YAML::Node& input)
nodes[item.first] = item.second;
}
} else {
std::runtime_error("can not handle this alias: " +
YAML::Dump(it->second));
throw std::runtime_error("can not handle this alias: " +
YAML::Dump(yaml_item.second));
}
} else {
nodes[key] = parse_yaml(it->second);
nodes[key] = parse_yaml(yaml_item.second);
}
}
return gko::config::pnode{nodes};
Expand Down

0 comments on commit 2af64bd

Please sign in to comment.