include fix + Setting.resetToDefault
This commit is contained in:
+19
-2
@@ -1,6 +1,7 @@
|
|||||||
#ifndef DATA_SETTING_H_
|
#ifndef DATA_SETTING_H_
|
||||||
#define DATA_SETTING_H_
|
#define DATA_SETTING_H_
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum class setting_format {
|
enum class setting_format {
|
||||||
@@ -16,6 +17,8 @@ public:
|
|||||||
|
|
||||||
virtual ~Setting() {}
|
virtual ~Setting() {}
|
||||||
|
|
||||||
|
virtual void resetToDefault() = 0;
|
||||||
|
|
||||||
virtual setting_format getFormat() const {
|
virtual setting_format getFormat() const {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
@@ -26,12 +29,22 @@ public:
|
|||||||
template<class T>
|
template<class T>
|
||||||
class NumberSetting : public Setting {
|
class NumberSetting : public Setting {
|
||||||
protected:
|
protected:
|
||||||
|
T initial;
|
||||||
T value;
|
T value;
|
||||||
T min;
|
T min;
|
||||||
T max;
|
T max;
|
||||||
public:
|
public:
|
||||||
NumberSetting(T value, T min, T max, setting_format format)
|
NumberSetting(
|
||||||
: Setting(format), value(value), min(min), max(max) {}
|
T value,
|
||||||
|
T min=std::numeric_limits<T>::min(),
|
||||||
|
T max=std::numeric_limits<T>::max(),
|
||||||
|
setting_format format=setting_format::simple
|
||||||
|
) : Setting(format),
|
||||||
|
initial(value),
|
||||||
|
value(value),
|
||||||
|
min(min),
|
||||||
|
max(max)
|
||||||
|
{}
|
||||||
|
|
||||||
T& operator*() {
|
T& operator*() {
|
||||||
return value;
|
return value;
|
||||||
@@ -57,6 +70,10 @@ public:
|
|||||||
return (value - min) / (max - min);
|
return (value - min) / (max - min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void resetToDefault() override {
|
||||||
|
value = initial;
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::string toString() const override;
|
virtual std::string toString() const override;
|
||||||
|
|
||||||
static inline NumberSetting createPercent(T def) {
|
static inline NumberSetting createPercent(T def) {
|
||||||
|
|||||||
Reference in New Issue
Block a user