Commit 20b62978 authored by Dominik Charousset's avatar Dominik Charousset

Fix top-level merging for new config syntax

parent 401fc89e
......@@ -209,7 +209,7 @@ private:
config_option_set& options_;
settings& cfg_;
std::string current_key;
std::string current_key_;
std::vector<error> warnings_;
};
......
......@@ -42,7 +42,6 @@ ini_list_consumer abstract_ini_consumer::begin_list() {
return {this};
}
// -- map_consumer -------------------------------------------------------------
ini_map_consumer::ini_map_consumer(abstract_ini_consumer* parent)
......@@ -156,23 +155,28 @@ ini_consumer* ini_category_consumer::dparent() {
ini_consumer::ini_consumer(config_option_set& options, settings& cfg)
: options_(options),
cfg_(cfg),
current_key("global") {
current_key_("global") {
// nop
}
ini_category_consumer ini_consumer::begin_map() {
return {this, current_key};
return {this, current_key_};
}
void ini_consumer::key(std::string name) {
current_key = std::move(name);
current_key_ = std::move(name);
}
void ini_consumer::value_impl(config_value&& x) {
using dict_type = config_value::dictionary;
auto dict = get_if<dict_type>(&x);
if (current_key != "global") {
auto& dst = cfg_.emplace(current_key, dict_type{}).first->second;
if (dict == nullptr) {
warnings_.emplace_back(make_error(pec::type_mismatch,
"expected a dictionary at top level"));
return;
}
if (current_key_ != "global") {
auto& dst = cfg_.emplace(current_key_, dict_type{}).first->second;
if (dict != nullptr && !dict->empty() && holds_alternative<dict_type>(dst)) {
auto& dst_dict = get<dict_type>(dst);
// We need to "merge" values into the destination, because it can already
......@@ -181,8 +185,13 @@ void ini_consumer::value_impl(config_value&& x) {
dst_dict.insert_or_assign(entry.first, std::move(entry.second));
}
} else {
for (auto& entry : *dict)
cfg_.insert_or_assign(entry.first, std::move(entry.second));
std::string prev_key;
swap(current_key_, prev_key);
for (auto& entry : *dict) {
current_key_ = std::move(entry.first);
value_impl(std::move(entry.second));
}
swap(prev_key, current_key_);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment