diff --git a/common/SettingsInterface.h b/common/SettingsInterface.h index f19b76b822..8ac443bc17 100644 --- a/common/SettingsInterface.h +++ b/common/SettingsInterface.h @@ -17,6 +17,7 @@ #include "Pcsx2Defs.h" #include +#include #include class SettingsInterface @@ -86,4 +87,70 @@ public: value.assign(default_value); return value; } + + __fi std::optional GetOptionalIntValue(const char* section, const char* key, std::optional default_value = std::nullopt) + { + int ret; + return GetIntValue(section, key, &ret) ? std::optional(ret) : default_value; + } + + __fi std::optional GetOptionalUIntValue(const char* section, const char* key, std::optional default_value = std::nullopt) + { + uint ret; + return GetUIntValue(section, key, &ret) ? std::optional(ret) : default_value; + } + + __fi std::optional GetOptionalFloatValue(const char* section, const char* key, std::optional default_value = std::nullopt) + { + float ret; + return GetFloatValue(section, key, &ret) ? std::optional(ret) : default_value; + } + + __fi std::optional GetOptionalDoubleValue(const char* section, const char* key, std::optional default_value = std::nullopt) + { + double ret; + return GetDoubleValue(section, key, &ret) ? std::optional(ret) : default_value; + } + + __fi std::optional GetOptionalBoolValue(const char* section, const char* key, std::optional default_value = std::nullopt) + { + bool ret; + return GetBoolValue(section, key, &ret) ? std::optional(ret) : default_value; + } + + __fi std::optional GetOptionalStringValue(const char* section, const char* key, std::optional default_value = std::nullopt) const + { + std::string ret; + return GetStringValue(section, key, &ret) ? std::optional(ret) : default_value; + } + + __fi void SetOptionalIntValue(const char* section, const char* key, const std::optional& value) + { + value.has_value() ? SetIntValue(section, key, value.value()) : DeleteValue(section, key); + } + + __fi void SetOptionalUIntValue(const char* section, const char* key, const std::optional& value) + { + value.has_value() ? SetUIntValue(section, key, value.value()) : DeleteValue(section, key); + } + + __fi void SetOptionalFloatValue(const char* section, const char* key, const std::optional& value) + { + value.has_value() ? SetFloatValue(section, key, value.value()) : DeleteValue(section, key); + } + + __fi void SetOptionalDoubleValue(const char* section, const char* key, const std::optional& value) + { + value.has_value() ? SetDoubleValue(section, key, value.value()) : DeleteValue(section, key); + } + + __fi void SetOptionalBoolValue(const char* section, const char* key, const std::optional& value) + { + value.has_value() ? SetBoolValue(section, key, value.value()) : DeleteValue(section, key); + } + + __fi void SetOptionalStringValue(const char* section, const char* key, const std::optional& value) + { + value.has_value() ? SetStringValue(section, key, value.value()) : DeleteValue(section, key); + } };