Dakota  Version
Explore and Predict with Confidence
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
GetLongOpt Class Reference

GetLongOpt is a general command line utility from S. Manoharan (Advanced Computer Research Institute, Lyon, France). More...

Inheritance diagram for GetLongOpt:
CommandLineHandler

Public Types

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

Public Member Functions

 GetLongOpt (const char optmark='-')
 Constructor. More...
 
 ~GetLongOpt ()
 Destructor.
 
int parse (int argc, char *const *argv)
 parse the command line args (argc, argv). More...
 
int parse (char *const str, char *const p)
 parse a string of options (typically given from the environment). More...
 
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. More...
 
const char * retrieve (const char *const opt) const
 Retrieve value of option. More...
 
void usage (std::ostream &outfile=Cout) const
 Print usage information to outfile.
 
void usage (const char *str)
 Change header of usage output to str. More...
 
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

GetLongOpt is a general command line utility from S. Manoharan (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 "=".

Member Enumeration Documentation

◆ OptType

enum OptType

enum for different types of values associated with command line options.

Enumerator
Valueless 

option that may never have a value

OptionalValue 

option with optional value

MandatoryValue 

option with required value

Constructor & Destructor Documentation

◆ GetLongOpt()

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.

References GetLongOpt::enroll_done, GetLongOpt::last, GetLongOpt::optmarker, GetLongOpt::table, and GetLongOpt::ustring.

Member Function Documentation

◆ parse() [1/2]

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.

References GetLongOpt::basename(), GetLongOpt::enroll_done, GetLongOpt::optmarker, GetLongOpt::pname, GetLongOpt::setcell(), and GetLongOpt::table.

Referenced by CommandLineHandler::check_usage().

◆ parse() [2/2]

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.

References GetLongOpt::enroll_done, GetLongOpt::optmarker, GetLongOpt::setcell(), and GetLongOpt::table.

◆ enroll()

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.

References GetLongOpt::enroll_done, GetLongOpt::last, and GetLongOpt::table.

Referenced by CommandLineHandler::initialize_options().

◆ retrieve()

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.

References GetLongOpt::optmarker, and GetLongOpt::table.

Referenced by CommandLineHandler::check_usage(), ProgramOptions::manage_run_modes(), ProgramOptions::ProgramOptions(), and CommandLineHandler::read_restart_evals().

◆ usage()

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.

References GetLongOpt::ustring.


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