From 70869f24a873de9912416b2f3a5a0f350039c2ab Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 26 Nov 2016 00:11:48 +0100 Subject: [PATCH] Add method to reset arguments recursively --- application/argumentparser.cpp | 23 +++++++++++++++++++++++ application/argumentparser.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index 319ec13..7dec1da 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -282,6 +282,18 @@ Argument *Argument::wouldConflictWithArgument() const return nullptr; } +/*! + * \brief Resets this argument and all sub arguments recursively. + * \sa Argument::reset() + */ +void Argument::resetRecursively() +{ + for(Argument *arg : m_subArgs) { + arg->resetRecursively(); + } + reset(); +} + /*! * \class ApplicationUtilities::ArgumentParser * \brief The ArgumentParser class provides a means for handling command line arguments. @@ -463,6 +475,17 @@ void ArgumentParser::readArgs(int argc, const char * const *argv) } } +/*! + * \brief Resets all Argument instances assigned as mainArguments() and sub arguments. + * \sa Argument::reset() + */ +void ArgumentParser::resetArgs() +{ + for(Argument *arg : m_mainArgs) { + arg->resetRecursively(); + } +} + /*! * \brief Checks whether at least one uncombinable main argument is present. */ diff --git a/application/argumentparser.h b/application/argumentparser.h index c07f456..62a166e 100644 --- a/application/argumentparser.h +++ b/application/argumentparser.h @@ -185,6 +185,7 @@ public: Argument *conflictsWithArgument() const; Argument *wouldConflictWithArgument() const; void reset(); + void resetRecursively(); private: const char *m_name; @@ -220,6 +221,7 @@ public: void printHelp(std::ostream &os) const; void parseArgs(int argc, const char *const *argv); void readArgs(int argc, const char *const *argv); + void resetArgs(); unsigned int actualArgumentCount() const; const char *executable() const; UnknownArgumentBehavior unknownArgumentBehavior() const;