ArgumentParser Class Reference

Command line parser. More...

#include <argumentParser.h>

Collaboration diagram for ArgumentParser:

Collaboration graph
[legend]

Public Member Functions

 ArgumentParser (const string &helpstr="", char hlpShrt='h', const string &hlpLng="help")
 Constructor using a global help string.
template<class T >
ArgumentParser & option (T *ptr, char sho, char *lon, char *help)
 Declare an optional argument.
template<class T >
ArgumentParser & parameter (T *ptr, char sho, char *lon, char *help)
 Declare a mandatory argument.
void operator() (int argc, char **argv)
 Parse a command line.
void operator() (std::list< std::string > str)
 ArgumentParser (const string &helpstr="", char hlpShrt='h', const string &hlpLng="help")
 Constructor using a global help string.
template<class T >
ArgumentParser & option (T *ptr, char sho, char *lon, char *help)
 Declare an optional argument.
template<class T >
ArgumentParser & parameter (T *ptr, char sho, char *lon, char *help)
 Declare a mandatory argument.
void operator() (int argc, char **argv)
 Parse a command line.
void operator() (std::list< std::string > str)

Private Types

typedef std::string string
 String.
typedef std::map< string,
ArgumentBase * > 
Map
 Associate a string with a Argument object.
typedef std::map< ArgumentBase
*, bool > 
SetMap
 Associate name with boolean value (true iff it is set).
typedef std::vector
< ArgumentBase * > 
ArgVec
 Set of commands.
typedef std::string string
 String.
typedef std::map< string,
ArgumentBase * > 
Map
 Associate a string with a Argument object.
typedef std::map< ArgumentBase
*, bool > 
SetMap
 Associate name with boolean value (true iff it is set).
typedef std::vector
< ArgumentBase * > 
ArgVec
 Set of commands.

Private Attributes

std::map< char, ArgumentBase * > shortName
 short name -> Argument object
Map longName
 long name -> Argument object
SetMap parameter_set
 Set map (bool true iff parameter is set).
ArgVec commands
 Set of commands.
string globalHelp
 Overall presentation.
char helpShortName
 short name for help
string helpLongName
 long name for help

Detailed Description

Command line parser.

This object parses arguments from a command line or from an input stream. The arguments are described using a pointer, a short name, a long name and a help message. Mandatory arguments are declared using method "parameter", optional arguments are declared using method "option". Once all arguments declared, operator () does the parsing. The special option -h or --help displays help on all arguments. See examples argumentParserLine_test.cpp and argumentParserFile_test.cpp

See also:
Argument

Definition at line 190 of file argumentParser.h.


Member Typedef Documentation

typedef std::vector<ArgumentBase*> ArgumentParser::ArgVec [private]

Set of commands.

Definition at line 209 of file argumentParser.h.

typedef std::vector<ArgumentBase*> ArgumentParser::ArgVec [private]

Set of commands.

Definition at line 207 of file argumentParser.h.

typedef std::map< string, ArgumentBase* > ArgumentParser::Map [private]

Associate a string with a Argument object.

Definition at line 196 of file argumentParser.h.

typedef std::map< string, ArgumentBase* > ArgumentParser::Map [private]

Associate a string with a Argument object.

Definition at line 194 of file argumentParser.h.

typedef std::map<ArgumentBase*,bool> ArgumentParser::SetMap [private]

Associate name with boolean value (true iff it is set).

Definition at line 203 of file argumentParser.h.

typedef std::map<ArgumentBase*,bool> ArgumentParser::SetMap [private]

Associate name with boolean value (true iff it is set).

Definition at line 201 of file argumentParser.h.

typedef std::string ArgumentParser::string [private]

String.

Definition at line 194 of file argumentParser.h.

typedef std::string ArgumentParser::string [private]

String.

Definition at line 192 of file argumentParser.h.


Constructor & Destructor Documentation

ArgumentParser::ArgumentParser ( const string &  helpstr = "",
char  hlpShrt = 'h',
const string &  hlpLng = "help" 
) [inline]

Constructor using a global help string.

Definition at line 219 of file argumentParser.h.

ArgumentParser::ArgumentParser ( const string &  helpstr = "",
char  hlpShrt = 'h',
const string &  hlpLng = "help" 
) [inline]

Constructor using a global help string.

Definition at line 221 of file argumentParser.h.


Member Function Documentation

void ArgumentParser::operator() ( std::list< std::string >  str  )  [inline]

void ArgumentParser::operator() ( int  argc,
char **  argv 
) [inline]

Parse a command line.

Parameters:
argc number of arguments + 1, as usual in C
argv arguments

Definition at line 306 of file argumentParser.h.

void ArgumentParser::operator() ( std::list< std::string >  str  )  [inline]

void ArgumentParser::operator() ( int  argc,
char **  argv 
) [inline]

Parse a command line.

Parameters:
argc number of arguments + 1, as usual in C
argv arguments

Definition at line 304 of file argumentParser.h.

template<class T >
ArgumentParser& ArgumentParser::option ( T *  ptr,
char  sho,
char *  lon,
char *  help 
) [inline]

Declare an optional argument.

Parameters:
ptr pointer to the variable
sho short name
lon long name
help 

Definition at line 234 of file argumentParser.h.

References commands, helpLongName, helpShortName, longName, and shortName.

template<class T >
ArgumentParser& ArgumentParser::option ( T *  ptr,
char  sho,
char *  lon,
char *  help 
) [inline]

Declare an optional argument.

Parameters:
ptr pointer to the variable
sho short name
lon long name
help 

Definition at line 232 of file argumentParser.h.

References commands, helpLongName, helpShortName, longName, and shortName.

Referenced by main().

template<class T >
ArgumentParser& ArgumentParser::parameter ( T *  ptr,
char  sho,
char *  lon,
char *  help 
) [inline]

Declare a mandatory argument.

Parameters:
ptr pointer to the variable
sho short name
lon long name
help 

Definition at line 271 of file argumentParser.h.

References commands, helpLongName, helpShortName, longName, and shortName.

template<class T >
ArgumentParser& ArgumentParser::parameter ( T *  ptr,
char  sho,
char *  lon,
char *  help 
) [inline]

Declare a mandatory argument.

Parameters:
ptr pointer to the variable
sho short name
lon long name
help 

Definition at line 269 of file argumentParser.h.

References commands, helpLongName, helpShortName, longName, and shortName.


Field Documentation

Set of commands.

Definition at line 209 of file argumentParser.h.

Referenced by operator()(), option(), and parameter().

Overall presentation.

Definition at line 212 of file argumentParser.h.

Referenced by operator()().

long name for help

Definition at line 214 of file argumentParser.h.

Referenced by operator()(), option(), and parameter().

short name for help

Definition at line 213 of file argumentParser.h.

Referenced by operator()(), option(), and parameter().

long name -> Argument object

Definition at line 198 of file argumentParser.h.

Referenced by operator()(), option(), and parameter().

Set map (bool true iff parameter is set).

Definition at line 204 of file argumentParser.h.

Referenced by operator()().

std::map< char, ArgumentBase * > ArgumentParser::shortName [private]

short name -> Argument object

Definition at line 196 of file argumentParser.h.

Referenced by operator()(), option(), and parameter().


The documentation for this class was generated from the following files:

Generated on Sun Nov 23 04:12:51 2008 for Sofa by  doxygen 1.5.7.1