From 7c77b590cb01dd03cc44473c77697432cf07703a Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 7 Jul 2021 16:28:02 +0200 Subject: [PATCH] Fixed specialisation for getting a bool value --- src/config_file.cpp | 4 ++++ src/config_file.hpp | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/config_file.cpp b/src/config_file.cpp index 7d44c50..d9261fb 100644 --- a/src/config_file.cpp +++ b/src/config_file.cpp @@ -20,3 +20,7 @@ sc::config_file::config_file(const std::string& prog_name, bool has_dir) std::string sc::config_file::path_for_file_name(const std::string& file_name) { return _root + file_name; } + +bool sc::config_file::get(const std::string& key, bool default_value) const { + return get(key, default_value ? "yes" : "no") == "yes"; +} diff --git a/src/config_file.hpp b/src/config_file.hpp index 5e2d9b3..cbd030d 100644 --- a/src/config_file.hpp +++ b/src/config_file.hpp @@ -14,7 +14,7 @@ namespace sc { std::string path_for_file_name(const std::string& file_name); template - T get(const std::string& key, const T& default_value) { + T get(const std::string& key, const T& default_value) const { auto it = _cfg.find(key); if (it == _cfg.end()) { return default_value; @@ -22,10 +22,7 @@ namespace sc { return sc::from_string(it->second); } - bool get(const std::string& key, bool default_value) { - std::string val {get(key, default_value ? "yes" : "no")}; - return val == "yes"; - } + bool get(const std::string& key, bool default_value) const; private: bool _has_dir {false};