summaryrefslogtreecommitdiff
path: root/src/common/settings_setting.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/settings_setting.h')
-rw-r--r--src/common/settings_setting.h43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h
index a8beb06e9..7be6f26f7 100644
--- a/src/common/settings_setting.h
+++ b/src/common/settings_setting.h
@@ -10,6 +10,7 @@
#include <string>
#include <typeindex>
#include <typeinfo>
+#include <fmt/core.h>
#include "common/common_types.h"
#include "common/settings_common.h"
#include "common/settings_enums.h"
@@ -115,8 +116,12 @@ protected:
} else if constexpr (std::is_same_v<Type, AudioEngine>) {
// Compatibility with old AudioEngine setting being a string
return CanonicalizeEnum(value_);
+ } else if constexpr (std::is_floating_point_v<Type>) {
+ return fmt::format("{:f}", value_);
+ } else if constexpr (std::is_enum_v<Type>) {
+ return std::to_string(static_cast<u32>(value_));
} else {
- return std::to_string(static_cast<u64>(value_));
+ return std::to_string(value_);
}
}
@@ -180,17 +185,19 @@ public:
this->SetValue(static_cast<u32>(std::stoul(input)));
} else if constexpr (std::is_same_v<Type, bool>) {
this->SetValue(input == "true");
- } else if constexpr (std::is_same_v<Type, AudioEngine>) {
- this->SetValue(ToEnum<Type>(input));
+ } else if constexpr (std::is_same_v<Type, float>) {
+ this->SetValue(std::stof(input));
} else {
this->SetValue(static_cast<Type>(std::stoll(input)));
}
} catch (std::invalid_argument&) {
this->SetValue(this->GetDefault());
+ } catch (std::out_of_range&) {
+ this->SetValue(this->GetDefault());
}
}
- [[nodiscard]] std::string constexpr Canonicalize() const override final {
+ [[nodiscard]] std::string Canonicalize() const override final {
if constexpr (std::is_enum_v<Type>) {
return CanonicalizeEnum(this->GetValue());
} else {
@@ -215,11 +222,27 @@ public:
}
}
+ [[nodiscard]] constexpr bool IsFloatingPoint() const final {
+ return std::is_floating_point_v<Type>;
+ }
+
+ [[nodiscard]] constexpr bool IsIntegral() const final {
+ return std::is_integral_v<Type>;
+ }
+
[[nodiscard]] std::string MinVal() const override final {
- return this->ToString(minimum);
+ if constexpr (std::is_arithmetic_v<Type> && !ranged) {
+ return this->ToString(std::numeric_limits<Type>::min());
+ } else {
+ return this->ToString(minimum);
+ }
}
[[nodiscard]] std::string MaxVal() const override final {
- return this->ToString(maximum);
+ if constexpr (std::is_arithmetic_v<Type> && !ranged) {
+ return this->ToString(std::numeric_limits<Type>::max());
+ } else {
+ return this->ToString(maximum);
+ }
}
[[nodiscard]] constexpr bool Ranged() const override {
@@ -256,11 +279,11 @@ public:
* @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded
* @param other_setting_ A second Setting to associate to this one in metadata
*/
+ template <typename T = BasicSetting>
explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name,
Category category_, u32 specialization_ = Specialization::Default,
bool save_ = true, bool runtime_modifiable_ = false,
- BasicSetting* other_setting_ = nullptr)
- requires(!ranged)
+ typename std::enable_if<!ranged, T*>::type other_setting_ = nullptr)
: Setting<Type, false>{
linkage, default_val, name, category_, specialization_,
save_, runtime_modifiable_, other_setting_} {
@@ -282,12 +305,12 @@ public:
* @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded
* @param other_setting_ A second Setting to associate to this one in metadata
*/
+ template <typename T = BasicSetting>
explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val,
const Type& max_val, const std::string& name, Category category_,
u32 specialization_ = Specialization::Default, bool save_ = true,
bool runtime_modifiable_ = false,
- BasicSetting* other_setting_ = nullptr)
- requires(ranged)
+ typename std::enable_if<ranged, T*>::type other_setting_ = nullptr)
: Setting<Type, true>{linkage, default_val, min_val,
max_val, name, category_,
specialization_, save_, runtime_modifiable_,