diff options
Diffstat (limited to 'framework/command_line')
-rw-r--r-- | framework/command_line/EnumListOption.h | 21 | ||||
-rw-r--r-- | framework/command_line/ListOption.h | 20 |
2 files changed, 20 insertions, 21 deletions
diff --git a/framework/command_line/EnumListOption.h b/framework/command_line/EnumListOption.h index 41c5b6ee85..d19bfbdc0f 100644 --- a/framework/command_line/EnumListOption.h +++ b/framework/command_line/EnumListOption.h @@ -85,17 +85,21 @@ bool EnumListOption<T>::parse(std::string value) { // Remove default values _values.clear(); + _is_set = true; try { std::stringstream stream{ value }; - T typed_value{}; + std::string item; - while(stream.good()) + while(!std::getline(stream, item, ',').fail()) { - stream >> typed_value; + std::stringstream item_stream(item); + T typed_value{}; - if(!stream.fail()) + item_stream >> typed_value; + + if(!item_stream.fail()) { if(_allowed_values.count(typed_value) == 0) { @@ -106,14 +110,9 @@ bool EnumListOption<T>::parse(std::string value) _values.emplace_back(typed_value); } - if(!stream.eof()) - { - stream.ignore(1, ','); - } + _is_set = _is_set && !item_stream.fail(); } - _is_set = !stream.fail(); - return _is_set; } catch(const std::invalid_argument &) @@ -133,7 +132,7 @@ std::string EnumListOption<T>::help() const msg << value << ","; } - msg << "} - " << _help; + msg << "}[,{...}[,...]] - " << _help; return msg.str(); } diff --git a/framework/command_line/ListOption.h b/framework/command_line/ListOption.h index f867ef804c..8b1bb3d05a 100644 --- a/framework/command_line/ListOption.h +++ b/framework/command_line/ListOption.h @@ -69,28 +69,28 @@ inline ListOption<T>::ListOption(std::string name, std::initializer_list<T> &&de template <typename T> bool ListOption<T>::parse(std::string value) { + _is_set = true; + try { std::stringstream stream{ value }; - T typed_value{}; + std::string item; - while(stream.good()) + while(!std::getline(stream, item, ',').fail()) { - stream >> typed_value; + std::stringstream item_stream(item); + T typed_value{}; + + item_stream >> typed_value; - if(!stream.fail()) + if(!item_stream.fail()) { _values.emplace_back(typed_value); } - if(!stream.eof()) - { - stream.ignore(1, ','); - } + _is_set = _is_set && !item_stream.fail(); } - _is_set = !stream.fail(); - return _is_set; } catch(const std::invalid_argument &) |