Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

simth::CmdLineParser Class Reference

#include <cmdlineparser.h>

List of all members.

Public Member Functions

 CmdLineParser ()
void addOption (const std::string &optName, const std::string &shortOptName, const std::string &description)
std::vector< std::string > parseAndValidate (int argc, char *argv[])
bool isOptionSet (const std::string &shortOptName, const std::string &longOptName) const
std::string optionList () const

Classes

class  CmdLineOption
class  InvalidOption


Detailed Description

This command line parser can be used to parse the command options given to the main() function.

An option to be parsed is specified by a long option name and a short option name. If the long option name is not empty the short option name can be empty and vice versa. A long option name is always preceded by a double dash, i.e. '--', a short option name by one dash, '-'.

The parser is very simple to use. First you have to specify the possible options your programm can take. This is done by adding options to the parser using the function addOption(longName,shortName,description), e.g. addOption("h","help","Displays help and exit").

To parse for this option, just call once the function parseAndValidate(argc,argv) after adding all options and then asked for the desired option by using the function isOptionSet("h","help").

If you would like to print out a formatted table of all added options just use the function optionList() that returns an appropriate string.


Constructor & Destructor Documentation

simth::CmdLineParser::CmdLineParser  ) 
 

Standard constructor.


Member Function Documentation

void simth::CmdLineParser::addOption const std::string &  optName,
const std::string &  shortOptName,
const std::string &  description
 

Adds an option to the command line parser.

std::vector<std::string> simth::CmdLineParser::parseAndValidate int  argc,
char *  argv[]
 

Parses the given arguments and sets the specified options. If argv specifies an option that has not been added by using addOption(), an InvalidOption error is thrown. The returned value of the function is a vector that contains the elements of argv that were not recognized as options. E.g. if argv contains [simthetic --debug filename] then the returned vector contains the elements [simthetic filename].

bool simth::CmdLineParser::isOptionSet const std::string &  shortOptName,
const std::string &  longOptName
const
 

Returns true if the option specified by long and short option name had been added to the parser (using the function addOption()).

std::string simth::CmdLineParser::optionList  )  const
 

Returns a string that describes the option list. This can be used to print out the specified options.


Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1