libutil/config: support optional<uint32_t>

This is going to be used in the extra-local-job future setting.

Change-Id: Ied76f32b8fa97cb71691d76167103001aa14fa01
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2026-03-02 20:20:06 +01:00
parent ac6c9a9c0a
commit bd108b7e61
2 changed files with 20 additions and 0 deletions
+1
View File
@@ -127,6 +127,7 @@ void BaseSetting<T>::convertToArg(Args & args, const std::string & category)
DECLARE_CONFIG_SERIALISER(std::string)
DECLARE_CONFIG_SERIALISER(std::optional<std::string>)
DECLARE_CONFIG_SERIALISER(std::optional<uint16_t>)
DECLARE_CONFIG_SERIALISER(std::optional<uint32_t>)
DECLARE_CONFIG_SERIALISER(bool)
DECLARE_CONFIG_SERIALISER(Strings)
DECLARE_CONFIG_SERIALISER(StringSet)
+19
View File
@@ -181,11 +181,30 @@ template<> std::optional<uint16_t> BaseSetting<std::optional<uint16_t>>::parse(c
throw UsageError("setting '%s' has invalid value '%s'", name, str);
}
template<>
std::optional<uint32_t>
BaseSetting<std::optional<uint32_t>>::parse(const std::string & str, const ApplyConfigOptions & options) const
{
if (str == "") {
return std::nullopt;
} else if (auto n = string2Int<uint32_t>(str)) {
return n;
} else {
throw UsageError("setting '%s' has invalid value '%s'", name, str);
}
}
template<> std::string BaseSetting<std::optional<uint16_t>>::to_string() const
{
return value ? std::to_string(*value) : "";
}
template<>
std::string BaseSetting<std::optional<uint32_t>>::to_string() const
{
return value ? std::to_string(*value) : "";
}
template<> bool BaseSetting<bool>::parse(const std::string & str, const ApplyConfigOptions & options) const
{
if (str == "true" || str == "yes" || str == "1")