Command line parser. More...
#include <CommandLine.h>
Public Member Functions | |
CommandLine (int argc, char *const argv[]) | |
Default constructor. | |
void | printUsage () const |
Print command line synopsis. | |
const char * | dbUser () const |
Returns database username. | |
const char * | dbPasswd () const |
Returns database password. | |
const char * | dbServer () const |
Returns database server address. | |
int | debugLevel () |
Returns debug log level. | |
bool | isFault () |
Returns parse exit status. | |
Protected Member Functions | |
const char * | optionArgument () const |
Returns the expected value of an option. | |
int | parseNext () const |
Returns success of current option parse. | |
void | parseError () |
Print an error message (syntax error). | |
Private Attributes | |
bool | _fault |
int | _argc |
char *const * | _argv |
const char * | _opts |
const char * | _password |
const char * | _user |
const char * | _server |
int | _debug |
Command line parser.
The class CommandLine is an helper class used to parse command line arguments passed to the executable. The main usage of the class is suggested by its constructor, which expects two parameters, the argc and argv of the main(), the entry point of any program.
As instantiated, the analysis of the parameters takes place: whenever the parser finds a syntax error or a misuse of the above specifiers, parse immediately stops and the private variable _fault is set to true, indicating the presence of an error. Whenever an error is found, an help message is displayed to the user, with the expected syntax to be used.
CommandLine::CommandLine | ( | int | argc, | |
char *const | argv[] | |||
) |
Default constructor.
As instantiated, the analysis of the parameters takes place: whenever the parser finds a syntax error or a misuse of the above specifiers, parse immediately stops and the private variable _fault is set to true, indicating the presence of an error.
[in] | argc | Number of available arguments |
[in] | argv | Array of parameters |
References _debug, _fault, _password, _server, _user, optionArgument(), parseError(), and parseNext().
const char * CommandLine::dbPasswd | ( | ) | const |
const char * CommandLine::dbServer | ( | ) | const |
const char * CommandLine::dbUser | ( | ) | const |
int CommandLine::debugLevel | ( | ) |
bool CommandLine::isFault | ( | ) |
const char * CommandLine::optionArgument | ( | ) | const [protected] |
Returns the expected value of an option.
Referenced by CommandLine().
void CommandLine::parseError | ( | ) | [protected] |
Print an error message (syntax error).
References _fault, and printUsage().
Referenced by CommandLine().
int CommandLine::parseNext | ( | ) | const [protected] |
Returns success of current option parse.
References _argc, _argv, and _opts.
Referenced by CommandLine().
void CommandLine::printUsage | ( | ) | const |
Print command line synopsis.
Referenced by parseError().
int CommandLine::_argc [private] |
Referenced by parseNext().
char* const* CommandLine::_argv [private] |
Referenced by parseNext().
int CommandLine::_debug [private] |
Referenced by CommandLine(), and debugLevel().
bool CommandLine::_fault [private] |
Referenced by CommandLine(), dbPasswd(), dbServer(), dbUser(), isFault(), and parseError().
const char* CommandLine::_opts [private] |
Referenced by parseNext().
const char* CommandLine::_password [private] |
Referenced by CommandLine(), and dbPasswd().
const char* CommandLine::_server [private] |
Referenced by CommandLine(), and dbServer().
const char* CommandLine::_user [private] |
Referenced by CommandLine(), and dbUser().