#include <optparse.h>
Inheritance diagram for optparse::OptionParser:
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< Option > | opts |
List of options the parser knows about. |
Definition at line 96 of file optparse.h.
typedef std::map<std::string, std::string> optparse::OptionParser::options_type |
Type of "options" dictionary.
Definition at line 140 of file optparse.h.
optparse::OptionParser::OptionParser | ( | std::string | usage = "" |
) |
optparse::OptionParser::~OptionParser | ( | ) | [virtual] |
Definition at line 59 of file optparse.cpp.
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.
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.
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.
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.
type | Type. |
Definition at line 285 of file optparse.cpp.
References optparse::BOOL, optparse::DOUBLE, optparse::INT, and optparse::STRING.
std::vector<std::string> optparse::OptionParser::arguments |
List of positional arguments.
Definition at line 142 of file optparse.h.
Referenced by parse_args().
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] |