Make git diff --check happy
[lsnes.git] / settings.hpp
blob246f57dc5f35dc23f40d1690f6844bd6d9a13ea0
1 #ifndef _settings__hpp__included__
2 #define _settings__hpp__included__
4 #include <string>
5 #include <stdexcept>
6 #include "window.hpp"
8 /**
9 * A setting.
11 class setting
13 public:
14 /**
15 * Create new setting.
17 * parameter name: Name of the setting.
18 * throws std::bad_alloc: Not enough memory.
20 setting(const std::string& name) throw(std::bad_alloc);
22 /**
23 * Remove the setting.
25 ~setting() throw();
27 /**
28 * Set the setting to special blank state. Not all settings can be blanked.
30 * throws std::bad_alloc: Not enough memory.
31 * throws std::runtime_error: Blanking this setting is not allowed (currently).
33 virtual void blank() throw(std::bad_alloc, std::runtime_error) = 0;
35 /**
36 * Look up setting and try to blank it.
38 * parameter name: Name of setting to blank.
39 * throws std::bad_alloc: Not enough memory.
40 * throws std::runtime_error: Blanking this setting is not allowed (currently). Or setting does not exist.
42 static void blank(const std::string& name) throw(std::bad_alloc, std::runtime_error);
44 /**
45 * Is this setting set (not blanked)?
47 * returns: True if setting is not blanked, false if it is blanked.
49 virtual bool is_set() throw() = 0;
51 /**
52 * Look up a setting and see if it is set (not blanked)?
54 * parameter name: Name of setting to check.
55 * returns: True if setting is not blanked, false if it is blanked.
56 * throws std::bad_alloc: Not enough memory.
57 * throws std::runtime_error: Setting does not exist.
59 static bool is_set(const std::string& name) throw(std::bad_alloc, std::runtime_error);
61 /**
62 * Set value of setting.
64 * parameter value: New value for setting.
65 * throws std::bad_alloc: Not enough memory.
66 * throws std::runtime_error: Setting the setting to this value is not allowed (currently).
68 virtual void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) = 0;
70 /**
71 * Look up setting and set it.
73 * parameter name: Name of the setting.
74 * parameter value: New value for setting.
75 * throws std::bad_alloc: Not enough memory.
76 * throws std::runtime_error: Setting the setting to this value is not allowed (currently). Or setting does not exist.
78 static void set(const std::string& name, const std::string& value) throw(std::bad_alloc, std::runtime_error);
80 /**
81 * Get the value of setting.
83 * returns: The setting value.
84 * throws std::bad_alloc: Not enough memory.
86 virtual std::string get() throw(std::bad_alloc) = 0;
88 /**
89 * Look up setting an get value of it.
91 * returns: The setting value.
92 * throws std::bad_alloc: Not enough memory.
93 * throws std::runtime_error: Setting does not exist.
95 static std::string get(const std::string& name) throw(std::bad_alloc, std::runtime_error);
97 /**
98 * Print all settings and values.
100 * parameter win: The graphics system handle.
101 * throws std::bad_alloc: Not enough memory.
103 static void print_all(window* win) throw(std::bad_alloc);
104 protected:
105 std::string settingname;
109 * Setting having numeric value.
111 class numeric_setting : public setting
113 public:
115 * Create a new numeric setting.
117 * parameter sname: Name of the setting.
118 * parameter minv: Minimum value for the setting.
119 * parameter maxv: Maximum value for the setting.
120 * parameter dflt: Default (initial) value for the setting.
121 * throws std::bad_alloc: Not enough memory.
123 numeric_setting(const std::string& sname, int32_t minv, int32_t maxv, int32_t dflt) throw(std::bad_alloc);
125 * Raises std::runtime_error as these settings can't be blanked.
127 void blank() throw(std::bad_alloc, std::runtime_error);
129 * Returns true (these settings are always set).
131 bool is_set() throw();
133 * Set the value of setting. Accepts only numeric values.
135 * parameter value: New value.
136 * throws std::bad_alloc: Not enough memory.
137 * throws std::runtime_error: Invalid value.
139 void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
141 * Gets the value of the setting.
143 * returns: Value of setting as string.
144 * throws std::bad_alloc: Not enough memory.
146 std::string get() throw(std::bad_alloc);
148 * Get the value of setting as numeric.
150 * returns: Value of the setting as numeric.
152 operator int32_t() throw();
153 private:
154 int32_t value;
155 int32_t minimum;
156 int32_t maximum;
160 * Setting having boolean value.
162 class boolean_setting : public setting
164 public:
166 * Create a new boolean setting.
168 * parameter sname: Name of the setting.
169 * parameter dflt: Default (initial) value for the setting.
170 * throws std::bad_alloc: Not enough memory.
172 boolean_setting(const std::string& sname, bool dflt) throw(std::bad_alloc);
174 * Raises std::runtime_error as these settings can't be blanked.
176 void blank() throw(std::bad_alloc, std::runtime_error);
178 * Returns true (these settings are always set).
180 bool is_set() throw();
182 * Set the value of setting.
184 * The following values are accepted as true: true, yes, on, 1, enable and enabled.
185 * The following values are accepted as false: false, no, off, 0, disable and disabled.
187 * parameter value: New value.
188 * throws std::bad_alloc: Not enough memory.
189 * throws std::runtime_error: Invalid value.
191 void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
193 * Gets the value of the setting.
195 * returns: Value of setting as string.
196 * throws std::bad_alloc: Not enough memory.
198 std::string get() throw(std::bad_alloc);
200 * Get the value of setting as boolean.
202 * returns: Value of the setting as boolean.
204 operator bool() throw();
205 private:
206 bool value;
209 #endif