C++ Utilities
4.13.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
The ArgumentParser class provides a means for handling command line arguments. More...
#include <argumentparser.h>
Public Member Functions | |
ArgumentParser () | |
Constructs a new ArgumentParser. More... | |
const ArgumentVector & | mainArguments () const |
Returns the main arguments. More... | |
void | setMainArguments (const ArgumentInitializerList &mainArguments) |
Sets the main arguments for the parser. More... | |
void | addMainArgument (Argument *argument) |
Adds the specified argument to the main argument. More... | |
void | printHelp (std::ostream &os) const |
Prints help text for all assigned arguments. More... | |
void | parseArgs (int argc, const char *const *argv) |
Parses the specified command line arguments. More... | |
void | parseArgsOrExit (int argc, const char *const *argv) |
Parses the specified command line arguments. More... | |
void | parseArgsExt (int argc, const char *const *argv, ParseArgumentBehavior behavior=ParseArgumentBehavior::CheckConstraints|ParseArgumentBehavior::InvokeCallbacks|ParseArgumentBehavior::ExitOnFailure) |
Parses the specified command line arguments. More... | |
void | readArgs (int argc, const char *const *argv) |
Parses the specified command line arguments. More... | |
void | resetArgs () |
Resets all Argument instances assigned as mainArguments() and sub arguments. More... | |
unsigned int | actualArgumentCount () const |
Returns the actual number of arguments that could be found when parsing. More... | |
const char * | executable () const |
Returns the name of the current executable. More... | |
UnknownArgumentBehavior | unknownArgumentBehavior () const |
Returns how unknown arguments are treated. More... | |
void | setUnknownArgumentBehavior (UnknownArgumentBehavior behavior) |
Sets how unknown arguments are treated. More... | |
Argument * | defaultArgument () const |
Returns the default argument. More... | |
void | setDefaultArgument (Argument *argument) |
Sets the default argument. More... | |
Argument * | specifiedOperation () const |
Returns the first operation argument specified by the user or nullptr if no operation has been specified. More... | |
void | checkConstraints () |
Checks whether contraints are violated. More... | |
void | invokeCallbacks () |
Invokes all assigned callbacks. More... | |
bool | isUncombinableMainArgPresent () const |
Checks whether at least one uncombinable main argument is present. More... | |
The ArgumentParser class provides a means for handling command line arguments.
To setup the parser create instances of ApplicationUtilities::Argument to define a set of known arguments and assign these to the parser using setMainArguments().
To invoke parsing call parseArgs(). The parser will verify the previously assigned definitions (and might throw std::invalid_argument) and then parse the given command line arguments according the definitions (and might throw ApplicationUtilities::Failure).
Definition at line 272 of file argumentparser.h.
ApplicationUtilities::ArgumentParser::ArgumentParser | ( | ) |
Constructs a new ArgumentParser.
Definition at line 634 of file argumentparser.cpp.
|
inline |
Returns the actual number of arguments that could be found when parsing.
Definition at line 832 of file argumentparser.h.
void ApplicationUtilities::ArgumentParser::addMainArgument | ( | Argument * | argument | ) |
Adds the specified argument to the main argument.
Definition at line 683 of file argumentparser.cpp.
|
inline |
Checks whether contraints are violated.
Throws | Failure if constraints are violated. |
Definition at line 888 of file argumentparser.h.
|
inline |
Returns the default argument.
Definition at line 869 of file argumentparser.h.
|
inline |
Returns the name of the current executable.
Definition at line 840 of file argumentparser.h.
|
inline |
Invokes all assigned callbacks.
Definition at line 897 of file argumentparser.h.
bool ApplicationUtilities::ArgumentParser::isUncombinableMainArgPresent | ( | ) | const |
Checks whether at least one uncombinable main argument is present.
Definition at line 929 of file argumentparser.cpp.
|
inline |
Returns the main arguments.
Definition at line 824 of file argumentparser.h.
void ApplicationUtilities::ArgumentParser::parseArgs | ( | int | argc, |
const char *const * | argv | ||
) |
Parses the specified command line arguments.
Throws | Failure if the specified arguments are invalid or violate the constraints defined by the Argument instances. |
Definition at line 772 of file argumentparser.cpp.
void ApplicationUtilities::ArgumentParser::parseArgsExt | ( | int | argc, |
const char *const * | argv, | ||
ParseArgumentBehavior | behavior = ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks | ParseArgumentBehavior::ExitOnFailure |
||
) |
Parses the specified command line arguments.
The behavior is configurable by specifying the behavior argument. See ParseArgumentBehavior for the options. By default, all options are present.
Throws | Failure if the specified arguments are invalid and the ParseArgumentBehavior::ExitOnFailure flag is not present. |
Definition at line 808 of file argumentparser.cpp.
void ApplicationUtilities::ArgumentParser::parseArgsOrExit | ( | int | argc, |
const char *const * | argv | ||
) |
Parses the specified command line arguments.
Definition at line 786 of file argumentparser.cpp.
void ApplicationUtilities::ArgumentParser::printHelp | ( | std::ostream & | os | ) | const |
Prints help text for all assigned arguments.
Definition at line 692 of file argumentparser.cpp.
void ApplicationUtilities::ArgumentParser::readArgs | ( | int | argc, |
const char *const * | argv | ||
) |
Parses the specified command line arguments.
Throws | Failure if the specified arguments are invalid. |
Definition at line 844 of file argumentparser.cpp.
void ApplicationUtilities::ArgumentParser::resetArgs | ( | ) |
Resets all Argument instances assigned as mainArguments() and sub arguments.
Definition at line 903 of file argumentparser.cpp.
|
inline |
Sets the default argument.
Definition at line 878 of file argumentparser.h.
void ApplicationUtilities::ArgumentParser::setMainArguments | ( | const ArgumentInitializerList & | mainArguments | ) |
Sets the main arguments for the parser.
The parser will use these argument definitions to when parsing the command line arguments and when printing help information.
Definition at line 651 of file argumentparser.cpp.
|
inline |
Sets how unknown arguments are treated.
The default value is UnknownArgumentBehavior::Fail.
Definition at line 860 of file argumentparser.h.
Argument * ApplicationUtilities::ArgumentParser::specifiedOperation | ( | ) | const |
Returns the first operation argument specified by the user or nullptr if no operation has been specified.
Definition at line 916 of file argumentparser.cpp.
|
inline |
Returns how unknown arguments are treated.
The default value is UnknownArgumentBehavior::Fail.
Definition at line 850 of file argumentparser.h.