From 051afd21e730005ea24ce3c8743962beb3085031 Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 28 Dec 2023 23:24:23 -0500 Subject: frontend_common: config: Refactor WriteSetting to stricter types Previously this could cause problems if a version of the template generated for WriteSetting didn't use the type you needed (e.g. floating point values). Now these are all ready without having to be used within frontend_common first. --- src/frontend_common/config.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/frontend_common/config.h') diff --git a/src/frontend_common/config.h b/src/frontend_common/config.h index b3812af17..e73cf6929 100644 --- a/src/frontend_common/config.h +++ b/src/frontend_common/config.h @@ -154,11 +154,20 @@ protected: * @param use_global Specifies if the custom or global config should be in use, for custom * configs */ - template - void WriteSetting(const std::string& key, const Type& value, - const std::optional& default_value = std::nullopt, - const std::optional& use_global = std::nullopt); - void WriteSettingInternal(const std::string& key, const std::string& value); + void WriteBooleanSetting(const std::string& key, const bool& value, + const std::optional& default_value = std::nullopt, + const std::optional& use_global = std::nullopt); + template + std::enable_if_t> WriteIntegerSetting( + const std::string& key, const T& value, + const std::optional& default_value = std::nullopt, + const std::optional& use_global = std::nullopt); + void WriteDoubleSetting(const std::string& key, const double& value, + const std::optional& default_value = std::nullopt, + const std::optional& use_global = std::nullopt); + void WriteStringSetting(const std::string& key, const std::string& value, + const std::optional& default_value = std::nullopt, + const std::optional& use_global = std::nullopt); void ReadCategory(Settings::Category category); void WriteCategory(Settings::Category category); @@ -175,8 +184,10 @@ protected: return value_ ? "true" : "false"; } else if constexpr (std::is_same_v) { return std::to_string(static_cast(value_)); - } else { + } else if constexpr (std::is_same_v) { return std::to_string(static_cast(value_)); + } else { + return std::to_string(value_); } } @@ -197,6 +208,11 @@ protected: const bool global; private: + void WritePreparedSetting(const std::string& key, const std::string& adjusted_value, + const std::optional& adjusted_default_value, + const std::optional& use_global); + void WriteString(const std::string& key, const std::string& value); + inline static std::array special_characters = {'!', '#', '$', '%', '^', '&', '*', '|', ';', '\'', '\"', ',', '<', '.', '>', '?', '`', '~', '='}; -- cgit v1.2.3