Reorder method declarations in Argument and ArgumentParser
So it becomes clear which parts might be moved to a separate class to prevent Argument from becoming to big.
This commit is contained in:
parent
64be5bce63
commit
c8bf068e74
|
@ -184,6 +184,14 @@ public:
|
||||||
Argument(const char *name, char abbreviation = '\0', const char *description = nullptr, const char *example = nullptr);
|
Argument(const char *name, char abbreviation = '\0', const char *description = nullptr, const char *example = nullptr);
|
||||||
~Argument();
|
~Argument();
|
||||||
|
|
||||||
|
// declare getter/setter/properties/operations for argument definition:
|
||||||
|
// - those properties must be set *before* parsing
|
||||||
|
// - they control the behaviour of the parser, eg.
|
||||||
|
// - the name/abbreviation to look for
|
||||||
|
// - constraints to be checked
|
||||||
|
// - callbacks to be invoked
|
||||||
|
// TODO v5: It would make sense to move these to a separate class (eg. ArgumentDefinition) to prevent this one from
|
||||||
|
// becoming to big.
|
||||||
const char *name() const;
|
const char *name() const;
|
||||||
void setName(const char *name);
|
void setName(const char *name);
|
||||||
char abbreviation() const;
|
char abbreviation() const;
|
||||||
|
@ -194,19 +202,11 @@ public:
|
||||||
void setDescription(const char *description);
|
void setDescription(const char *description);
|
||||||
const char *example() const;
|
const char *example() const;
|
||||||
void setExample(const char *example);
|
void setExample(const char *example);
|
||||||
const std::vector<const char *> &values(std::size_t occurrence = 0) const;
|
|
||||||
const char *firstValue() const;
|
|
||||||
std::size_t requiredValueCount() const;
|
std::size_t requiredValueCount() const;
|
||||||
void setRequiredValueCount(std::size_t requiredValueCount);
|
void setRequiredValueCount(std::size_t requiredValueCount);
|
||||||
const std::vector<const char *> &valueNames() const;
|
const std::vector<const char *> &valueNames() const;
|
||||||
void setValueNames(std::initializer_list<const char *> valueNames);
|
void setValueNames(std::initializer_list<const char *> valueNames);
|
||||||
void appendValueName(const char *valueName);
|
void appendValueName(const char *valueName);
|
||||||
bool allRequiredValuesPresent(std::size_t occurrence = 0) const;
|
|
||||||
bool isPresent() const;
|
|
||||||
std::size_t occurrences() const;
|
|
||||||
std::size_t index(std::size_t occurrence) const;
|
|
||||||
std::size_t minOccurrences() const;
|
|
||||||
std::size_t maxOccurrences() const;
|
|
||||||
void setConstraints(std::size_t minOccurrences, std::size_t maxOccurrences);
|
void setConstraints(std::size_t minOccurrences, std::size_t maxOccurrences);
|
||||||
const std::vector<Argument *> &path(std::size_t occurrence = 0) const;
|
const std::vector<Argument *> &path(std::size_t occurrence = 0) const;
|
||||||
bool isRequired() const;
|
bool isRequired() const;
|
||||||
|
@ -219,25 +219,37 @@ public:
|
||||||
void setDenotesOperation(bool denotesOperation);
|
void setDenotesOperation(bool denotesOperation);
|
||||||
const CallbackFunction &callback() const;
|
const CallbackFunction &callback() const;
|
||||||
void setCallback(CallbackFunction callback);
|
void setCallback(CallbackFunction callback);
|
||||||
void printInfo(std::ostream &os, unsigned char indentation = 0) const;
|
|
||||||
const ArgumentVector &subArguments() const;
|
const ArgumentVector &subArguments() const;
|
||||||
void setSubArguments(const ArgumentInitializerList &subArguments);
|
void setSubArguments(const ArgumentInitializerList &subArguments);
|
||||||
void addSubArgument(Argument *arg);
|
void addSubArgument(Argument *arg);
|
||||||
bool hasSubArguments() const;
|
bool hasSubArguments() const;
|
||||||
const ArgumentVector parents() const;
|
const ArgumentVector parents() const;
|
||||||
bool isMainArgument() const;
|
void printInfo(std::ostream &os, unsigned char indentation = 0) const;
|
||||||
bool isParentPresent() const;
|
|
||||||
|
// declare getter/setter/properties for bash completion: those properties must be set *before parsing
|
||||||
ValueCompletionBehavior valueCompletionBehaviour() const;
|
ValueCompletionBehavior valueCompletionBehaviour() const;
|
||||||
void setValueCompletionBehavior(ValueCompletionBehavior valueCompletionBehaviour);
|
void setValueCompletionBehavior(ValueCompletionBehavior valueCompletionBehaviour);
|
||||||
const char *preDefinedCompletionValues() const;
|
const char *preDefinedCompletionValues() const;
|
||||||
void setPreDefinedCompletionValues(const char *preDefinedCompletionValues);
|
void setPreDefinedCompletionValues(const char *preDefinedCompletionValues);
|
||||||
|
|
||||||
|
// declare getter/read-only properties for parsing results: those properties will be populated when parsing
|
||||||
|
const std::vector<const char *> &values(std::size_t occurrence = 0) const;
|
||||||
|
const char *firstValue() const;
|
||||||
|
bool allRequiredValuesPresent(std::size_t occurrence = 0) const;
|
||||||
|
bool isPresent() const;
|
||||||
|
std::size_t occurrences() const;
|
||||||
|
std::size_t index(std::size_t occurrence) const;
|
||||||
|
std::size_t minOccurrences() const;
|
||||||
|
std::size_t maxOccurrences() const;
|
||||||
|
bool isMainArgument() const;
|
||||||
|
bool isParentPresent() const;
|
||||||
Argument *conflictsWithArgument() const;
|
Argument *conflictsWithArgument() const;
|
||||||
Argument *wouldConflictWithArgument() const;
|
Argument *wouldConflictWithArgument() const;
|
||||||
Argument *specifiedOperation() const;
|
Argument *specifiedOperation() const;
|
||||||
void reset();
|
|
||||||
void resetRecursively();
|
|
||||||
const std::vector<ArgumentOccurrence> &occurrenceInfo() const;
|
const std::vector<ArgumentOccurrence> &occurrenceInfo() const;
|
||||||
std::vector<ArgumentOccurrence> &occurrenceInfo();
|
std::vector<ArgumentOccurrence> &occurrenceInfo();
|
||||||
|
void reset();
|
||||||
|
void resetRecursively();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Denotes a variable number of values.
|
* \brief Denotes a variable number of values.
|
||||||
|
@ -246,6 +258,7 @@ public:
|
||||||
static constexpr std::size_t varValueCount = std::numeric_limits<std::size_t>::max();
|
static constexpr std::size_t varValueCount = std::numeric_limits<std::size_t>::max();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// declare internal getter/setter/properties/operations for argument definition
|
||||||
bool matchesDenotation(const char *denotation, size_t denotationLength) const;
|
bool matchesDenotation(const char *denotation, size_t denotationLength) const;
|
||||||
|
|
||||||
const char *m_name;
|
const char *m_name;
|
||||||
|
@ -276,9 +289,12 @@ class CPP_UTILITIES_EXPORT ArgumentParser {
|
||||||
public:
|
public:
|
||||||
ArgumentParser();
|
ArgumentParser();
|
||||||
|
|
||||||
|
// declare getter/setter for argument definitions
|
||||||
const ArgumentVector &mainArguments() const;
|
const ArgumentVector &mainArguments() const;
|
||||||
void setMainArguments(const ArgumentInitializerList &mainArguments);
|
void setMainArguments(const ArgumentInitializerList &mainArguments);
|
||||||
void addMainArgument(Argument *argument);
|
void addMainArgument(Argument *argument);
|
||||||
|
|
||||||
|
// declare operations which will consider previously assigned argument definitions and maybe modify parsing results
|
||||||
void printHelp(std::ostream &os) const;
|
void printHelp(std::ostream &os) const;
|
||||||
void parseArgs(int argc, const char *const *argv);
|
void parseArgs(int argc, const char *const *argv);
|
||||||
void parseArgsOrExit(int argc, const char *const *argv);
|
void parseArgsOrExit(int argc, const char *const *argv);
|
||||||
|
@ -287,6 +303,10 @@ public:
|
||||||
= ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks | ParseArgumentBehavior::ExitOnFailure);
|
= ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks | ParseArgumentBehavior::ExitOnFailure);
|
||||||
void readArgs(int argc, const char *const *argv);
|
void readArgs(int argc, const char *const *argv);
|
||||||
void resetArgs();
|
void resetArgs();
|
||||||
|
void checkConstraints();
|
||||||
|
void invokeCallbacks();
|
||||||
|
|
||||||
|
// declare getter for parsing results
|
||||||
unsigned int actualArgumentCount() const;
|
unsigned int actualArgumentCount() const;
|
||||||
const char *executable() const;
|
const char *executable() const;
|
||||||
UnknownArgumentBehavior unknownArgumentBehavior() const;
|
UnknownArgumentBehavior unknownArgumentBehavior() const;
|
||||||
|
@ -294,11 +314,10 @@ public:
|
||||||
Argument *defaultArgument() const;
|
Argument *defaultArgument() const;
|
||||||
void setDefaultArgument(Argument *argument);
|
void setDefaultArgument(Argument *argument);
|
||||||
Argument *specifiedOperation() const;
|
Argument *specifiedOperation() const;
|
||||||
void checkConstraints();
|
|
||||||
void invokeCallbacks();
|
|
||||||
bool isUncombinableMainArgPresent() const;
|
bool isUncombinableMainArgPresent() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// declare internal operations
|
||||||
IF_DEBUG_BUILD(void verifyArgs(const ArgumentVector &args);)
|
IF_DEBUG_BUILD(void verifyArgs(const ArgumentVector &args);)
|
||||||
void printBashCompletion(int argc, const char *const *argv, unsigned int cursorPos, const ArgumentReader &reader);
|
void printBashCompletion(int argc, const char *const *argv, unsigned int cursorPos, const ArgumentReader &reader);
|
||||||
void checkConstraints(const ArgumentVector &args);
|
void checkConstraints(const ArgumentVector &args);
|
||||||
|
@ -734,6 +753,8 @@ inline bool Argument::hasSubArguments() const
|
||||||
*
|
*
|
||||||
* If this argument is used as a main argument shouldn't be used as
|
* If this argument is used as a main argument shouldn't be used as
|
||||||
* secondary argument at the same time and thus have no parents.
|
* secondary argument at the same time and thus have no parents.
|
||||||
|
*
|
||||||
|
* \todo Return by reference in v5.
|
||||||
*/
|
*/
|
||||||
inline const ArgumentVector Argument::parents() const
|
inline const ArgumentVector Argument::parents() const
|
||||||
{
|
{
|
||||||
|
@ -791,6 +812,8 @@ inline void Argument::setPreDefinedCompletionValues(const char *preDefinedComple
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Resets occurrences (indices, values and paths).
|
* \brief Resets occurrences (indices, values and paths).
|
||||||
|
*
|
||||||
|
* So parsing results are wiped while the argument definition is preserved.
|
||||||
*/
|
*/
|
||||||
inline void Argument::reset()
|
inline void Argument::reset()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue