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

Class implementing command line parsing functionality. More...

#include <unittest_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 > 
args
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 unittest_CmdLineParser.hpp.


Constructor & Destructor Documentation

unittest::CmdLineParser::CmdLineParser ( )

Definition at line 38 of file unittest_CmdLineParser.cpp.

unittest::CmdLineParser::CmdLineParser ( const CmdLineParser p)

Definition at line 44 of file unittest_CmdLineParser.cpp.

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

Definition at line 50 of file unittest_CmdLineParser.cpp.


Member Function Documentation

void unittest::CmdLineParser::add_legal ( const std::string  s)

Definition at line 64 of file unittest_CmdLineParser.cpp.

bool unittest::CmdLineParser::has ( const std::string  arg) const

Definition at line 162 of file unittest_CmdLineParser.cpp.

bool unittest::CmdLineParser::has_one_of ( const std::string  arg) const

Definition at line 173 of file unittest_CmdLineParser.cpp.

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

Definition at line 54 of file unittest_CmdLineParser.cpp.

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

Definition at line 89 of file unittest_CmdLineParser.cpp.

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

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

Definition at line 141 of file unittest_CmdLineParser.cpp.

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

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

Definition at line 112 of file unittest_CmdLineParser.cpp.

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

Definition at line 198 of file unittest_CmdLineParser.cpp.

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

Definition at line 203 of file unittest_CmdLineParser.cpp.

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

Definition at line 36 of file unittest_CmdLineParser.tcc.


Member Data Documentation

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

Definition at line 61 of file unittest_CmdLineParser.hpp.

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

Definition at line 58 of file unittest_CmdLineParser.hpp.

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

Definition at line 62 of file unittest_CmdLineParser.hpp.

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

Definition at line 60 of file unittest_CmdLineParser.hpp.


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