CommandLine Class Reference

Command line parser. More...

#include <CommandLine.h>

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

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.

Parameters:
[in] argc Number of available arguments
[in] argv Array of parameters

References _debug, _fault, _password, _server, _user, optionArgument(), parseError(), and parseNext().


Member Function Documentation

const char * CommandLine::dbPasswd (  )  const

Returns database password.

Returns:
A string representing database password

References _fault, and _password.

Referenced by main().

const char * CommandLine::dbServer (  )  const

Returns database server address.

Returns:
A string representing database server address

References _fault, and _server.

Referenced by main().

const char * CommandLine::dbUser (  )  const

Returns database username.

Returns:
A string representing database username

References _fault, and _user.

Referenced by main().

int CommandLine::debugLevel (  ) 

Returns debug log level.

Returns:
An integer representing debug level

References _debug.

Referenced by main().

bool CommandLine::isFault (  ) 

Returns parse exit status.

Returns:
True if no syntax errors were detected

References _fault.

Referenced by main().

const char * CommandLine::optionArgument (  )  const [protected]

Returns the expected value of an option.

Returns:
A string representing the option value

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.

Returns:
EOF if there are no more parameters to parse

References _argc, _argv, and _opts.

Referenced by CommandLine().

void CommandLine::printUsage (  )  const

Print command line synopsis.

Referenced by parseError().


Member Data Documentation

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]
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().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2