Lua: Fix type confusion between signed and unsigned
[lsnes.git] / include / interface / setting.hpp
blobe41eaebb4d6f8c67748032844bbb00fa44a5d83d
1 #ifndef _interface__setting__hpp__included__
2 #define _interface__setting__hpp__included__
4 #include <string>
5 #include <stdexcept>
6 #include <vector>
7 #include <map>
8 #include <set>
10 struct core_setting;
11 struct core_setting_group;
13 /**
14 * A value for setting (structure).
16 struct core_setting_value_param
18 const char* iname;
19 const char* hname;
20 signed index;
23 /**
24 * A setting (structure)
26 struct core_setting_param
28 const char* iname;
29 const char* hname;
30 const char* dflt;
31 std::vector<core_setting_value_param> values;
32 const char* regex;
35 /**
36 * A value for setting.
38 struct core_setting_value
40 /**
41 * Create a new setting value.
43 core_setting_value(const core_setting_value_param& p) throw(std::bad_alloc);
44 /**
45 * Internal value.
47 const std::string iname;
48 /**
49 * Human-readable value.
51 const std::string hname;
52 /**
53 * Index.
55 signed index;
58 /**
59 * A setting.
61 struct core_setting
63 /**
64 * Create a new setting.
66 core_setting(const core_setting_param& p);
67 /**
68 * Internal name.
70 const std::string iname;
71 /**
72 * Human-readable name.
74 const std::string hname;
75 /**
76 * Regular expression for validation of fretext setting.
78 const std::string regex;
79 /**
80 * The default value.
82 const std::string dflt;
83 /**
84 * The values.
86 std::vector<core_setting_value> values;
87 /**
88 * Is this setting a boolean?
90 bool is_boolean() const throw();
91 /**
92 * Is this setting a freetext setting?
94 bool is_freetext() const throw();
95 /**
96 * Get set of human-readable strings.
98 std::vector<std::string> hvalues() const throw(std::runtime_error);
99 /**
100 * Translate hvalue to ivalue.
102 std::string hvalue_to_ivalue(const std::string& hvalue) const throw(std::runtime_error);
104 * Translate ivalue to index.
106 signed ivalue_to_index(const std::string& ivalue) const throw(std::runtime_error);
108 * Validate a value.
110 * Parameter value: The value to validate.
112 bool validate(const std::string& value) const;
116 * A group of settings.
118 struct core_setting_group
120 core_setting_group();
122 * Create a new group of settings.
124 core_setting_group(std::initializer_list<core_setting_param> settings);
126 * Create a new group of settings.
128 core_setting_group(std::vector<core_setting_param> settings);
130 * The settings.
132 std::map<std::string, core_setting> settings;
134 * Get specified setting.
136 core_setting& operator[](const std::string& name) { return settings.find(name)->second; }
138 * Translate ivalue to index.
140 signed ivalue_to_index(std::map<std::string, std::string>& values, const std::string& name) const
141 throw(std::runtime_error)
143 return settings.find(name)->second.ivalue_to_index(values[name]);
146 * Fill a map of settings with defaults.
148 void fill_defaults(std::map<std::string, std::string>& values) throw(std::bad_alloc);
150 * Get set of settings.
152 std::set<std::string> get_setting_set();
155 #endif