#include <string>
#include <vector>
Go to the source code of this file.
Data Structures | |
class | popt::option |
Namespaces | |
namespace | popt |
Functions | |
void | popt::parse_options (int argc, char const **argv, std::vector< std::string > &additional_params) |
option parsing
This provides a simple facility for adding command-line options, and parsing them.
You can add a number of options and then call parse_options() to process them, for example :
bool allow_frob; string frob; static popt::option allow_frob_opt(allow_frob, "allow-frob", 'a', "allow frobs"); static popt::option frob_opt(frob, "frob", 'f', "what to frob", "name"); ... popt::parse_options(argc, argv, add_params);
Note than if you try to implement an option for an unsupported type like :
static unsigned int i; static popt::option i_opt(i, ....);
you don't get a compile time error but a link time error.
The call to parse_options() will fill in allow_frob and frob, if they are passed to the program (myfrobber --allow-frob --frob foo), and place any left over command line arguments in the add_params vector. Note that the template parameter denotes the type of the option argument.
When the template parameter type is bool, option starting with "no-" prefix are implicitely considered as negated before writing the associated bool so this will work as expected:
bool demangle; popt::option(demangle, "demangle", 'd', "demangle C++ symbols"), popt::option(demangle, "no-demangle", '\0', "don't demangle C++ symbols"),
Definition in file popt_options.h.