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.h33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h
index e10843c73..3175ab07d 100644
--- a/src/common/settings_setting.h
+++ b/src/common/settings_setting.h
@@ -10,6 +10,7 @@
10#include <string> 10#include <string>
11#include <typeindex> 11#include <typeindex>
12#include <typeinfo> 12#include <typeinfo>
13#include <fmt/core.h>
13#include "common/common_types.h" 14#include "common/common_types.h"
14#include "common/settings_common.h" 15#include "common/settings_common.h"
15#include "common/settings_enums.h" 16#include "common/settings_enums.h"
@@ -115,8 +116,12 @@ protected:
115 } else if constexpr (std::is_same_v<Type, AudioEngine>) { 116 } else if constexpr (std::is_same_v<Type, AudioEngine>) {
116 // Compatibility with old AudioEngine setting being a string 117 // Compatibility with old AudioEngine setting being a string
117 return CanonicalizeEnum(value_); 118 return CanonicalizeEnum(value_);
119 } else if constexpr (std::is_floating_point_v<Type>) {
120 return fmt::format("{:f}", value_);
121 } else if constexpr (std::is_enum_v<Type>) {
122 return std::to_string(static_cast<u32>(value_));
118 } else { 123 } else {
119 return std::to_string(static_cast<u64>(value_)); 124 return std::to_string(value_);
120 } 125 }
121 } 126 }
122 127
@@ -180,13 +185,17 @@ public:
180 this->SetValue(static_cast<u32>(std::stoul(input))); 185 this->SetValue(static_cast<u32>(std::stoul(input)));
181 } else if constexpr (std::is_same_v<Type, bool>) { 186 } else if constexpr (std::is_same_v<Type, bool>) {
182 this->SetValue(input == "true"); 187 this->SetValue(input == "true");
188 } else if constexpr (std::is_same_v<Type, float>) {
189 this->SetValue(std::stof(input));
183 } else if constexpr (std::is_same_v<Type, AudioEngine>) { 190 } else if constexpr (std::is_same_v<Type, AudioEngine>) {
184 this->SetValue(ToEnum<Type>(input)); 191 this->SetValue(ToEnum<AudioEngine>(input));
185 } else { 192 } else {
186 this->SetValue(static_cast<Type>(std::stoll(input))); 193 this->SetValue(static_cast<Type>(std::stoll(input)));
187 } 194 }
188 } catch (std::invalid_argument&) { 195 } catch (std::invalid_argument&) {
189 this->SetValue(this->GetDefault()); 196 this->SetValue(this->GetDefault());
197 } catch (std::out_of_range&) {
198 this->SetValue(this->GetDefault());
190 } 199 }
191 } 200 }
192 201
@@ -215,11 +224,27 @@ public:
215 } 224 }
216 } 225 }
217 226
227 [[nodiscard]] constexpr bool IsFloatingPoint() const final {
228 return std::is_floating_point_v<Type>;
229 }
230
231 [[nodiscard]] constexpr bool IsIntegral() const final {
232 return std::is_integral_v<Type>;
233 }
234
218 [[nodiscard]] std::string MinVal() const override final { 235 [[nodiscard]] std::string MinVal() const override final {
219 return this->ToString(minimum); 236 if constexpr (std::is_arithmetic_v<Type> && !ranged) {
237 return this->ToString(std::numeric_limits<Type>::min());
238 } else {
239 return this->ToString(minimum);
240 }
220 } 241 }
221 [[nodiscard]] std::string MaxVal() const override final { 242 [[nodiscard]] std::string MaxVal() const override final {
222 return this->ToString(maximum); 243 if constexpr (std::is_arithmetic_v<Type> && !ranged) {
244 return this->ToString(std::numeric_limits<Type>::max());
245 } else {
246 return this->ToString(maximum);
247 }
223 } 248 }
224 249
225 [[nodiscard]] constexpr bool Ranged() const override { 250 [[nodiscard]] constexpr bool Ranged() const override {