| 88 | |
| 89 | template <typename T> |
| 90 | bool EnumListOption<T>::parse(std::string value) |
| 91 | { |
| 92 | // Remove default values |
| 93 | _values.clear(); |
| 94 | _is_set = true; |
| 95 | |
| 96 | std::stringstream stream{value}; |
| 97 | std::string item; |
| 98 | |
| 99 | while (!std::getline(stream, item, ',').fail()) |
| 100 | { |
| 101 | try |
| 102 | { |
| 103 | std::stringstream item_stream(item); |
| 104 | T typed_value{}; |
| 105 | |
| 106 | item_stream >> typed_value; |
| 107 | |
| 108 | if (!item_stream.fail()) |
| 109 | { |
| 110 | if (_allowed_values.count(typed_value) == 0) |
| 111 | { |
| 112 | _is_set = false; |
| 113 | continue; |
| 114 | } |
| 115 | |
| 116 | _values.emplace_back(typed_value); |
| 117 | } |
| 118 | |
| 119 | _is_set = _is_set && !item_stream.fail(); |
| 120 | } |
| 121 | catch (const std::invalid_argument &) |
| 122 | { |
| 123 | _is_set = false; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return _is_set; |
| 128 | } |
| 129 | |
| 130 | template <typename T> |
| 131 | std::string EnumListOption<T>::help() const |