popt_options.h File Reference

option parsing More...

#include <string>
#include <vector>
Include dependency graph for popt_options.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  popt::option
 option - base class for a command line option More...


namespace  popt


void popt::parse_options (int argc, char const **argv, std::vector< std::string > &additional_params)
 parse_options - parse command line options

Detailed Description

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"),
Copyright 2002 OProfile authors
Read the file COPYING
Philippe Elie
John Levon

Generated on 29 Jul 2013 for oprofile by  doxygen 1.6.1