diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-04-20T14·52+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-04-20T14·52+0200 |
commit | 4410e9d995bcd53a7a4cff0bbee3917375adcba3 (patch) | |
tree | 9798177ab77f4918c15f7f9b4061915e71bb79a6 /src/libutil/config.cc | |
parent | f05d5f89ff4ec52ed2f6d576b2b2323b5292f815 (diff) |
Setting: Remove "Tag" template argument
Diffstat (limited to 'src/libutil/config.cc')
-rw-r--r-- | src/libutil/config.cc | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc index bf137299718f..72b6cf806841 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -111,83 +111,72 @@ AbstractSetting::AbstractSetting( { } -template<> void Setting<std::string>::set(const std::string & str) +template<> void BaseSetting<std::string>::set(const std::string & str) { value = str; } -template<> std::string Setting<std::string>::to_string() +template<> std::string BaseSetting<std::string>::to_string() { return value; } -template<typename T, typename Tag> -void Setting<T, Tag>::set(const std::string & str) +template<typename T> +void BaseSetting<T>::set(const std::string & str) { static_assert(std::is_integral<T>::value, "Integer required."); if (!string2Int(str, value)) throw UsageError("setting '%s' has invalid value '%s'", name, str); } -template<typename T, typename Tag> -std::string Setting<T, Tag>::to_string() +template<typename T> +std::string BaseSetting<T>::to_string() { static_assert(std::is_integral<T>::value, "Integer required."); return std::to_string(value); } -bool AbstractSetting::parseBool(const std::string & str) +template<> void BaseSetting<bool>::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<bool>::set(const std::string & str) +template<> std::string BaseSetting<bool>::to_string() { - value = parseBool(str); + return value ? "true" : "false"; } -std::string AbstractSetting::printBool(bool b) -{ - return b ? "true" : "false"; -} - - -template<> std::string Setting<bool>::to_string() -{ - return printBool(value); -} - -template<> void Setting<Strings>::set(const std::string & str) +template<> void BaseSetting<Strings>::set(const std::string & str) { value = tokenizeString<Strings>(str); } -template<> std::string Setting<Strings>::to_string() +template<> std::string BaseSetting<Strings>::to_string() { return concatStringsSep(" ", value); } -template<> void Setting<StringSet>::set(const std::string & str) +template<> void BaseSetting<StringSet>::set(const std::string & str) { value = tokenizeString<StringSet>(str); } -template<> std::string Setting<StringSet>::to_string() +template<> std::string BaseSetting<StringSet>::to_string() { return concatStringsSep(" ", value); } -template class Setting<int>; -template class Setting<unsigned int>; -template class Setting<long>; -template class Setting<unsigned long>; -template class Setting<long long>; -template class Setting<unsigned long long>; +template class BaseSetting<int>; +template class BaseSetting<unsigned int>; +template class BaseSetting<long>; +template class BaseSetting<unsigned long>; +template class BaseSetting<long long>; +template class BaseSetting<unsigned long long>; void PathSetting::set(const std::string & str) { |