diff options
author | Alois Wohlschlager <alois1@gmx-topmail.de> | 2024-08-17 20:55:41 +0200 |
---|---|---|
committer | Alois Wohlschlager <alois1@gmx-topmail.de> | 2024-08-21 17:57:23 +0200 |
commit | e3c289dbe945415367dc1f54f85ad2452f5a97e0 (patch) | |
tree | efb2480cb9e9fc7ffa5a90609033994a541302aa /src/libutil/config.hh | |
parent | e38410799b5b78b2fc2b0c9e4b1dc0dfc5801097 (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.hh')
-rw-r--r-- | src/libutil/config.hh | 69 |
1 files changed, 16 insertions, 53 deletions
diff --git a/src/libutil/config.hh b/src/libutil/config.hh index d1812f47e..dbca4b406 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -353,69 +353,32 @@ public: }; /** - * A special setting for Paths. These are automatically canonicalised - * (e.g. "/foo//bar/" becomes "/foo/bar"). - * - * It is mandatory to specify a path; i.e. the empty string is not - * permitted. + * A special setting for Paths. + * These are automatically canonicalised (e.g. "/foo//bar/" becomes "/foo/bar"). + * The empty string is not permitted when a path is required. */ -class PathSetting : public BaseSetting<Path> -{ -public: - - PathSetting(Config * options, - const Path & def, - const std::string & name, - const std::string & description, - const std::set<std::string> & aliases = {}); - - Path parse(const std::string & str) const override; - - Path operator +(const char * p) const { return value + p; } - - void operator =(const Path & v) { this->assign(v); } -}; - -/** - * Like `PathSetting`, but the absence of a path is also allowed. - * - * `std::optional` is used instead of the empty string for clarity. - */ -class OptionalPathSetting : public BaseSetting<std::optional<Path>> -{ -public: - - OptionalPathSetting(Config * options, - const std::optional<Path> & def, - const std::string & name, - const std::string & description, - const std::set<std::string> & aliases = {}); - - std::optional<Path> parse(const std::string & str) const override; - - void operator =(const std::optional<Path> & v); -}; - -/** - * Like `OptionalPathSetting`, but allows multiple paths. - */ -class PathsSetting : public BaseSetting<Paths> +template<typename T> +class PathsSetting : public BaseSetting<T> { public: - PathsSetting(Config * options, - const Paths & def, + const T & def, const std::string & name, const std::string & description, - const std::set<std::string> & aliases = {}); - - Paths parse(const std::string & str) const override; + const std::set<std::string> & aliases = {}, + const bool documentDefault = true, + std::optional<ExperimentalFeature> experimentalFeature = std::nullopt) + : BaseSetting<T>(def, documentDefault, name, description, aliases, std::move(experimentalFeature)) + { + options->addSetting(this); + } - void operator =(const Paths & v); + T parse(const std::string & str) const override; - operator bool() const noexcept; + void operator =(const T & v) { this->assign(v); } }; + struct GlobalConfig : public AbstractConfig { typedef std::vector<Config*> ConfigRegistrations; |