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 * Get set of all settings.
101 static std::set
<std::string
> get_settings_set() throw(std::bad_alloc
);
103 std::string settingname
;
107 * Setting having numeric value.
109 class numeric_setting
: public setting
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();
158 * Setting having boolean value.
160 class boolean_setting
: public setting
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();