Evdev joystick plugin
[lsnes.git] / generic / settings.hpp
blobd834609e79e35845c6f4623c40e4123b22fd7a40
1 #ifndef _settings__hpp__included__
2 #define _settings__hpp__included__
4 #include <string>
5 #include <stdexcept>
6 #include <iostream>
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 * throws std::bad_alloc: Not enough memory.
102 static void print_all() throw(std::bad_alloc);
103 protected:
104 std::string settingname;
108 * Setting having numeric value.
110 class numeric_setting : public setting
112 public:
114 * Create a new numeric setting.
116 * parameter sname: Name of the setting.
117 * parameter minv: Minimum value for the setting.
118 * parameter maxv: Maximum value for the setting.
119 * parameter dflt: Default (initial) value for the setting.
120 * throws std::bad_alloc: Not enough memory.
122 numeric_setting(const std::string& sname, int32_t minv, int32_t maxv, int32_t dflt) throw(std::bad_alloc);
124 * Raises std::runtime_error as these settings can't be blanked.
126 void blank() throw(std::bad_alloc, std::runtime_error);
128 * Returns true (these settings are always set).
130 bool is_set() throw();
132 * Set the value of setting. Accepts only numeric values.
134 * parameter value: New value.
135 * throws std::bad_alloc: Not enough memory.
136 * throws std::runtime_error: Invalid value.
138 void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
140 * Gets the value of the setting.
142 * returns: Value of setting as string.
143 * throws std::bad_alloc: Not enough memory.
145 std::string get() throw(std::bad_alloc);
147 * Get the value of setting as numeric.
149 * returns: Value of the setting as numeric.
151 operator int32_t() throw();
152 private:
153 int32_t value;
154 int32_t minimum;
155 int32_t maximum;
159 * Setting having boolean value.
161 class boolean_setting : public setting
163 public:
165 * Create a new boolean setting.
167 * parameter sname: Name of the setting.
168 * parameter dflt: Default (initial) value for the setting.
169 * throws std::bad_alloc: Not enough memory.
171 boolean_setting(const std::string& sname, bool dflt) throw(std::bad_alloc);
173 * Raises std::runtime_error as these settings can't be blanked.
175 void blank() throw(std::bad_alloc, std::runtime_error);
177 * Returns true (these settings are always set).
179 bool is_set() throw();
181 * Set the value of setting.
183 * The following values are accepted as true: true, yes, on, 1, enable and enabled.
184 * The following values are accepted as false: false, no, off, 0, disable and disabled.
186 * parameter value: New value.
187 * throws std::bad_alloc: Not enough memory.
188 * throws std::runtime_error: Invalid value.
190 void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
192 * Gets the value of the setting.
194 * returns: Value of setting as string.
195 * throws std::bad_alloc: Not enough memory.
197 std::string get() throw(std::bad_alloc);
199 * Get the value of setting as boolean.
201 * returns: Value of the setting as boolean.
203 operator bool() throw();
204 private:
205 bool value;
208 #endif