Commit eb41b032dfc4dc1cf048386e8f27746084ee0c91
1 parent
37122edb
count uses
Showing
2 changed files
with
27 additions
and
2 deletions
src/cxxopts.cpp
| @@ -101,7 +101,8 @@ Options::parse(int& argc, char**& argv) | @@ -101,7 +101,8 @@ Options::parse(int& argc, char**& argv) | ||
| 101 | if (!value->has_arg()) | 101 | if (!value->has_arg()) |
| 102 | { | 102 | { |
| 103 | auto& v = m_parsed[name]; | 103 | auto& v = m_parsed[name]; |
| 104 | - value->parse("", v); | 104 | + value->parse("", v.value); |
| 105 | + ++v.count; | ||
| 105 | } | 106 | } |
| 106 | else | 107 | else |
| 107 | { | 108 | { |
src/cxxopts.hpp
| @@ -154,6 +154,17 @@ namespace cxxopts | @@ -154,6 +154,17 @@ namespace cxxopts | ||
| 154 | std::shared_ptr<const Value> m_parser; | 154 | std::shared_ptr<const Value> m_parser; |
| 155 | }; | 155 | }; |
| 156 | 156 | ||
| 157 | + struct ParsedOption | ||
| 158 | + { | ||
| 159 | + boost::any value; | ||
| 160 | + int count; | ||
| 161 | + | ||
| 162 | + ParsedOption() | ||
| 163 | + : count(0) | ||
| 164 | + { | ||
| 165 | + } | ||
| 166 | + }; | ||
| 167 | + | ||
| 157 | class Options | 168 | class Options |
| 158 | { | 169 | { |
| 159 | public: | 170 | public: |
| @@ -164,13 +175,26 @@ namespace cxxopts | @@ -164,13 +175,26 @@ namespace cxxopts | ||
| 164 | OptionAdder | 175 | OptionAdder |
| 165 | add_options(); | 176 | add_options(); |
| 166 | 177 | ||
| 178 | + int | ||
| 179 | + count(const std::string& o) const | ||
| 180 | + { | ||
| 181 | + auto iter = m_parsed.find(o); | ||
| 182 | + | ||
| 183 | + if (iter == m_parsed.end()) | ||
| 184 | + { | ||
| 185 | + return 0; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + return iter->second.count; | ||
| 189 | + } | ||
| 190 | + | ||
| 167 | private: | 191 | private: |
| 168 | friend class OptionAdder; | 192 | friend class OptionAdder; |
| 169 | 193 | ||
| 170 | std::map<std::string, std::shared_ptr<OptionDetails>> m_short; | 194 | std::map<std::string, std::shared_ptr<OptionDetails>> m_short; |
| 171 | std::map<std::string, std::shared_ptr<OptionDetails>> m_long; | 195 | std::map<std::string, std::shared_ptr<OptionDetails>> m_long; |
| 172 | 196 | ||
| 173 | - std::map<std::string, boost::any> m_parsed; | 197 | + std::map<std::string, ParsedOption> m_parsed; |
| 174 | }; | 198 | }; |
| 175 | 199 | ||
| 176 | class OptionAdder | 200 | class OptionAdder |