summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Config
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-02-23 19:05:56 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2025-03-17 20:46:24 -0500
commitba1bf6959ea3d512bc8fe48f5fede5f752353bcf (patch)
tree992b51500d9deb93ae214df67b9f4b85e6de5c5f /Source/Core/Common/Config
parent137d1375d4bf09f6b136d37596c5539b5b14f883 (diff)
Config: Allow passing a DefaultState object to Set functions to delete keys.
Diffstat (limited to 'Source/Core/Common/Config')
-rw-r--r--Source/Core/Common/Config/Config.h24
-rw-r--r--Source/Core/Common/Config/Layer.h15
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<T>& info)
return GetActiveLayerForConfig(info.GetLocation());
}
-template <typename T>
-void Set(LayerType layer, const Info<T>& info, const std::common_type_t<T>& value)
+template <typename InfoT, typename ValueT>
+void Set(LayerType layer, const InfoT& info, const ValueT& value)
{
if (GetLayer(layer)->Set(info, value))
OnConfigChanged();
}
-template <typename T>
-void SetBase(const Info<T>& info, const std::common_type_t<T>& value)
+template <typename InfoT, typename ValueT>
+void SetBase(const Info<InfoT>& info, const ValueT& value)
{
- Set<T>(LayerType::Base, info, value);
+ Set(LayerType::Base, info, value);
}
-template <typename T>
-void SetCurrent(const Info<T>& info, const std::common_type_t<T>& value)
+template <typename InfoT, typename ValueT>
+void SetCurrent(const Info<InfoT>& info, const ValueT& value)
{
- Set<T>(LayerType::CurrentRun, info, value);
+ Set(LayerType::CurrentRun, info, value);
}
-template <typename T>
-void SetBaseOrCurrent(const Info<T>& info, const std::common_type_t<T>& value)
+template <typename InfoT, typename ValueT>
+void SetBaseOrCurrent(const Info<InfoT>& info, const ValueT& value)
{
if (GetActiveLayerForConfig(info) == LayerType::Base)
- Set<T>(LayerType::Base, info, value);
+ Set(LayerType::Base, info, value);
else
- Set<T>(LayerType::CurrentRun, info, value);
+ Set(LayerType::CurrentRun, info, value);
}
template <typename T>
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 <optional>
#include <string>
#include <type_traits>
-#include <vector>
#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 <typename T, std::enable_if_t<!std::is_enum<T>::value>* = nullptr>
@@ -117,11 +122,19 @@ public:
}
template <typename T>
+ bool Set(const Info<T>& config_info, DefaultState)
+ {
+ return DeleteKey(config_info.GetLocation());
+ }
+
+ template <typename T>
bool Set(const Info<T>& config_info, const std::common_type_t<T>& value)
{
return Set(config_info.GetLocation(), value);
}
+ bool Set(const Location& location, DefaultState) { return DeleteKey(location); }
+
template <typename T>
bool Set(const Location& location, const T& value)
{