summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar lat9nq2023-06-13 19:37:54 -0400
committerGravatar lat9nq2023-07-21 10:56:54 -0400
commit27e53990ed7100159cc08fd8470a9faecd011cbe (patch)
treeb4f5b4ad38179f012fedff8a22b22ca027a397fc /src/common
parentsettings: Move IsConfiguringGlobal to settings_common (diff)
downloadyuzu-27e53990ed7100159cc08fd8470a9faecd011cbe.tar.gz
yuzu-27e53990ed7100159cc08fd8470a9faecd011cbe.tar.xz
yuzu-27e53990ed7100159cc08fd8470a9faecd011cbe.zip
settings: Document BasicSetting, add Ranged
Diffstat (limited to 'src/common')
-rw-r--r--src/common/settings_common.h115
-rw-r--r--src/common/settings_setting.h4
2 files changed, 110 insertions, 9 deletions
diff --git a/src/common/settings_common.h b/src/common/settings_common.h
index 9d1044a19..4d6d3021e 100644
--- a/src/common/settings_common.h
+++ b/src/common/settings_common.h
@@ -57,6 +57,10 @@ public:
57 u32 count; 57 u32 count;
58}; 58};
59 59
60/**
61 * BasicSetting is an abstract class that only keeps track of metadata. The string methods are
62 * available to get data values out.
63 */
60class BasicSetting { 64class BasicSetting {
61protected: 65protected:
62 explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_, 66 explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
@@ -65,45 +69,117 @@ protected:
65public: 69public:
66 virtual ~BasicSetting(); 70 virtual ~BasicSetting();
67 71
68 /* Data retrieval */ 72 /*
73 * Data retrieval
74 */
69 75
76 /**
77 * Returns a string representation of the internal data. If the Setting is Switchable, it
78 * respects the internal global state: it is based on GetValue().
79 *
80 * @returns A string representation of the internal data.
81 */
70 [[nodiscard]] virtual std::string ToString() const = 0; 82 [[nodiscard]] virtual std::string ToString() const = 0;
83
84 /**
85 * Returns a string representation of the global version of internal data. If the Setting is
86 * not Switchable, it behaves like ToString.
87 *
88 * @returns A string representation of the global version of internal data.
89 */
71 [[nodiscard]] virtual std::string ToStringGlobal() const; 90 [[nodiscard]] virtual std::string ToStringGlobal() const;
91
92 /**
93 * @returns A string representation of the Setting's default value.
94 */
72 [[nodiscard]] virtual std::string DefaultToString() const = 0; 95 [[nodiscard]] virtual std::string DefaultToString() const = 0;
96
97 /**
98 * Returns a string representation of the minimum value of the setting. If the Setting is not
99 * ranged, the string represents the default initialization of the data type.
100 *
101 * @returns A string representation of the minimum value of the setting.
102 */
73 [[nodiscard]] virtual std::string MinVal() const = 0; 103 [[nodiscard]] virtual std::string MinVal() const = 0;
104
105 /**
106 * Returns a string representation of the maximum value of the setting. If the Setting is not
107 * ranged, the string represents the default initialization of the data type.
108 *
109 * @returns A string representation of the maximum value of the setting.
110 */
74 [[nodiscard]] virtual std::string MaxVal() const = 0; 111 [[nodiscard]] virtual std::string MaxVal() const = 0;
112
113 /**
114 * Takes a string input, converts it to the internal data type if necessary, and then runs
115 * SetValue with it.
116 *
117 * @param load String of the input data.
118 */
75 virtual void LoadString(const std::string& load) = 0; 119 virtual void LoadString(const std::string& load) = 0;
120
121 /**
122 * Returns a string representation of the data. If the data is an enum, it returns a string of
123 * the enum value. If the internal data type is not an enum, this is equivalent to ToString.
124 *
125 * e.g. renderer_backend.Canonicalize() == "OpenGL"
126 *
127 * @returns Canonicalized string representation of the internal data
128 */
76 [[nodiscard]] virtual std::string Canonicalize() const = 0; 129 [[nodiscard]] virtual std::string Canonicalize() const = 0;
77 130
78 /* Identification */ 131 /*
132 * Metadata
133 */
79 134
135 /**
136 * @returns A unique identifier for the Setting's internal data type.
137 */
80 [[nodiscard]] virtual std::type_index TypeId() const = 0; 138 [[nodiscard]] virtual std::type_index TypeId() const = 0;
139
140 /**
141 * Returns true if the Setting's internal data type is an enum.
142 *
143 * @returns True if the Setting's internal data type is an enum
144 */
81 [[nodiscard]] virtual constexpr bool IsEnum() const = 0; 145 [[nodiscard]] virtual constexpr bool IsEnum() const = 0;
146
82 /** 147 /**
83 * Returns whether the current setting is Switchable. 148 * Returns true if the current setting is Switchable.
84 * 149 *
85 * @returns If the setting is a SwitchableSetting 150 * @returns If the setting is a SwitchableSetting
86 */ 151 */
87 [[nodiscard]] virtual constexpr bool Switchable() const { 152 [[nodiscard]] virtual constexpr bool Switchable() const {
88 return false; 153 return false;
89 } 154 }
155
90 /** 156 /**
91 * Returns the save preference of the setting i.e. when saving or reading the setting from a 157 * Returns true to suggest that a frontend can read or write the setting to a configuration
92 * frontend, whether this setting should be skipped. 158 * file.
93 * 159 *
94 * @returns The save preference 160 * @returns The save preference
95 */ 161 */
96 [[nodiscard]] bool Save() const; 162 [[nodiscard]] bool Save() const;
163
164 /**
165 * @returns true if the current setting can be changed while the guest is running.
166 */
97 [[nodiscard]] bool RuntimeModfiable() const; 167 [[nodiscard]] bool RuntimeModfiable() const;
168
169 /**
170 * @returns A unique number corresponding to the setting.
171 */
98 [[nodiscard]] constexpr u32 Id() const { 172 [[nodiscard]] constexpr u32 Id() const {
99 return id; 173 return id;
100 } 174 }
175
101 /** 176 /**
102 * Returns the setting's category AKA INI group. 177 * Returns the setting's category AKA INI group.
103 * 178 *
104 * @returns The setting's category 179 * @returns The setting's category
105 */ 180 */
106 [[nodiscard]] Category Category() const; 181 [[nodiscard]] Category Category() const;
182
107 /** 183 /**
108 * Returns the label this setting was created with. 184 * Returns the label this setting was created with.
109 * 185 *
@@ -111,17 +187,38 @@ public:
111 */ 187 */
112 [[nodiscard]] const std::string& GetLabel() const; 188 [[nodiscard]] const std::string& GetLabel() const;
113 189
114 /* Switchable settings */ 190 /**
191 * @returns If the Setting checks input values for valid ranges.
192 */
193 [[nodiscard]] virtual constexpr bool Ranged() const = 0;
194
195 /*
196 * Switchable settings
197 */
115 198
199 /**
200 * Sets a setting's global state. True means use the normal setting, false to use a custom
201 * value. Has no effect if the Setting is not Switchable.
202 *
203 * @param global The desired state
204 */
116 virtual void SetGlobal(bool global); 205 virtual void SetGlobal(bool global);
206
207 /**
208 * Returns true if the setting is using the normal setting value. Always true if the setting is
209 * not Switchable.
210 *
211 * @returns The Setting's global state
212 */
117 [[nodiscard]] virtual bool UsingGlobal() const; 213 [[nodiscard]] virtual bool UsingGlobal() const;
118 214
119private: 215private:
120 const std::string label; ///< The setting's label 216 const std::string label; ///< The setting's label
121 const enum Category category; ///< The setting's category AKA INI group 217 const enum Category category; ///< The setting's category AKA INI group
122 const u32 id; 218 const u32 id; ///< Unique integer for the setting
123 const bool save; 219 const bool save; ///< Suggests if the setting should be saved and read to a frontend config
124 const bool runtime_modifiable; 220 const bool
221 runtime_modifiable; ///< Suggests if the setting can be modified while a guest is running
125}; 222};
126 223
127} // namespace Settings 224} // namespace Settings
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h
index 1ca3acf18..658b6328d 100644
--- a/src/common/settings_setting.h
+++ b/src/common/settings_setting.h
@@ -198,6 +198,10 @@ public:
198 return this->ToString(maximum); 198 return this->ToString(maximum);
199 } 199 }
200 200
201 constexpr bool Ranged() const override {
202 return ranged;
203 }
204
201protected: 205protected:
202 Type value{}; ///< The setting 206 Type value{}; ///< The setting
203 const Type default_value{}; ///< The default value 207 const Type default_value{}; ///< The default value