GetLongOpt Class Reference

(Advanced Computer Research Institute, Lyon, France). More...

Inheritance diagram for GetLongOpt:

CommandLineHandler List of all members.

Public Types

enum  OptType { Valueless, OptionalValue, MandatoryValue }
 enum for different types of values associated with command line options.

Public Member Functions

 GetLongOpt (const char optmark= '-')
 Constructor.
 ~GetLongOpt ()
 Destructor.
int parse (int argc, char *const *argv)
 parse the command line args (argc, argv).
int parse (char *const str, char *const p)
 parse a string of options (typically given from the environment).
int enroll (const char *const opt, const OptType t, const char *const desc, const char *const val)
 Add an option to the list of valid command options.
const char * retrieve (const char *const opt) const
 Retrieve value of option.
void usage (ostream &outfile=cout) const
 Print usage information to outfile.
void usage (const char *str)
 Change header of usage output to str.
void store (const char *name, const char *value)
 Store a specified option value.

Private Member Functions

char * basename (char *const p) const
 extract the base name from a string as delimited by '/'
int setcell (Cell *c, char *valtoken, char *nexttoken, const char *p)
 internal convenience function for setting Cell::value

Private Attributes

Cell * table
 option table
const char * ustring
 usage message
char * pname
 program basename
char optmarker
 option marker
int enroll_done
 finished enrolling
Cell * last
 last entry in option table

Detailed Description

(Advanced Computer Research Institute, Lyon, France).

GetLongOpt manages the definition and parsing of "long options." Command line options can be abbreviated as long as there is no ambiguity. If an option requires a value, the value should be separated from the option either by whitespace or an "=".


Constructor & Destructor Documentation

GetLongOpt ( const char  optmark = '-'  ) 

Constructor.

Constructor for GetLongOpt takes an optional argument: the option marker. If unspecified, this defaults to '-', the standard (?) Unix option marker.


Member Function Documentation

int parse ( int  argc,
char *const *  argv 
)

parse the command line args (argc, argv).

A return value < 1 represents a parse error. Appropriate error messages are printed when errors are seen. parse returns the the optind (see getopt(3)) if parsing is successful.

int parse ( char *const   str,
char *const   p 
)

parse a string of options (typically given from the environment).

A return value < 1 represents a parse error. Appropriate error messages are printed when errors are seen. parse takes two strings: the first one is the string to be parsed and the second one is a string to be prefixed to the parse errors.

int enroll ( const char *const   opt,
const OptType  t,
const char *const   desc,
const char *const   val 
)

Add an option to the list of valid command options.

enroll adds option specifications to its internal database. The first argument is the option sting. The second is an enum saying if the option is a flag (Valueless), if it requires a mandatory value (MandatoryValue) or if it takes an optional value (OptionalValue). The third argument is a string giving a brief description of the option. This description will be used by GetLongOpt::usage. GetLongOpt, for usage-printing, uses {$val} to represent values needed by the options. {<$val>} is a mandatory value and {[$val]} is an optional value. The final argument to enroll is the default string to be returned if the option is not specified. For flags (options with Valueless), use "" (empty string, or in fact any arbitrary string) for specifying TRUE and 0 (null pointer) to specify FALSE.

const char * retrieve ( const char *const   opt  )  const

Retrieve value of option.

The values of the options that are enrolled in the database can be retrieved using retrieve. This returns a string and this string should be converted to whatever type you want. See atoi, atof, atol, etc. If a "parse" is not done before retrieving all you will get are the default values you gave while enrolling! Ambiguities while retrieving (may happen when options are abbreviated) are resolved by taking the matching option that was enrolled last. For example, -{v} will expand to {-verify}. If you try to retrieve something you didn't enroll, you will get a warning message.

void usage ( const char *  str  )  [inline]

Change header of usage output to str.

GetLongOpt::usage is overloaded. If passed a string "str", it sets the internal usage string to "str". Otherwise it simply prints the command usage.


The documentation for this class was generated from the following files:
Generated on Mon Feb 16 01:32:21 2009 for DAKOTA by  doxygen 1.5.1