Options Class Reference

Options class, stores all options and helps parsing. More...

#include <optparse.h>

List of all members.

Public Types

typedef bool(*) option_validator (const String &)
 Callback used to impose constraints on options.
typedef int(*) generic_callback (int, const String &)
 Generic callback type.

Public Member Functions

int addOption (const String &p_short, const String &p_long, const String &p_help, int p_flags, option_validator p_validator=NULL)
String asString (const String &p_opt)
bool isSet (const String &p_opt)
void setErrorCallback (generic_callback p_callback)
void setHelpCallback (help_callback p_callback)
void reset ()

Friends

class Parser


Detailed Description

Options class, stores all options and helps parsing.


Member Function Documentation

int Options::addOption ( const String &  p_short,
const String &  p_long,
const String &  p_help,
int  p_flags,
option_validator  p_validator = NULL 
)

Parameters:
p_short String describing the short form of this option, e.g "-s"
p_long String describing the long form of this option, e.g. "--start"
p_help Documentation for this parameter, e.g. "Start the server"
p_flags Flags for this option
p_validator Callback used to validate the value of the argument (NULL if no validation required or no argument for this opt)
Returns:
E_ERROR when there was a failure allocating memory

E_INVALID if both option strings are empty or the option was given a validator even if not needed

E_OPT_DUPLICATE if there was another option by this name

E_OK if everything went ok

String Options::asString ( const String &  p_opt  ) 

Parameters:
p_opt String containing the option whose argument is to be retrieved
Returns:
Argument given on the commandline to the requested option

Empty string in case the option is invalid or missing or no argument was found

bool Options::isSet ( const String &  p_opt  ) 

Example: bool b = isOptionSet("-s");

Parameters:
p_opt String containing the option to look for.
Returns:
true If the option was specified on the command line

false Otherwise

void Options::setErrorCallback ( generic_callback  p_callback  ) 

Sets callback for invalid command line options encountered

Parameters:
p_callback Pointer to function to call on invalid opts

void Options::setHelpCallback ( help_callback  p_callback  ) 

Sets callback for help generation (invoked when encountered) -h or --help. If not set, default will be used

Parameters:
p_callback Pointer to function to call on help generation.

void Options::reset (  ) 

Reset the options object


The documentation for this class was generated from the following files:
Generated on Mon Feb 19 21:12:26 2007 for OptParse by  doxygen 1.5.1-p1