From e3c289dbe945415367dc1f54f85ad2452f5a97e0 Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sat, 17 Aug 2024 20:55:41 +0200 Subject: libutil/config: unify path setting types There have been multiple setting types for paths that are supposed to be canonicalised, depending on whether zero or one, one, or any number of paths is to be specified. Naturally, they behaved in slightly different ways in the code. Simplify things by unifying them and removing special behaviour (mainly the "multiple paths type can coerce to boolean" thing). Change-Id: I7c1ce95e9c8e1829a866fb37d679e167811e9705 --- src/libutil/config.cc | 52 +++++++-------------------------------------------- 1 file changed, 7 insertions(+), 45 deletions(-) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 3c4f4798b..8e20f1321 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -434,34 +434,12 @@ static Path parsePath(const AbstractSetting & s, const std::string & str) return canonPath(str); } -PathSetting::PathSetting(Config * options, - const Path & def, - const std::string & name, - const std::string & description, - const std::set & aliases) - : BaseSetting(def, true, name, description, aliases) -{ - options->addSetting(this); -} - -Path PathSetting::parse(const std::string & str) const +template<> Path PathsSetting::parse(const std::string & str) const { return parsePath(*this, str); } - -OptionalPathSetting::OptionalPathSetting(Config * options, - const std::optional & def, - const std::string & name, - const std::string & description, - const std::set & aliases) - : BaseSetting>(def, true, name, description, aliases) -{ - options->addSetting(this); -} - - -std::optional OptionalPathSetting::parse(const std::string & str) const +template<> std::optional PathsSetting>::parse(const std::string & str) const { if (str == "") return std::nullopt; @@ -469,23 +447,7 @@ std::optional OptionalPathSetting::parse(const std::string & str) const return parsePath(*this, str); } -void OptionalPathSetting::operator =(const std::optional & v) -{ - this->assign(v); -} - -PathsSetting::PathsSetting(Config * options, - const Paths & def, - const std::string & name, - const std::string & description, - const std::set & aliases) - : BaseSetting(def, true, name, description, aliases) -{ - options->addSetting(this); -} - - -Paths PathsSetting::parse(const std::string & str) const +template<> Paths PathsSetting::parse(const std::string & str) const { auto strings = tokenizeString(str); Paths parsed; @@ -497,10 +459,10 @@ Paths PathsSetting::parse(const std::string & str) const return parsed; } -PathsSetting::operator bool() const noexcept -{ - return !get().empty(); -} +template class PathsSetting; +template class PathsSetting>; +template class PathsSetting; + bool GlobalConfig::set(const std::string & name, const std::string & value) { -- cgit v1.2.3