| 235 | }; |
| 236 | |
| 237 | class Option final |
| 238 | : public LeafPattern |
| 239 | { |
| 240 | public: |
| 241 | static Option parse(std::string const& option_description); |
| 242 | |
| 243 | Option(std::string shortOption, |
| 244 | std::string longOption, |
| 245 | int argcount = 0, |
| 246 | value v = value{false}) |
| 247 | : LeafPattern(longOption.empty() ? shortOption : longOption, |
| 248 | std::move(v)), |
| 249 | fShortOption(std::move(shortOption)), |
| 250 | fLongOption(std::move(longOption)), |
| 251 | fArgcount(argcount) |
| 252 | { |
| 253 | // From Python: |
| 254 | // self.value = None if value is False and argcount else value |
| 255 | if (argcount && v.isBool() && !v.asBool()) { |
| 256 | setValue(value{}); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | Option(Option const&) = default; |
| 261 | Option(Option&&) = default; |
| 262 | Option& operator=(Option const&) = default; |
| 263 | Option& operator=(Option&&) = default; |
| 264 | |
| 265 | using LeafPattern::setValue; |
| 266 | |
| 267 | std::string const& longOption() const { return fLongOption; } |
| 268 | std::string const& shortOption() const { return fShortOption; } |
| 269 | int argCount() const { return fArgcount; } |
| 270 | |
| 271 | virtual size_t hash() const override { |
| 272 | size_t seed = LeafPattern::hash(); |
| 273 | hash_combine(seed, fShortOption); |
| 274 | hash_combine(seed, fLongOption); |
| 275 | hash_combine(seed, fArgcount); |
| 276 | return seed; |
| 277 | } |
| 278 | |
| 279 | protected: |
| 280 | virtual std::pair<size_t, std::shared_ptr<LeafPattern>> single_match(PatternList const& left) const override; |
| 281 | |
| 282 | private: |
| 283 | std::string fShortOption; |
| 284 | std::string fLongOption; |
| 285 | int fArgcount; |
| 286 | }; |
| 287 | |
| 288 | class Required : public BranchPattern { |
| 289 | public: |
nothing calls this directly
no outgoing calls
no test coverage detected