#include <cmdline.h>
Public Types | |
typedef std::multimap < std::string, std::string > | ParamsList |
Multimap type used to store parameters. | |
typedef std::map < std::string, std::string > | VarsList |
Map type used to store environment variables. | |
Public Member Functions | |
CmdLineParser () | |
Default constructor. | |
CmdLineParser (int argc, char const *const *argv, char const *const *envp=NULL) | |
Constructor setting argc, argv and envp. | |
CmdLineParser (CmdLineParser const &clp) | |
Copy constructor. | |
virtual | ~CmdLineParser () |
Destructor. | |
virtual bool | parse () |
Parses the command-line parameters and environment variables. | |
int | argc () const |
Returns the number of parameters in the argv() array. | |
char const *const * | argv () const |
Returns the raw parameters list. | |
char const *const * | envp () const |
Returns the array of environment variables. | |
std::string const & | error () const |
Returns a description of the error that occured. | |
char const * | c_error () const |
Same as error() but returns a char const *. | |
std::string const | program () const |
Returns the program path. | |
char const * | c_program () const |
Same as program() but returns a char const *. | |
std::string const & | progname () const |
Returns the program name. | |
char const * | c_progname () const |
Same as progname() but returns a char const *. | |
ParamsList const & | params () const |
Returns the multimap of parameters. | |
VarsList const & | vars () const |
Returns the map of environment variables. | |
Protected Member Functions | |
virtual bool | eval () |
Processes the command line parameters and environment variables. | |
Protected Attributes | |
std::string | m_error |
Last error. | |
std::string | m_progname |
Program name. | |
ParamsList | m_params |
Parameters list. | |
VarsList | m_vars |
Variables list. |
cmdline::CmdLineParser::CmdLineParser | ( | int | argc, | |
char const *const * | argv, | |||
char const *const * | envp = NULL | |||
) | [inline] |
This constructor will set the count and array of parameters used by the parse() function (usually the same as those of the main() function) Optionally, an array of environment variables (also available in main()) can be supplied, and they will be parsed by the parse() function too in that case.
[in] | argc | The number of parameters in argv. |
[in] | argv | The array of parameters. |
[in] | envp | The array of environment variables (defaults to NULL). |
virtual bool cmdline::CmdLineParser::parse | ( | ) | [virtual] |
std::string const& cmdline::CmdLineParser::error | ( | ) | const [inline] |
std::string const cmdline::CmdLineParser::program | ( | ) | const [inline] |
std::string const& cmdline::CmdLineParser::progname | ( | ) | const [inline] |
Returns the program file name, with any directory information removed.
ParamsList const& cmdline::CmdLineParser::params | ( | ) | const [inline] |
Returns the multimap of parameters. The keys are the parameter names, while the values are the parameter values.
VarsList const& cmdline::CmdLineParser::vars | ( | ) | const [inline] |
Returns the map of environment variables. The keys are the variable names, while the values are the variable values.
virtual bool cmdline::CmdLineParser::eval | ( | ) | [inline, protected, virtual] |
Processes the command line parameters and environment variables. This function is automatically called from parse(). It should be overriden in derived classes to do whatever needed.