1 #include "interface/setting.hpp"
2 #include "library/register-queue.hpp"
3 #include "library/string.hpp"
5 core_setting_value::core_setting_value(const core_setting_value_param
& p
) throw(std::bad_alloc
)
6 : iname(p
.iname
), hname(p
.hname
), index(p
.index
)
10 core_setting::core_setting(const core_setting_param
& p
)
11 : iname(p
.iname
), hname(p
.hname
), regex(p
.regex
? p
.regex
: ""), dflt(p
.dflt
)
13 for(auto i
: p
.values
)
14 values
.push_back(core_setting_value(i
));
17 bool core_setting::is_boolean() const throw()
19 if(values
.size() != 2)
21 std::string a
= values
[0].iname
;
22 std::string b
= values
[1].iname
;
25 return (a
== "0" && b
== "1");
28 bool core_setting::is_freetext() const throw()
30 return (values
.size() == 0);
33 bool core_setting::validate(const std::string
& value
) const
35 if(values
.size() != 0) {
41 return regex_match(regex
, value
);
44 core_setting_group::core_setting_group(std::initializer_list
<core_setting_param
> _settings
)
46 for(auto i
: _settings
)
47 settings
.insert(std::make_pair(i
.iname
, core_setting(i
)));
50 core_setting_group::core_setting_group(std::vector
<core_setting_param
> _settings
)
52 for(auto i
: _settings
)
53 settings
.insert(std::make_pair(i
.iname
, core_setting(i
)));
56 void core_setting_group::fill_defaults(std::map
<std::string
, std::string
>& values
) throw(std::bad_alloc
)
58 for(auto i
: settings
)
59 if(!values
.count(i
.first
))
60 values
[i
.first
] = i
.second
.dflt
;
63 std::set
<std::string
> core_setting_group::get_setting_set()
65 std::set
<std::string
> r
;
66 for(auto i
: settings
)
71 std::vector
<std::string
> core_setting::hvalues() const throw(std::runtime_error
)
73 std::vector
<std::string
> x
;
74 if(values
.size() == 0)
75 throw std::runtime_error("hvalues() not valid for freetext settings");
81 std::string
core_setting::hvalue_to_ivalue(const std::string
& hvalue
) const throw(std::runtime_error
)
86 throw std::runtime_error("Invalid hvalue for setting");
89 signed core_setting::ivalue_to_index(const std::string
& ivalue
) const throw(std::runtime_error
)
94 throw std::runtime_error("Invalid ivalue for setting");