diff --git a/src/commands.cc b/src/commands.cc index 6dce3986..fc315fd3 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -479,6 +479,8 @@ void declare_option(const CommandParameters& params, Context& context) opt = &GlobalOptions::instance().declare_option(params[1], 0); else if (params[0] == "str") opt = &GlobalOptions::instance().declare_option(params[1], ""); + else if (params[0] == "int-list") + opt = &GlobalOptions::instance().declare_option>(params[1], {}); else throw runtime_error("unknown type " + params[0]); diff --git a/src/option_manager.cc b/src/option_manager.cc index 5f070ad8..817d5409 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -26,6 +26,32 @@ void option_from_string(const String& str, bool& opt) throw runtime_error("boolean values are either true, yes, false or no"); } +template +String option_to_string(const std::vector& opt) +{ + String res; + for (size_t i = 0; i < opt.size(); ++i) + { + res += option_to_string(opt[i]); + if (i != opt.size() - 1) + res += ","; + } + return res; +} + +template +void option_from_string(const String& str, std::vector& opt) +{ + opt.clear(); + std::vector elems = split(str, ','); + for (auto& elem: elems) + { + T opt_elem; + option_from_string(elem, opt_elem); + opt.push_back(opt_elem); + } +} + } template @@ -79,6 +105,8 @@ template void Option::set(const int&); template const bool& Option::get() const; template void Option::set(const bool&); +template const std::vector& Option::get>() const; +template void Option::set>(const std::vector&); OptionManager::OptionManager(OptionManager& parent) : m_parent(&parent) @@ -205,4 +233,6 @@ Option& GlobalOptions::declare_option(const String& name, const T& value) return *m_options.back(); } +template Option& GlobalOptions::declare_option<>(const String&, const std::vector&); + }