Store "true" and "false" in bool options

UCI protocol uses "true" and "false" for check and button types,
so store that values instead of "1" and "0", this simplifies a
bit the code.

Also a bit strictier option's type checking in debug mode.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2010-11-20 14:23:28 +01:00
parent 358ccf206b
commit f57d51b7f3
2 changed files with 30 additions and 37 deletions

View File

@@ -27,8 +27,8 @@
class Option {
public:
Option(); // To allow insertion in a std::map
Option(const char* defaultValue, std::string type = "string");
Option() {} // To allow insertion in a std::map
Option(const char* defaultValue);
Option(bool defaultValue, std::string type = "check");
Option(int defaultValue, int minValue, int maxValue);
@@ -47,17 +47,24 @@ private:
template<typename T>
inline T Option::value() const {
assert(type != "UNDEFINED");
assert(type == "spin");
return T(atoi(currentValue.c_str()));
}
template<>
inline std::string Option::value<std::string>() const {
assert(type != "UNDEFINED");
assert(type == "string");
return currentValue;
}
template<>
inline bool Option::value<bool>() const {
assert(type == "check" || type == "button");
return currentValue == "true";
}
typedef std::map<std::string, Option> OptionsMap;
extern OptionsMap Options;