From b39c02d1ec8f7a199238f83ca4a9e702adb8a1a8 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 2 Dec 2021 18:13:45 +0100 Subject: [PATCH] added specialisation for get for strings --- src/config_file.cpp | 9 +++++++++ src/config_file.hpp | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/config_file.cpp b/src/config_file.cpp index 7230725..6ce0ee8 100644 --- a/src/config_file.cpp +++ b/src/config_file.cpp @@ -26,3 +26,12 @@ std::string sc::config_file::path_for_file_name(const std::string& file_name) { bool sc::config_file::get(const std::string& key, bool default_value) const { return get(key, default_value ? "yes" : "no") == "yes"; } + +std::string sc::config_file::get(const std::string& key, + const std::string& default_value) const { + auto it = _cfg.find(key); + if (it == _cfg.end()) { + return default_value; + } + return it->second; +} diff --git a/src/config_file.hpp b/src/config_file.hpp index cbd030d..11b341d 100644 --- a/src/config_file.hpp +++ b/src/config_file.hpp @@ -22,6 +22,8 @@ namespace sc { return sc::from_string(it->second); } + std::string get(const std::string& key, + const std::string& default_value) const; bool get(const std::string& key, bool default_value) const; private: