From 9bc4c477e39725d6031a601f5341363bcbf54646 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Sat, 16 Jul 2016 03:44:22 -0600 Subject: fix many bugs, add tests for terminator --- args.hxx | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'args.hxx') diff --git a/args.hxx b/args.hxx index 8deb71b..7be2305 100644 --- a/args.hxx +++ b/args.hxx @@ -574,6 +574,15 @@ namespace args } virtual void ParseValue(const std::string &value) = 0; + + virtual void Reset() noexcept override + { + matched = false; + ready = true; +#ifdef ARGS_NOEXCEPT + error = Error::None; +#endif + } }; /** Class for all kinds of validating groups, including ArgumentParser @@ -686,7 +695,7 @@ namespace args { next = group->GetNextPositional(); } - if (next and next->Ready()) + if (next && next->Ready()) { return next; } @@ -1162,7 +1171,7 @@ namespace args { const auto &chunk = *it; - if (!terminated and chunk == terminator) + if (!terminated && chunk == terminator) { terminated = true; // If a long arg was found @@ -1475,10 +1484,11 @@ namespace args class CounterFlag : public Flag { private: + const int startcount; int count; public: - CounterFlag(Group &group, const std::string &name, const std::string &help, Matcher &&matcher, const int startcount = 0): Flag(group, name, help, std::move(matcher)), count(startcount) {} + CounterFlag(Group &group, const std::string &name, const std::string &help, Matcher &&matcher, const int startcount = 0): Flag(group, name, help, std::move(matcher)), startcount(startcount), count(startcount) {} virtual ~CounterFlag() {} @@ -1508,6 +1518,12 @@ namespace args { return count; } + + virtual void Reset() noexcept override + { + FlagBase::Reset(); + count = startcount; + } }; /** A default Reader class for argument classes @@ -1645,6 +1661,12 @@ namespace args { return name + std::string("..."); } + + virtual void Reset() noexcept override + { + ValueFlagBase::Reset(); + values.clear(); + } }; /** A mapping value flag class @@ -1778,6 +1800,12 @@ namespace args { return name + std::string("..."); } + + virtual void Reset() noexcept override + { + ValueFlagBase::Reset(); + values.clear(); + } }; /** A positional argument class @@ -1873,6 +1901,12 @@ namespace args { return values; } + + virtual void Reset() noexcept override + { + PositionalBase::Reset(); + values.clear(); + } }; /** A positional argument mapping class @@ -2009,5 +2043,11 @@ namespace args { return name + std::string("..."); } + + virtual void Reset() noexcept override + { + PositionalBase::Reset(); + values.clear(); + } }; } -- cgit v1.2.1