lsnes/include/core/settings.hpp

208 lines
5.4 KiB
C++
Raw Normal View History

#ifndef _settings__hpp__included__
#define _settings__hpp__included__
#include <string>
#include <set>
#include <stdexcept>
#include <iostream>
/**
2011-09-15 15:12:26 +03:00
* A setting.
*/
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.
*/
setting(const std::string& name) throw(std::bad_alloc);
/**
2011-09-15 15:12:26 +03:00
* Remove the setting.
*/
~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).
*/
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-15 15:12:26 +03:00
static void blank(const std::string& name) throw(std::bad_alloc, std::runtime_error);
/**
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-15 15:12:26 +03:00
virtual bool is_set() throw() = 0;
/**
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-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-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-15 15:12:26 +03:00
virtual void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) = 0;
/**
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-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-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-15 15:12:26 +03:00
virtual std::string get() throw(std::bad_alloc) = 0;
/**
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-15 15:12:26 +03:00
static std::string get(const std::string& name) throw(std::bad_alloc, std::runtime_error);
/**
* 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-15 15:12:26 +03:00
/**
* Setting having numeric value.
*/
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.
*/
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.
*/
void blank() throw(std::bad_alloc, std::runtime_error);
2011-09-15 15:12:26 +03:00
/**
* Returns true (these settings are always set).
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
void blank() throw(std::bad_alloc, std::runtime_error);
2011-09-15 15:12:26 +03:00
/**
* Returns true (these settings are always set).
*/
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.
*/
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.
*/
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.
*/
operator bool() throw();
private:
bool value;
};
#endif