optparse::OptionParser Class Reference

#include <optparse.h>

Inheritance diagram for optparse::OptionParser:

Inheritance graph
[legend]
List of all members.

Public Types

typedef std::map< std::string,
std::string > 
options_type

Public Member Functions

 OptionParser (std::string usage="")
virtual ~OptionParser ()
void add_option (std::string shrt_flag, std::string lng_flag, std::string destination, std::string help="", action_t act=STORE, type_t type=STRING, std::string dfault="", std::string allowed_values="")
void parse_args (int argc, char **argv)
void help (std::ostream &os)
std::string type2string (type_t type)

Public Attributes

options_type options
 Dictionary of options. Use options[key] to access.
std::vector< std::string > arguments
 List of positional arguments.

Protected Member Functions

virtual void set_option (Option &option, std::string argument)

Private Member Functions

void find_opt_short (int argc, char **argv, int &index)
void find_opt_long (int argc, char **argv, int &index)

Private Attributes

std::string use_msg
 Usage message.
std::vector< Optionopts
 List of options the parser knows about.

Detailed Description

Option parser.

Definition at line 96 of file optparse.h.


Member Typedef Documentation

typedef std::map<std::string, std::string> optparse::OptionParser::options_type

Type of "options" dictionary.

Definition at line 140 of file optparse.h.


Constructor & Destructor Documentation

optparse::OptionParser::OptionParser ( std::string  usage = ""  ) 

optparse::OptionParser::~OptionParser (  )  [virtual]

Definition at line 59 of file optparse.cpp.


Member Function Documentation

void optparse::OptionParser::add_option ( std::string  shrt_flag,
std::string  lng_flag,
std::string  destination,
std::string  help = "",
action_t  act = STORE,
type_t  type = STRING,
std::string  dfault = "",
std::string  allowed_values = "" 
)

Add an option to the parser.

Parameters:
shrt_flag Short option name, like e.g. "-q".
lng_flag Long option name, like e.g. "--quiet"
destination Key under which the option argument is stored in the dictionary.
help Help string for generating the usage info.
act Action, one of STORE, STORE_TRUE, STORE_FALSE.
type Type info of the expected option argument. One of INT, DOUBLE, STRING, BOOL.
dfault Default value. Value stored in the dictionary if the option is not given.
allowed_values List of possible option values. A string of comma-separated allowed values. An empty string means that any value is allowed.

Reimplemented in optparse::TypedOptionParser.

Referenced by optparse::TypedOptionParser::add_option().

void optparse::OptionParser::find_opt_long ( int  argc,
char **  argv,
int &  index 
) [private]

Definition at line 236 of file optparse.cpp.

References opts, set_option(), optparse::STORE, optparse::STORE_FALSE, and optparse::STORE_TRUE.

Referenced by parse_args().

Here is the call graph for this function:

void optparse::OptionParser::find_opt_short ( int  argc,
char **  argv,
int &  index 
) [private]

Definition at line 203 of file optparse.cpp.

References opts, set_option(), optparse::STORE, optparse::STORE_FALSE, and optparse::STORE_TRUE.

Referenced by parse_args().

Here is the call graph for this function:

void optparse::OptionParser::help ( std::ostream &  os  ) 

Write usage info to stream. The usage info includes a formatted list of all options the parser knows about, including the help string, expected argument type and default value.

Parameters:
os Output stream the usage info is written to.

Referenced by optparse::TypedOptionParser::add_option().

void optparse::OptionParser::parse_args ( int  argc,
char **  argv 
)

Definition at line 79 of file optparse.cpp.

References arguments, find_opt_long(), and find_opt_short().

Here is the call graph for this function:

void optparse::OptionParser::set_option ( Option option,
std::string  argument 
) [protected, virtual]

Set option in dictionary. Function the parser uses to store an option argument or a default value in options dictionary. Can be overridden in a subclass to store additional info.

Parameters:
option Option object.
argument Option argument to store.

Reimplemented in optparse::TypedOptionParser.

Definition at line 278 of file optparse.cpp.

References optparse::Option::destination, optparse::Option::is_allowed(), and options.

Referenced by find_opt_long(), and find_opt_short().

Here is the call graph for this function:

string optparse::OptionParser::type2string ( type_t  type  ) 

Convert type_t type to human-readable string. This is used for generating the usage string and also in TypeOptionParser to encode the argument type in the options dictionary.

See also:
help
Parameters:
type Type.
Returns:
Converted string.

Definition at line 285 of file optparse.cpp.

References optparse::BOOL, optparse::DOUBLE, optparse::INT, and optparse::STRING.


Member Data Documentation

std::vector<std::string> optparse::OptionParser::arguments

List of positional arguments.

Definition at line 142 of file optparse.h.

Referenced by parse_args().

options_type optparse::OptionParser::options

Dictionary of options. Use options[key] to access.

Definition at line 141 of file optparse.h.

Referenced by optparse::TypedOptionParser::get_option(), set_option(), and optparse::TypedOptionParser::set_parameter_list().

std::vector<Option> optparse::OptionParser::opts [private]

List of options the parser knows about.

Definition at line 156 of file optparse.h.

Referenced by find_opt_long(), and find_opt_short().

std::string optparse::OptionParser::use_msg [private]

Usage message.

Definition at line 155 of file optparse.h.


The documentation for this class was generated from the following files:
Generated on Fri Oct 26 13:35:18 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7