sofa::helper::ArgumentParser Class Reference

Command line parser. More...

#include <ArgumentParser.h>

Collaboration diagram for sofa::helper::ArgumentParser:

Collaboration graph
[legend]

Public Member Functions

 ArgumentParser (const string &helpstr="", char hlpShrt='h', const string &hlpLng="help")
 Constructor using a global help string.
 ArgumentParser (std::vector< std::string > *files, const string &helpstr="", char hlpShrt='h', const string &hlpLng="help")
 Constructor using a global help string and a list of filenames.
 ~ArgumentParser ()
 Constructor using a global help string.
template<class T >
ArgumentParser & option (T *ptr, char sho, const char *lon, const char *help)
 Declare an optional argument.
template<class T >
ArgumentParser & parameter (T *ptr, char sho, const char *lon, const 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.

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.
std::vector< std::string > * files
 Set of remaining file.
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 226 of file ArgumentParser.h.


Member Typedef Documentation

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

Set of commands.

Definition at line 243 of file ArgumentParser.h.

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

Associate a string with a Argument object.

Definition at line 230 of file ArgumentParser.h.

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

Definition at line 237 of file ArgumentParser.h.

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

String.

Definition at line 228 of file ArgumentParser.h.


Constructor & Destructor Documentation

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

Constructor using a global help string.

Definition at line 65 of file ArgumentParser.cpp.

ArgumentParser::ArgumentParser ( std::vector< std::string > *  files,
const string &  helpstr = "",
char  hlpShrt = 'h',
const string &  hlpLng = "help" 
)

Constructor using a global help string and a list of filenames.

Definition at line 73 of file ArgumentParser.cpp.

ArgumentParser::~ArgumentParser (  ) 

Constructor using a global help string.

Definition at line 81 of file ArgumentParser.cpp.

References commands.


Member Function Documentation

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

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

Parse a command line.

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

Definition at line 91 of file ArgumentParser.cpp.

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

Declare an optional argument.

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

Definition at line 273 of file ArgumentParser.h.

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

Referenced by main().

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

Declare a mandatory argument.

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

Definition at line 310 of file ArgumentParser.h.

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


Field Documentation

Set of commands.

Definition at line 245 of file ArgumentParser.h.

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

std::vector<std::string>* sofa::helper::ArgumentParser::files [private]

Set of remaining file.

Definition at line 248 of file ArgumentParser.h.

Referenced by operator()().

Overall presentation.

Definition at line 251 of file ArgumentParser.h.

Referenced by operator()().

long name for help

Definition at line 253 of file ArgumentParser.h.

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

short name for help

Definition at line 252 of file ArgumentParser.h.

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

long name -> Argument object

Definition at line 234 of file ArgumentParser.h.

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

Set map (bool true iff parameter is set).

Definition at line 240 of file ArgumentParser.h.

Referenced by operator()().

short name -> Argument object

Definition at line 232 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:24:15 2008 for Sofa by  doxygen 1.5.7.1