1 #ifndef _settings__hpp__included__
2 #define _settings__hpp__included__
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
);
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;
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
);
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;
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
);
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;
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
);
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;
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
);
99 * Print all settings and values.
101 * throws std::bad_alloc: Not enough memory.
103 static void print_all() throw(std::bad_alloc
);
106 * Get set of all settings.
108 static std::set
<std::string
> get_settings_set() throw(std::bad_alloc
);
110 std::string settingname
;
114 * Setting having numeric value.
116 class numeric_setting
: public setting
120 * Create a new numeric setting.
122 * parameter sname: Name of the setting.
123 * parameter minv: Minimum value for the setting.
124 * parameter maxv: Maximum value for the setting.
125 * parameter dflt: Default (initial) value for the setting.
126 * throws std::bad_alloc: Not enough memory.
128 numeric_setting(const std::string
& sname
, int32_t minv
, int32_t maxv
, int32_t dflt
) throw(std::bad_alloc
);
130 * Raises std::runtime_error as these settings can't be blanked.
132 void blank() throw(std::bad_alloc
, std::runtime_error
);
134 * Returns true (these settings are always set).
136 bool is_set() throw();
138 * Set the value of setting. Accepts only numeric values.
140 * parameter value: New value.
141 * throws std::bad_alloc: Not enough memory.
142 * throws std::runtime_error: Invalid value.
144 void set(const std::string
& value
) throw(std::bad_alloc
, std::runtime_error
);
146 * Gets the value of the setting.
148 * returns: Value of setting as string.
149 * throws std::bad_alloc: Not enough memory.
151 std::string
get() throw(std::bad_alloc
);
153 * Get the value of setting as numeric.
155 * returns: Value of the setting as numeric.
157 operator int32_t() throw();
165 * Setting having boolean value.
167 class boolean_setting
: public setting
171 * Create a new boolean setting.
173 * parameter sname: Name of the setting.
174 * parameter dflt: Default (initial) value for the setting.
175 * throws std::bad_alloc: Not enough memory.
177 boolean_setting(const std::string
& sname
, bool dflt
) throw(std::bad_alloc
);
179 * Raises std::runtime_error as these settings can't be blanked.
181 void blank() throw(std::bad_alloc
, std::runtime_error
);
183 * Returns true (these settings are always set).
185 bool is_set() throw();
187 * Set the value of setting.
189 * The following values are accepted as true: true, yes, on, 1, enable and enabled.
190 * The following values are accepted as false: false, no, off, 0, disable and disabled.
192 * parameter value: New value.
193 * throws std::bad_alloc: Not enough memory.
194 * throws std::runtime_error: Invalid value.
196 void set(const std::string
& value
) throw(std::bad_alloc
, std::runtime_error
);
198 * Gets the value of the setting.
200 * returns: Value of setting as string.
201 * throws std::bad_alloc: Not enough memory.
203 std::string
get() throw(std::bad_alloc
);
205 * Get the value of setting as boolean.
207 * returns: Value of the setting as boolean.
209 operator bool() throw();