CommandlineParser Class Reference
Public Member Functions | |
| CommandlineParser (const std::string &programName="") | |
| Default constructor which does nothing fancy at all. | |
| ~CommandlineParser () | |
| The destructor will also delete all the contained classes within. | |
| void | setCommandLine (int argc, char **argv) |
| Sets the commandline given from the main method. | |
| void | setCommandLine (std::vector< std::string > arguments) |
| Sets the commandline given from the main method. | |
| void | execute () |
| Parses the commandline, evaluates all the commands and executes them. | |
| void | addCommand (Command *cmd) throw (VoreenException) |
| Add a new command to the parser. | |
| void | addCommandForNamelessArguments (Command *cmd) throw (VoreenException) |
| Add a new command to take care of the nameless arguments. | |
| std::string | getProgramPath () const |
| Returns the first commandline argument containing the path and the executable name. | |
| void | setVerbosity (const bool verbosity) |
| Sets the verbosity of the commandline parser. | |
| void | displayUsage (const std::string &command="") |
| Prints the usage information to the std::cout. | |
| void | displayHelp () |
| Print the full help text to the std::cout. | |
Protected Member Functions | |
| Command * | getCommand (const std::string &shortOrLongName) |
Returns the command with a specific shortName or name. | |
| void | exitWithError (const std::string &msg, const std::string &command="") |
Bail out, display the message msg and display the usage. | |
Protected Attributes | |
| std::vector< Command * > | commands_ |
| The stored commands. | |
| Command * | commandForNamelessArguments_ |
| The command we want to use for nameless arguments. | |
| std::vector< std::string > | arguments_ |
| All the arguments passed onto this parser. | |
| std::string | programPath_ |
| The path to the program + filename. | |
| std::string | programName_ |
| The name of the program used in the. | |
| bool | verbosity_ |
| Controls the verbosity of the commandline parser in regard to execution. | |
Detailed Description
Definition at line 46 of file commandlineparser.h.
Constructor & Destructor Documentation
| CommandlineParser | ( | const std::string & | programName = "" |
) |
Default constructor which does nothing fancy at all.
- Parameters:
-
programName The name of the program. Used in the
- See also:
- displayUsage and
- displayHelp methods
Definition at line 81 of file commandlineparser.cpp.
Member Function Documentation
| void addCommand | ( | Command * | cmd | ) | throw (VoreenException) |
Add a new command to the parser.
- Parameters:
-
cmd The new command
- Exceptions:
-
CommandNameAssignedTwiceException self explanatory
Definition at line 226 of file commandlineparser.cpp.
| void addCommandForNamelessArguments | ( | Command * | cmd | ) | throw (VoreenException) |
Add a new command to take care of the nameless arguments.
- Parameters:
-
cmd The command responsible for those arguments
- Exceptions:
-
CommandAlreadyAssignedException self explanatory again
Definition at line 236 of file commandlineparser.cpp.
| void displayUsage | ( | const std::string & | command = "" |
) |
Prints the usage information to the std::cout.
- Parameters:
-
command Show information for this command only, show all if empty.
Definition at line 248 of file commandlineparser.cpp.
| void execute | ( | ) |
Parses the commandline, evaluates all the commands and executes them.
The nameless command will be checked last, but executed first. Other executions might be somewhat random
Definition at line 128 of file commandlineparser.cpp.
| void exitWithError | ( | const std::string & | msg, | |
| const std::string & | command = "" | |||
| ) | [inline, protected] |
Bail out, display the message msg and display the usage.
- Parameters:
-
command Command with which the error happened.
Definition at line 293 of file commandlineparser.cpp.
| Command * getCommand | ( | const std::string & | shortOrLongName | ) | [protected] |
Returns the command with a specific shortName or name.
If no such command exists, 0 is returned
Definition at line 285 of file commandlineparser.cpp.
| void setCommandLine | ( | std::vector< std::string > | arguments | ) |
Sets the commandline given from the main method.
- Parameters:
-
arguments The arguments
Definition at line 115 of file commandlineparser.cpp.
| void setCommandLine | ( | int | argc, | |
| char ** | argv | |||
| ) |
Sets the commandline given from the main method.
- Parameters:
-
argc The number of arguments argv The arguments themself
Definition at line 102 of file commandlineparser.cpp.
| void setVerbosity | ( | const bool | verbosity | ) |
Sets the verbosity of the commandline parser.
When set, each (command,argument) pair will be printed to std::cout
Definition at line 98 of file commandlineparser.cpp.
Member Data Documentation
std::string programName_ [protected] |
The name of the program used in the.
- See also:
- usage method
Definition at line 133 of file commandlineparser.h.