lsnes/include/interface/setting.hpp

155 lines
2.8 KiB
C++
Raw Normal View History

2013-01-05 09:19:09 +02:00
#ifndef _interface__setting__hpp__included__
#define _interface__setting__hpp__included__
#include <string>
#include <stdexcept>
#include <vector>
#include <map>
#include <set>
struct core_setting;
struct core_setting_group;
2013-06-28 17:57:45 +03:00
/**
* A value for setting (structure).
*/
struct core_setting_value_param
{
const char* iname;
const char* hname;
signed index;
};
2013-07-06 20:41:32 +03:00
/**
* A setting (structure)
*/
struct core_setting_param
{
const char* iname;
const char* hname;
const char* dflt;
std::vector<core_setting_value_param> values;
const char* regex;
};
2013-01-05 09:19:09 +02:00
/**
* A value for setting.
*/
struct core_setting_value
{
/**
* Create a new setting value.
*/
2013-07-06 20:41:32 +03:00
core_setting_value(const core_setting_value_param& p) throw(std::bad_alloc);
2013-01-05 09:19:09 +02:00
/**
* Internal value.
*/
const std::string iname;
/**
* Human-readable value.
*/
const std::string hname;
/**
* Index.
*/
signed index;
};
/**
* A setting.
*/
struct core_setting
{
/**
* Create a new setting.
*/
2013-07-06 20:41:32 +03:00
core_setting(const core_setting_param& p);
2013-01-05 09:19:09 +02:00
/**
* Internal name.
*/
const std::string iname;
/**
* Human-readable name.
*/
const std::string hname;
/**
* Regular expression for validation of fretext setting.
*/
const std::string regex;
/**
* The default value.
*/
const std::string dflt;
/**
* The values.
*/
2013-07-06 20:41:32 +03:00
std::vector<core_setting_value> values;
2013-01-05 09:19:09 +02:00
/**
* Is this setting a boolean?
*/
bool is_boolean() const throw();
/**
* Is this setting a freetext setting?
*/
bool is_freetext() const throw();
/**
* Get set of human-readable strings.
*/
std::vector<std::string> hvalues() const throw(std::runtime_error);
/**
* Translate hvalue to ivalue.
*/
std::string hvalue_to_ivalue(const std::string& hvalue) const throw(std::runtime_error);
/**
* Translate ivalue to index.
*/
signed ivalue_to_index(const std::string& ivalue) const throw(std::runtime_error);
/**
* Validate a value.
*
* Parameter value: The value to validate.
*/
bool validate(const std::string& value) const;
};
/**
* A group of settings.
*/
struct core_setting_group
{
/**
* Create a new group of settings.
*/
2013-07-06 20:41:32 +03:00
core_setting_group(std::initializer_list<core_setting_param> settings);
2013-01-05 09:19:09 +02:00
/**
2013-07-06 20:41:32 +03:00
* Create a new group of settings.
2013-01-05 09:19:09 +02:00
*/
2013-07-06 20:41:32 +03:00
core_setting_group(std::vector<core_setting_param> settings);
2013-01-05 09:19:09 +02:00
/**
2013-07-06 20:41:32 +03:00
* The settings.
2013-01-05 09:19:09 +02:00
*/
2013-07-06 20:41:32 +03:00
std::map<std::string, core_setting> settings;
2013-01-05 09:19:09 +02:00
/**
2013-07-06 20:41:32 +03:00
* Get specified setting.
2013-01-05 09:19:09 +02:00
*/
2013-07-06 20:41:32 +03:00
core_setting& operator[](const std::string& name) { return settings.find(name)->second; }
2013-01-05 09:19:09 +02:00
/**
2013-07-06 20:41:32 +03:00
* Translate ivalue to index.
2013-01-05 09:19:09 +02:00
*/
2013-07-06 20:41:32 +03:00
signed ivalue_to_index(std::map<std::string, std::string>& values, const std::string& name) const
throw(std::runtime_error)
{
return settings.find(name)->second.ivalue_to_index(values[name]);
}
2013-01-05 09:19:09 +02:00
/**
* Fill a map of settings with defaults.
*/
void fill_defaults(std::map<std::string, std::string>& values) throw(std::bad_alloc);
/**
* Get set of settings.
*/
std::set<std::string> get_setting_set();
};
#endif