From 4410e9d995bcd53a7a4cff0bbee3917375adcba3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 20 Apr 2017 16:52:53 +0200 Subject: Setting: Remove "Tag" template argument --- src/libutil/config.cc | 53 ++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index bf13729971..72b6cf8068 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -111,83 +111,72 @@ AbstractSetting::AbstractSetting( { } -template<> void Setting::set(const std::string & str) +template<> void BaseSetting::set(const std::string & str) { value = str; } -template<> std::string Setting::to_string() +template<> std::string BaseSetting::to_string() { return value; } -template -void Setting::set(const std::string & str) +template +void BaseSetting::set(const std::string & str) { static_assert(std::is_integral::value, "Integer required."); if (!string2Int(str, value)) throw UsageError("setting '%s' has invalid value '%s'", name, str); } -template -std::string Setting::to_string() +template +std::string BaseSetting::to_string() { static_assert(std::is_integral::value, "Integer required."); return std::to_string(value); } -bool AbstractSetting::parseBool(const std::string & str) +template<> void BaseSetting::set(const std::string & str) { if (str == "true" || str == "yes" || str == "1") - return true; + value = true; else if (str == "false" || str == "no" || str == "0") - return false; + value = false; else throw UsageError("Boolean setting '%s' has invalid value '%s'", name, str); } -template<> void Setting::set(const std::string & str) +template<> std::string BaseSetting::to_string() { - value = parseBool(str); + return value ? "true" : "false"; } -std::string AbstractSetting::printBool(bool b) -{ - return b ? "true" : "false"; -} - - -template<> std::string Setting::to_string() -{ - return printBool(value); -} - -template<> void Setting::set(const std::string & str) +template<> void BaseSetting::set(const std::string & str) { value = tokenizeString(str); } -template<> std::string Setting::to_string() +template<> std::string BaseSetting::to_string() { return concatStringsSep(" ", value); } -template<> void Setting::set(const std::string & str) +template<> void BaseSetting::set(const std::string & str) { value = tokenizeString(str); } -template<> std::string Setting::to_string() +template<> std::string BaseSetting::to_string() { return concatStringsSep(" ", value); } -template class Setting; -template class Setting; -template class Setting; -template class Setting; -template class Setting; -template class Setting; +template class BaseSetting; +template class BaseSetting; +template class BaseSetting; +template class BaseSetting; +template class BaseSetting; +template class BaseSetting; void PathSetting::set(const std::string & str) { -- cgit 1.4.1