1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00

fix(config): Use std::map to store sections #412

This commit is contained in:
Michael Carlberg 2017-02-07 14:55:26 +01:00
parent 1f31870d43
commit 1d06df25a9
2 changed files with 4 additions and 7 deletions

View file

@ -21,7 +21,7 @@ DEFINE_ERROR(key_error);
class config { class config {
public: public:
using valuemap_t = std::unordered_map<string, string>; using valuemap_t = std::unordered_map<string, string>;
using sectionmap_t = std::unordered_map<string, valuemap_t>; using sectionmap_t = std::map<string, valuemap_t>;
using make_type = const config&; using make_type = const config&;
static make_type make(string path = "", string bar = ""); static make_type make(string path = "", string bar = "");
@ -351,7 +351,6 @@ class config {
} }
private: private:
static constexpr const char* KEY_INHERIT{"inherit"};
const logger& m_log; const logger& m_log;
string m_file; string m_file;
string m_barname; string m_barname;

View file

@ -182,18 +182,17 @@ void config::parse_file() {
void config::copy_inherited() { void config::copy_inherited() {
for (auto&& section : m_sections) { for (auto&& section : m_sections) {
for (auto&& param : section.second) { 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 // Get name of base section
auto inherit = param.second; auto inherit = param.second;
if ((inherit = dereference<string>(section.first, param.first, inherit, inherit)).empty()) { if ((inherit = dereference<string>(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 // Find and validate base section
auto base_section = m_sections.find(inherit); auto base_section = m_sections.find(inherit);
if (base_section == m_sections.end()) { if (base_section == m_sections.end()) {
throw value_error( throw value_error("Invalid section \"" + inherit + "\" defined for \"" + section.first + ".inherit\"");
"Invalid section \"" + inherit + "\" defined for \"" + section.first + "." + KEY_INHERIT + "\"");
} }
m_log.trace("config: Copying missing params (sub=\"%s\", base=\"%s\")", 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 // Iterate the base and copy the parameters
// that hasn't been defined for the sub-section // that hasn't been defined for the sub-section
for (auto&& base_param : base_section->second) { for (auto&& base_param : base_section->second) {
valuemap_t::const_iterator iter;
section.second.insert(make_pair(base_param.first, base_param.second)); section.second.insert(make_pair(base_param.first, base_param.second));
} }
} }