summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar lat9nq2021-08-11 15:49:01 -0700
committerGravatar lat9nq2021-08-11 17:12:14 -0400
commit5be2d6fd2829e1bbb056f38101a0d6106736217a (patch)
treed47a8acb717c7974a50ea4aafbd6a604a6faa2ec /src
parentMerge pull request #6776 from lat9nq/ranged-settings (diff)
downloadyuzu-5be2d6fd2829e1bbb056f38101a0d6106736217a.tar.gz
yuzu-5be2d6fd2829e1bbb056f38101a0d6106736217a.tar.xz
yuzu-5be2d6fd2829e1bbb056f38101a0d6106736217a.zip
settings: Fix MSVC issues
According to https://stackoverflow.com/questions/469508, we run into a MSVC bug (since VS 2005) when using diamond inheritance for RangedSetting. This explicitly implements those functions in RangedSetting. GetValue is implemented as just calling the inherited version. The explicit converson operator is reimplemented. I opted for this over ignoring the warning with a pragma since this specifies the inherited behavior, and I have now less faith in MSVC to pick the right one. In addition, we mark destructors as virtual to silence what I believe is a fair MSVC compilation error.
Diffstat (limited to 'src')
-rw-r--r--src/common/settings.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index c4afff50b..1ba9b606c 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -75,7 +75,7 @@ public:
75 */ 75 */
76 explicit BasicSetting(const Type& default_val, const std::string& name) 76 explicit BasicSetting(const Type& default_val, const std::string& name)
77 : default_value{default_val}, global{default_val}, label{name} {} 77 : default_value{default_val}, global{default_val}, label{name} {}
78 ~BasicSetting() = default; 78 virtual ~BasicSetting() = default;
79 79
80 /** 80 /**
81 * Returns a reference to the setting's value. 81 * Returns a reference to the setting's value.
@@ -161,7 +161,7 @@ public:
161 explicit BasicRangedSetting(const Type& default_val, const Type& min_val, const Type& max_val, 161 explicit BasicRangedSetting(const Type& default_val, const Type& min_val, const Type& max_val,
162 const std::string& name) 162 const std::string& name)
163 : BasicSetting<Type>{default_val, name}, minimum{min_val}, maximum{max_val} {} 163 : BasicSetting<Type>{default_val, name}, minimum{min_val}, maximum{max_val} {}
164 ~BasicRangedSetting() = default; 164 virtual ~BasicRangedSetting() = default;
165 165
166 /** 166 /**
167 * Like BasicSetting's SetValue, except value is clamped to the range of the setting. 167 * Like BasicSetting's SetValue, except value is clamped to the range of the setting.
@@ -208,7 +208,7 @@ public:
208 */ 208 */
209 explicit Setting(const Type& default_val, const std::string& name) 209 explicit Setting(const Type& default_val, const std::string& name)
210 : BasicSetting<Type>(default_val, name) {} 210 : BasicSetting<Type>(default_val, name) {}
211 ~Setting() = default; 211 virtual ~Setting() = default;
212 212
213 /** 213 /**
214 * Tells this setting to represent either the global or custom setting when other member 214 * Tells this setting to represent either the global or custom setting when other member
@@ -237,13 +237,13 @@ public:
237 * 237 *
238 * @returns The required value of the setting 238 * @returns The required value of the setting
239 */ 239 */
240 [[nodiscard]] const Type& GetValue() const override { 240 [[nodiscard]] virtual const Type& GetValue() const override {
241 if (use_global) { 241 if (use_global) {
242 return this->global; 242 return this->global;
243 } 243 }
244 return custom; 244 return custom;
245 } 245 }
246 [[nodiscard]] const Type& GetValue(bool need_global) const { 246 [[nodiscard]] virtual const Type& GetValue(bool need_global) const {
247 if (use_global || need_global) { 247 if (use_global || need_global) {
248 return this->global; 248 return this->global;
249 } 249 }
@@ -286,7 +286,7 @@ public:
286 * 286 *
287 * @returns A reference to the current setting value 287 * @returns A reference to the current setting value
288 */ 288 */
289 explicit operator const Type&() const override { 289 virtual explicit operator const Type&() const override {
290 if (use_global) { 290 if (use_global) {
291 return this->global; 291 return this->global;
292 } 292 }
@@ -318,7 +318,22 @@ public:
318 : BasicSetting<Type>{default_val, name}, 318 : BasicSetting<Type>{default_val, name},
319 BasicRangedSetting<Type>{default_val, min_val, max_val, name}, Setting<Type>{default_val, 319 BasicRangedSetting<Type>{default_val, min_val, max_val, name}, Setting<Type>{default_val,
320 name} {} 320 name} {}
321 ~RangedSetting() = default; 321 virtual ~RangedSetting() = default;
322
323 // The following are needed to avoid a MSVC bug
324 // (source: https://stackoverflow.com/questions/469508)
325 [[nodiscard]] const Type& GetValue() const override {
326 return Setting<Type>::GetValue();
327 }
328 [[nodiscard]] const Type& GetValue(bool need_global) const override {
329 return Setting<Type>::GetValue(need_global);
330 }
331 explicit operator const Type&() const override {
332 if (this->use_global) {
333 return this->global;
334 }
335 return this->custom;
336 }
322 337
323 /** 338 /**
324 * Like BasicSetting's SetValue, except value is clamped to the range of the setting. Sets the 339 * Like BasicSetting's SetValue, except value is clamped to the range of the setting. Sets the