fix(config): Use KEY_INHERIT

This commit is contained in:
Michael Carlberg 2016-12-01 08:23:39 +01:00
parent 0c6937edae
commit 121d367205

View File

@ -55,21 +55,19 @@ void config::copy_inherited() {
for (auto&& section : m_ptree) { for (auto&& section : m_ptree) {
for (auto&& param : section.second) { for (auto&& param : section.second) {
if (param.first.compare(KEY_INHERIT) == 0) { if (param.first.compare(KEY_INHERIT) == 0) {
// Find and validate parent section // Get name of base section
auto inherit_section = param.second.get_value<string>(); auto inherit = param.second.get_value<string>();
if ((inherit = dereference<string>(section.first, param.first, inherit, inherit)).empty()) {
// Dereference value throw value_error("[" + section.first + "." + KEY_INHERIT + "] requires a value");
inherit_section = dereference<string>(section.first, param.first, inherit_section, inherit_section);
if (inherit_section.empty()) {
throw value_error("[" + section.first + ".inherit] requires a value");
} }
auto base_section = m_ptree.get_child_optional(inherit_section);
// Find and validate base section
auto base_section = m_ptree.get_child_optional(inherit);
if (!base_section || base_section.value().empty()) { if (!base_section || base_section.value().empty()) {
throw value_error("[" + section.first + ".inherit] points to an invalid section \"" + inherit_section + "\""); throw value_error("[" + section.first + "." + KEY_INHERIT + "] invalid reference \"" + inherit + "\"");
} }
m_logger.trace("config: Copying missing params (sub=\"%s\", base=\"%s\")", section.first, inherit_section); m_logger.trace("config: Copying missing params (sub=\"%s\", base=\"%s\")", section.first, inherit);
// Iterate the the base and copy the parameters // Iterate the the base and copy the parameters
// that hasn't been defined for the sub-section // that hasn't been defined for the sub-section