OptionParser Class Reference

Generic option parser. More...

#include <OptionParser.h>

List of all members.

Public Member Functions

 OptionParser (const char *progname)
 Constructor: expects a string containing the name of the calling program.
bool addOption (char sn, const char *ln, const char *hm, bool hasArg=false)
 Add a new option to the list.
bool removeOption (const char *ln)
 Remove an option from the list.
int findOption (const char *ln, bool shortName=false) const
 Find the option in the list.
int addArgument (const char *name, const char *help, bool mandatory=true)
 Add a new argument to the argumet list.
void clearArguments ()
 Clear the argument list.
bool parse (int argc, const char **argv, StringMap &opts, ArrayList &args)
 Parse the command line.
void usage ()
 Print the usage message.
const StringBuffer & getErrMsg () const
 get error message as a StringBuffer
const StringBuffer & getProgramName () const

Private Attributes

StringBuffer programName
 The program name, used in the usage page.
ArrayList options
 A list of Option objects, representing the options supported by the program.
ArrayList arguments
 A map of arguments, with the name of the arg and the help message This is used only for the usage page.
StringBuffer errMsg
 error string


Detailed Description

Generic option parser.

Member Function Documentation

int OptionParser::addArgument ( const char *  name,
const char *  help,
bool  mandatory = true 
)

Add a new argument to the argumet list.

Parameters:
name the name of the argument
help an help message true if the option argument is mandatory (default=true)
Returns:
true if the argument has been added to the list, false in case of error.

bool OptionParser::addOption ( char  sn,
const char *  ln,
const char *  hm,
bool  hasArg = false 
)

Add a new option to the list.

Parameters:
sn the short name of the option (one letter) ln the long name of the option
hm an help message (one line) true if the option requires an argument (default=false)
Returns:
true if the option has been added to the list, false in case of error.

int OptionParser::findOption ( const char *  ln,
bool  shortName = false 
) const

Find the option in the list.

Parameters:
ln the long name of the option to remove
Returns:
the position of the option in the list, -1 if not found.

bool OptionParser::parse ( int  argc,
const char **  argv,
StringMap &  opts,
ArrayList &  args 
)

Parse the command line.

Parameters:
argc the argc parameter, same as the one of the main() function
argv the argv parameter, same as the one of the main() function
OUT an ArrayList of KeyValuePair containing the options found on the commandline
OUT an ArrayList of StringBuffer containing the other arguments found on the commandline
Returns:
true on success, false on error

bool OptionParser::removeOption ( const char *  ln  ) 

Remove an option from the list.

Parameters:
ln the long name of the option to remove
Returns:
true if the option has been removed from the list false in case of error.


Member Data Documentation

ArrayList OptionParser::arguments [private]

A map of arguments, with the name of the arg and the help message This is used only for the usage page.

The arguments are positional and there is no syntax checking on them.

StringBuffer OptionParser::programName [private]

The program name, used in the usage page.


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

Generated on Tue Apr 6 13:00:42 2010 for Funambol Outlook Plug-in Library by  doxygen 1.5.7.1