Add new lua hooks
[lsnes.git] / include / core / settings.hpp
blob10849258fb1e7216770574212ca24e4d315f4537
1 #ifndef _settings__hpp__included__
2 #define _settings__hpp__included__
4 #include <string>
5 #include <set>
6 #include <stdexcept>
7 #include <iostream>
9 /**
10 * A setting.
12 class setting
14 public:
15 /**
16 * Create new setting.
18 * parameter name: Name of the setting.
19 * throws std::bad_alloc: Not enough memory.
21 setting(const std::string& name) throw(std::bad_alloc);
23 /**
24 * Remove the setting.
26 ~setting() throw();
28 /**
29 * Set the setting to special blank state. Not all settings can be blanked.
31 * throws std::bad_alloc: Not enough memory.
32 * throws std::runtime_error: Blanking this setting is not allowed (currently).
34 virtual void blank() throw(std::bad_alloc, std::runtime_error) = 0;
36 /**
37 * Look up setting and try to blank it.
39 * parameter name: Name of setting to blank.
40 * throws std::bad_alloc: Not enough memory.
41 * throws std::runtime_error: Blanking this setting is not allowed (currently). Or setting does not exist.
43 static void blank(const std::string& name) throw(std::bad_alloc, std::runtime_error);
45 /**
46 * Is this setting set (not blanked)?
48 * returns: True if setting is not blanked, false if it is blanked.
50 virtual bool is_set() throw() = 0;
52 /**
53 * Look up a setting and see if it is set (not blanked)?
55 * parameter name: Name of setting to check.
56 * returns: True if setting is not blanked, false if it is blanked.
57 * throws std::bad_alloc: Not enough memory.
58 * throws std::runtime_error: Setting does not exist.
60 static bool is_set(const std::string& name) throw(std::bad_alloc, std::runtime_error);
62 /**
63 * Set value of setting.
65 * parameter value: New value for setting.
66 * throws std::bad_alloc: Not enough memory.
67 * throws std::runtime_error: Setting the setting to this value is not allowed (currently).
69 virtual void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) = 0;
71 /**
72 * Look up setting and set it.
74 * parameter name: Name of the setting.
75 * parameter value: New value for setting.
76 * throws std::bad_alloc: Not enough memory.
77 * throws std::runtime_error: Setting the setting to this value is not allowed (currently). Or setting does not exist.
79 static void set(const std::string& name, const std::string& value) throw(std::bad_alloc, std::runtime_error);
81 /**
82 * Get the value of setting.
84 * returns: The setting value.
85 * throws std::bad_alloc: Not enough memory.
87 virtual std::string get() throw(std::bad_alloc) = 0;
89 /**
90 * Look up setting an get value of it.
92 * returns: The setting value.
93 * throws std::bad_alloc: Not enough memory.
94 * throws std::runtime_error: Setting does not exist.
96 static std::string get(const std::string& name) throw(std::bad_alloc, std::runtime_error);
98 /**
99 * Get set of all settings.
101 static std::set<std::string> get_settings_set() throw(std::bad_alloc);
102 protected:
103 std::string settingname;
107 * Setting having numeric value.
109 class numeric_setting : public setting
111 public:
113 * Create a new numeric setting.
115 * parameter sname: Name of the setting.
116 * parameter minv: Minimum value for the setting.
117 * parameter maxv: Maximum value for the setting.
118 * parameter dflt: Default (initial) value for the setting.
119 * throws std::bad_alloc: Not enough memory.
121 numeric_setting(const std::string& sname, int32_t minv, int32_t maxv, int32_t dflt) throw(std::bad_alloc);
123 * Raises std::runtime_error as these settings can't be blanked.
125 void blank() throw(std::bad_alloc, std::runtime_error);
127 * Returns true (these settings are always set).
129 bool is_set() throw();
131 * Set the value of setting. Accepts only numeric values.
133 * parameter value: New value.
134 * throws std::bad_alloc: Not enough memory.
135 * throws std::runtime_error: Invalid value.
137 void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
139 * Gets the value of the setting.
141 * returns: Value of setting as string.
142 * throws std::bad_alloc: Not enough memory.
144 std::string get() throw(std::bad_alloc);
146 * Get the value of setting as numeric.
148 * returns: Value of the setting as numeric.
150 operator int32_t() throw();
151 private:
152 int32_t value;
153 int32_t minimum;
154 int32_t maximum;
158 * Setting having boolean value.
160 class boolean_setting : public setting
162 public:
164 * Create a new boolean setting.
166 * parameter sname: Name of the setting.
167 * parameter dflt: Default (initial) value for the setting.
168 * throws std::bad_alloc: Not enough memory.
170 boolean_setting(const std::string& sname, bool dflt) throw(std::bad_alloc);
172 * Raises std::runtime_error as these settings can't be blanked.
174 void blank() throw(std::bad_alloc, std::runtime_error);
176 * Returns true (these settings are always set).
178 bool is_set() throw();
180 * Set the value of setting.
182 * The following values are accepted as true: true, yes, on, 1, enable and enabled.
183 * The following values are accepted as false: false, no, off, 0, disable and disabled.
185 * parameter value: New value.
186 * throws std::bad_alloc: Not enough memory.
187 * throws std::runtime_error: Invalid value.
189 void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
191 * Gets the value of the setting.
193 * returns: Value of setting as string.
194 * throws std::bad_alloc: Not enough memory.
196 std::string get() throw(std::bad_alloc);
198 * Get the value of setting as boolean.
200 * returns: Value of the setting as boolean.
202 operator bool() throw();
203 private:
204 bool value;
207 #endif