From ba1bf6959ea3d512bc8fe48f5fede5f752353bcf Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 23 Feb 2025 19:05:56 -0600 Subject: [PATCH] Config: Allow passing a DefaultState object to Set functions to delete keys. --- Source/Core/Common/Config/Config.h | 24 ++++++++++++------------ Source/Core/Common/Config/Layer.h | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 1c91bc65af..d7b370282a 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -100,32 +100,32 @@ LayerType GetActiveLayerForConfig(const Info& info) return GetActiveLayerForConfig(info.GetLocation()); } -template -void Set(LayerType layer, const Info& info, const std::common_type_t& value) +template +void Set(LayerType layer, const InfoT& info, const ValueT& value) { if (GetLayer(layer)->Set(info, value)) OnConfigChanged(); } -template -void SetBase(const Info& info, const std::common_type_t& value) +template +void SetBase(const Info& info, const ValueT& value) { - Set(LayerType::Base, info, value); + Set(LayerType::Base, info, value); } -template -void SetCurrent(const Info& info, const std::common_type_t& value) +template +void SetCurrent(const Info& info, const ValueT& value) { - Set(LayerType::CurrentRun, info, value); + Set(LayerType::CurrentRun, info, value); } -template -void SetBaseOrCurrent(const Info& info, const std::common_type_t& value) +template +void SetBaseOrCurrent(const Info& info, const ValueT& value) { if (GetActiveLayerForConfig(info) == LayerType::Base) - Set(LayerType::Base, info, value); + Set(LayerType::Base, info, value); else - Set(LayerType::CurrentRun, info, value); + Set(LayerType::CurrentRun, info, value); } template diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h index 5e3f61c1e6..58859789ca 100644 --- a/Source/Core/Common/Config/Layer.h +++ b/Source/Core/Common/Config/Layer.h @@ -8,7 +8,6 @@ #include #include #include -#include #include "Common/Config/ConfigInfo.h" #include "Common/Config/Enums.h" @@ -16,6 +15,12 @@ namespace Config { +// Setting a key to an object of this type will delete the key. +struct DefaultState +{ + friend constexpr bool operator==(DefaultState, DefaultState) { return true; }; +}; + namespace detail { template ::value>* = nullptr> @@ -116,12 +121,20 @@ public: return detail::TryParse(*iter->second); } + template + bool Set(const Info& config_info, DefaultState) + { + return DeleteKey(config_info.GetLocation()); + } + template bool Set(const Info& config_info, const std::common_type_t& value) { return Set(config_info.GetLocation(), value); } + bool Set(const Location& location, DefaultState) { return DeleteKey(location); } + template bool Set(const Location& location, const T& value) {