aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/config.cc
diff options
context:
space:
mode:
authorAlois Wohlschlager <alois1@gmx-topmail.de>2024-08-17 20:55:41 +0200
committerAlois Wohlschlager <alois1@gmx-topmail.de>2024-08-21 17:57:23 +0200
commite3c289dbe945415367dc1f54f85ad2452f5a97e0 (patch)
treeefb2480cb9e9fc7ffa5a90609033994a541302aa /src/libutil/config.cc
parente38410799b5b78b2fc2b0c9e4b1dc0dfc5801097 (diff)
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
Diffstat (limited to 'src/libutil/config.cc')
-rw-r--r--src/libutil/config.cc52
1 files changed, 7 insertions, 45 deletions
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<std::string> & aliases)
- : BaseSetting<Path>(def, true, name, description, aliases)
-{
- options->addSetting(this);
-}
-
-Path PathSetting::parse(const std::string & str) const
+template<> Path PathsSetting<Path>::parse(const std::string & str) const
{
return parsePath(*this, str);
}
-
-OptionalPathSetting::OptionalPathSetting(Config * options,
- const std::optional<Path> & def,
- const std::string & name,
- const std::string & description,
- const std::set<std::string> & aliases)
- : BaseSetting<std::optional<Path>>(def, true, name, description, aliases)
-{
- options->addSetting(this);
-}
-
-
-std::optional<Path> OptionalPathSetting::parse(const std::string & str) const
+template<> std::optional<Path> PathsSetting<std::optional<Path>>::parse(const std::string & str) const
{
if (str == "")
return std::nullopt;
@@ -469,23 +447,7 @@ std::optional<Path> OptionalPathSetting::parse(const std::string & str) const
return parsePath(*this, str);
}
-void OptionalPathSetting::operator =(const std::optional<Path> & v)
-{
- this->assign(v);
-}
-
-PathsSetting::PathsSetting(Config * options,
- const Paths & def,
- const std::string & name,
- const std::string & description,
- const std::set<std::string> & aliases)
- : BaseSetting<Paths>(def, true, name, description, aliases)
-{
- options->addSetting(this);
-}
-
-
-Paths PathsSetting::parse(const std::string & str) const
+template<> Paths PathsSetting<Paths>::parse(const std::string & str) const
{
auto strings = tokenizeString<Strings>(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<Path>;
+template class PathsSetting<std::optional<Path>>;
+template class PathsSetting<Paths>;
+
bool GlobalConfig::set(const std::string & name, const std::string & value)
{