CPUnit 0.95 (beta)
The REAL C++ port of JUnit.
cpunit::CmdLineParser Class Reference

Class implementing command line parsing functionality. More...

#include <cpunit_CmdLineParser.hpp>

List of all members.

Public Member Functions

 CmdLineParser ()
 CmdLineParser (const CmdLineParser &p)
virtual ~CmdLineParser ()
CmdLineParseroperator= (const CmdLineParser &p)
void add_legal (const std::string &s)
void parse (const int argc, const char **cmdline)
bool has (const std::string &arg) const
bool has_one_of (const std::string &arg) const
template<class T >
value_of (const std::string &arg) const
const std::vector< std::string > & program_input () const
std::string to_string () const

Private Member Functions

void parse_long_token (const std::string &token)
 A long token is a string prepended by '--'.
void parse_short_token (const std::string &token)
 A short token is a string prepended by '-'.

Private Attributes

std::set< std::string > legal_args
std::map< std::string,
std::string > 
std::vector< std::string > input

Static Private Attributes

static const std::string BLANKS

Detailed Description

Class implementing command line parsing functionality.

The parser is used in the following manner:

  1. Call CmdLineParser.add_legal to register the legal parameters. Both short forms and long forms must be explicitly specified. For arguments taking values, this does not have to be specified.
  2. Call parse to parse the command line arguments.
  3. Use has or has_one_of to figure which arguments has been specified.
  4. Use value_of to obtain values for arguments taking such.
  5. Use program_input to get the list of text occurrences on the command line which where not recognized as arguments. (I.e. they where not prefixed by '-' or '--').

Definition at line 57 of file cpunit_CmdLineParser.hpp.

Constructor & Destructor Documentation

cpunit::CmdLineParser::CmdLineParser ( )

Definition at line 38 of file cpunit_CmdLineParser.cpp.

cpunit::CmdLineParser::CmdLineParser ( const CmdLineParser p)

Definition at line 44 of file cpunit_CmdLineParser.cpp.

cpunit::CmdLineParser::~CmdLineParser ( ) [virtual]

Definition at line 50 of file cpunit_CmdLineParser.cpp.

Member Function Documentation

void cpunit::CmdLineParser::add_legal ( const std::string &  s)

Definition at line 64 of file cpunit_CmdLineParser.cpp.

bool cpunit::CmdLineParser::has ( const std::string &  arg) const

Definition at line 162 of file cpunit_CmdLineParser.cpp.

bool cpunit::CmdLineParser::has_one_of ( const std::string &  arg) const

Definition at line 173 of file cpunit_CmdLineParser.cpp.

cpunit::CmdLineParser & cpunit::CmdLineParser::operator= ( const CmdLineParser p)

Definition at line 54 of file cpunit_CmdLineParser.cpp.

void cpunit::CmdLineParser::parse ( const int  argc,
const char **  cmdline 

Definition at line 89 of file cpunit_CmdLineParser.cpp.

void cpunit::CmdLineParser::parse_long_token ( const std::string &  token) [private]

A long token is a string prepended by '--'.

Definition at line 141 of file cpunit_CmdLineParser.cpp.

void cpunit::CmdLineParser::parse_short_token ( const std::string &  token) [private]

A short token is a string prepended by '-'.

Definition at line 112 of file cpunit_CmdLineParser.cpp.

const std::vector< std::string > & cpunit::CmdLineParser::program_input ( ) const

Definition at line 198 of file cpunit_CmdLineParser.cpp.

std::string cpunit::CmdLineParser::to_string ( ) const

Definition at line 203 of file cpunit_CmdLineParser.cpp.

template<class T >
T cpunit::CmdLineParser::value_of ( const std::string &  arg) const

Definition at line 36 of file cpunit_CmdLineParser.tcc.

Member Data Documentation

std::map<std::string, std::string> cpunit::CmdLineParser::args [private]

Definition at line 61 of file cpunit_CmdLineParser.hpp.

const std::string cpunit::CmdLineParser::BLANKS [static, private]

Definition at line 58 of file cpunit_CmdLineParser.hpp.

std::vector<std::string> cpunit::CmdLineParser::input [private]

Definition at line 62 of file cpunit_CmdLineParser.hpp.

std::set<std::string> cpunit::CmdLineParser::legal_args [private]

Definition at line 60 of file cpunit_CmdLineParser.hpp.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines