From 1d06df25a90814a1fb208f5cd283fcb68c9da8df Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 7 Feb 2017 14:55:26 +0100 Subject: [PATCH] fix(config): Use std::map to store sections #412 --- include/components/config.hpp | 3 +-- src/components/config.cpp | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/components/config.hpp b/include/components/config.hpp index 286e060c..fdda44c1 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -21,7 +21,7 @@ DEFINE_ERROR(key_error); class config { public: using valuemap_t = std::unordered_map; - using sectionmap_t = std::unordered_map; + using sectionmap_t = std::map; using make_type = const config&; static make_type make(string path = "", string bar = ""); @@ -351,7 +351,6 @@ class config { } private: - static constexpr const char* KEY_INHERIT{"inherit"}; const logger& m_log; string m_file; string m_barname; diff --git a/src/components/config.cpp b/src/components/config.cpp index 83a942bd..f913d7ae 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -182,18 +182,17 @@ void config::parse_file() { void config::copy_inherited() { for (auto&& section : m_sections) { for (auto&& param : section.second) { - if (param.first.compare(0, strlen(KEY_INHERIT), KEY_INHERIT) == 0) { + if (param.first.find("inherit") == 0) { // Get name of base section auto inherit = param.second; if ((inherit = dereference(section.first, param.first, inherit, inherit)).empty()) { - throw value_error("Invalid section \"\" defined for \"" + section.first + "." + KEY_INHERIT + "\""); + throw value_error("Invalid section \"\" defined for \"" + section.first + ".inherit\""); } // Find and validate base section auto base_section = m_sections.find(inherit); if (base_section == m_sections.end()) { - throw value_error( - "Invalid section \"" + inherit + "\" defined for \"" + section.first + "." + KEY_INHERIT + "\""); + throw value_error("Invalid section \"" + inherit + "\" defined for \"" + section.first + ".inherit\""); } m_log.trace("config: Copying missing params (sub=\"%s\", base=\"%s\")", section.first, inherit); @@ -201,7 +200,6 @@ void config::copy_inherited() { // Iterate the base and copy the parameters // that hasn't been defined for the sub-section for (auto&& base_param : base_section->second) { - valuemap_t::const_iterator iter; section.second.insert(make_pair(base_param.first, base_param.second)); } }