cmdline::CmdLineParser Class Reference

A parser for command-line parameters and environment variables. More...

#include <cmdline.h>

List of all members.

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.


Detailed Description

The CmdLineParser class is used to parse and evaluate command-line parameters and environment variables as given at program launch (the argc, argv and envp parameters of main(). Parameters are stored in a map so they can be easily retrieved later.


Constructor & Destructor Documentation

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.

Parameters:
[in] argc The number of parameters in argv.
[in] argv The array of parameters.
[in] envp The array of environment variables (defaults to NULL).
See also:
parse()


Member Function Documentation

virtual bool cmdline::CmdLineParser::parse (  )  [virtual]

Parses command-line parameters and environment variables (if available), and calls the eval() function.

Returns:
true if everything has been parsed successfully and the eval() function succeeded, else it returns false and will generate an error message that can be retrieved through error().
See also:
error() eval()

std::string const& cmdline::CmdLineParser::error (  )  const [inline]

If parse() fails, this function will return a description of the error that occured.

Returns:
The description of the error that occured.
See also:
parse()

std::string const cmdline::CmdLineParser::program (  )  const [inline]

Returns the program path. This is roughly equivalent to string(argv()[0]).

Returns:
The program path.
See also:
argv()

std::string const& cmdline::CmdLineParser::progname (  )  const [inline]

Returns the program file name, with any directory information removed.

Returns:
The program file name.

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.

Returns:
The map of parameters.

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.

Returns:
The map of environment variables.

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.

Returns:
true if the processing succeeded, else it must return false and set m_error as appropriate.
See also:
m_error parse()


The documentation for this class was generated from the following file:
Generated on Wed Aug 15 00:37:22 2007 for Epona API by  doxygen 1.5.2