- template<typename T> T get_option_value(const std::string& optionName);
- Options::iterator option_from_name(const std::string& optionName);
+ Options::iterator option_with_name(const std::string& optionName);
+
+ // stringify converts a value of type T to a std::string
+ template<typename T>
+ std::string stringify(const T& v) {
+
+ std::ostringstream ss;
+ ss << v;
+ return ss.str();
+ }
+
+ // We want conversion from a bool value to be "true" or "false",
+ // not "1" or "0", so add a specialization for bool type.
+ template<>
+ std::string stringify<bool>(const bool& v) {
+
+ return v ? "true" : "false";
+ }
+
+ // get_option_value implements the various get_option_value_<type>
+ // functions defined later, because only the option value
+ // type changes a template seems a proper solution.
+
+ template<typename T>
+ T get_option_value(const std::string& optionName) {
+
+ T ret = T();
+ Options::iterator it = option_with_name(optionName);
+
+ if (it != options.end())
+ {
+ std::istringstream ss(it->currentValue);
+ ss >> ret;
+ } else
+ assert(false);
+
+ return ret;
+ }