2011-09-13 17:50:18 +03:00
|
|
|
#ifndef _settings__hpp__included__
|
|
|
|
#define _settings__hpp__included__
|
|
|
|
|
|
|
|
#include <string>
|
2011-11-05 20:09:10 +02:00
|
|
|
#include <set>
|
2011-09-13 17:50:18 +03:00
|
|
|
#include <stdexcept>
|
2011-09-16 21:16:27 +03:00
|
|
|
#include <iostream>
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* A setting.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
class setting
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Create new setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter name: Name of the setting.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
setting(const std::string& name) throw(std::bad_alloc);
|
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Remove the setting.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
~setting() throw();
|
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Set the setting to special blank state. Not all settings can be blanked.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Blanking this setting is not allowed (currently).
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
virtual void blank() throw(std::bad_alloc, std::runtime_error) = 0;
|
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Look up setting and try to blank it.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter name: Name of setting to blank.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Blanking this setting is not allowed (currently). Or setting does not exist.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
static void blank(const std::string& name) throw(std::bad_alloc, std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Is this setting set (not blanked)?
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: True if setting is not blanked, false if it is blanked.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
virtual bool is_set() throw() = 0;
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Look up a setting and see if it is set (not blanked)?
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter name: Name of setting to check.
|
|
|
|
* returns: True if setting is not blanked, false if it is blanked.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Setting does not exist.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
static bool is_set(const std::string& name) throw(std::bad_alloc, std::runtime_error);
|
2011-09-15 22:56:33 +03:00
|
|
|
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Set value of setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter value: New value for setting.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Setting the setting to this value is not allowed (currently).
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
virtual void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) = 0;
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Look up setting and set it.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter name: Name of the setting.
|
|
|
|
* parameter value: New value for setting.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Setting the setting to this value is not allowed (currently). Or setting does not exist.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
static void set(const std::string& name, const std::string& value) throw(std::bad_alloc, std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Get the value of setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: The setting value.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
virtual std::string get() throw(std::bad_alloc) = 0;
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Look up setting an get value of it.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: The setting value.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Setting does not exist.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-15 15:12:26 +03:00
|
|
|
static std::string get(const std::string& name) throw(std::bad_alloc, std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Print all settings and values.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-17 01:05:41 +03:00
|
|
|
static void print_all() throw(std::bad_alloc);
|
2011-11-05 20:09:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get set of all settings.
|
|
|
|
*/
|
|
|
|
static std::set<std::string> get_settings_set() throw(std::bad_alloc);
|
2011-09-15 15:12:26 +03:00
|
|
|
protected:
|
|
|
|
std::string settingname;
|
|
|
|
};
|
2011-09-13 17:50:18 +03:00
|
|
|
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Setting having numeric value.
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
class numeric_setting : public setting
|
|
|
|
{
|
|
|
|
public:
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Create a new numeric setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter sname: Name of the setting.
|
|
|
|
* parameter minv: Minimum value for the setting.
|
|
|
|
* parameter maxv: Maximum value for the setting.
|
|
|
|
* parameter dflt: Default (initial) value for the setting.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
numeric_setting(const std::string& sname, int32_t minv, int32_t maxv, int32_t dflt) throw(std::bad_alloc);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Raises std::runtime_error as these settings can't be blanked.
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
void blank() throw(std::bad_alloc, std::runtime_error);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Returns true (these settings are always set).
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
bool is_set() throw();
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Set the value of setting. Accepts only numeric values.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter value: New value.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Invalid value.
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Gets the value of the setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: Value of setting as string.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
std::string get() throw(std::bad_alloc);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Get the value of setting as numeric.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: Value of the setting as numeric.
|
|
|
|
*/
|
2011-09-13 17:50:18 +03:00
|
|
|
operator int32_t() throw();
|
|
|
|
private:
|
|
|
|
int32_t value;
|
|
|
|
int32_t minimum;
|
|
|
|
int32_t maximum;
|
|
|
|
};
|
|
|
|
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Setting having boolean value.
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
class boolean_setting : public setting
|
|
|
|
{
|
|
|
|
public:
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Create a new boolean setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter sname: Name of the setting.
|
|
|
|
* parameter dflt: Default (initial) value for the setting.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
boolean_setting(const std::string& sname, bool dflt) throw(std::bad_alloc);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Raises std::runtime_error as these settings can't be blanked.
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
void blank() throw(std::bad_alloc, std::runtime_error);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Returns true (these settings are always set).
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
bool is_set() throw();
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Set the value of setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* The following values are accepted as true: true, yes, on, 1, enable and enabled.
|
|
|
|
* The following values are accepted as false: false, no, off, 0, disable and disabled.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* parameter value: New value.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Invalid value.
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Gets the value of the setting.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: Value of setting as string.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
std::string get() throw(std::bad_alloc);
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
|
|
|
* Get the value of setting as boolean.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-15 15:12:26 +03:00
|
|
|
* returns: Value of the setting as boolean.
|
|
|
|
*/
|
2011-09-14 23:16:24 +03:00
|
|
|
operator bool() throw();
|
|
|
|
private:
|
|
|
|
bool value;
|
|
|
|
};
|
|
|
|
|
2011-09-13 17:50:18 +03:00
|
|
|
#endif
|