Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

CmdLineParser Class Reference

#include <cmdline_parser.hh>

Collaboration diagram for CmdLineParser:

Collaboration graph
[legend]
List of all members.

Public Methods

 CmdLineParser (const string &progName_, PropRegistry &pr_)
int parse (int argc, char *argv[]) throw (CmdLineParseException)
void printUsage (ostream &os)
Specifying command line syntax
The methods add a new atom description into the parser's table and return a ref to the parser object in order to allow chained insertions (something like: clParaser.add(atom1).add(atom2).add(...);).

CmdLineParser& add (const CmdLineAtom &atom)
CmdLineParser& add (const string &tag, bool multi, bool optional, const string &sOpt, const string &lOpt, const string &prop, const string &description)

Private Types

typedef struct CmdLineParser::t_CmdLineAtom  CmdLineAtom

Private Attributes

PropRegistrypr
vector<CmdLineAtomdesc
string progName

Detailed Description

A simple command line parser implementation. It supports both short one-letter (like -abcdef) and long (like --a_longopt --b_something ) options. Also, options arguments of type string/bool/numeric are supportd. It supoprts the GNU style "--" options terminator, and automatic help message dumping.

Definition at line 98 of file cmdline_parser.hh.


Member Typedef Documentation

typedef struct CmdLineParser::t_CmdLineAtom CmdLineParser::CmdLineAtom [private]
 

A command line atom (or "option" ) is something like "-c" or "-o foo" or "--enable-things".

Each atom can contain one or more arguments. furthermore, the same atom can appear more than once. The multi field tells how multiple occurence should be handled. If it is false, each occurence will override the previous one. If true, the argument from each occurence is appended to the property that corresponds to that atom.

The tag field (corresponding to the tag field used into the Propregistry) means:

  • k_string : a parameter followed by a string argument (something like "--enable this" or "--enable=other").
  • k_bool: can be either "--switch=yes" (or, alternatively "--switch no")) or just "--switch" (yea is implied) or (the short version) "-s". If multi is enabled, the boolean values are stored in a list for the corresponding property. Otherwise, the last one will be the property's value. "true" and "false" in place of yes and no are also supported.
  • k_int: something like "-n 100" or "--numer 100". The multi parameter has the same meaning as for k_bool.
  • k_float: same as k_int.
The sOpt and lOpt fields are the option's name (i.e. the bi that appears after the - or --, respectively). Each option can have any of the two forms or both.

If the optional field is true, the optino is, well, optional :)

The description string is a text that indicates the meaning of the option, from the user's point of view. It is used when dumping the command line synopsys.

The prop string is the key of the property that will receive the value(s) of the option.

Referenced by add().


Constructor & Destructor Documentation

CmdLineParser::CmdLineParser ( const string & progName_,
PropRegistry & pr_ ) [inline]
 

Creates a new CmdLineParser that will parse a command line that obeys the given format string and will store the corersponding properties into the given property registry.

Definition at line 186 of file cmdline_parser.hh.


Member Function Documentation

int CmdLineParser::parse ( int argc,
char * argv[] ) throw (CmdLineParseException)
 

Parses the given command line and stores all the properties into the registry. The parsing stops at the first non-option argument (i.e. not starting with - or --).

Exceptions:
CmdLineparseException   if any error was encountered during parsing the command line. The exception's what message indicates what went wrong.

Returns:
the number of parsed arguments (the rest up to argv is supposed to only contain input files or whateer).

Definition at line 100 of file cmdline_parser.cc.

Referenced by main().

CmdLineParser & CmdLineParser::add ( const CmdLineAtom & atom ) [inline]
 

Definition at line 212 of file cmdline_parser.hh.

Referenced by add(), and main().

CmdLineParser & CmdLineParser::add ( const string & tag,
bool multi,
bool optional,
const string & sOpt,
const string & lOpt,
const string & prop,
const string & description ) [inline]
 

Definition at line 218 of file cmdline_parser.hh.

void CmdLineParser::printUsage ( ostream & os )
 

Definition at line 196 of file cmdline_parser.cc.

Referenced by main().


Member Data Documentation

PropRegistry & CmdLineParser::pr [private]
 

The registry where the parsed roperties will be stored by parse.

Definition at line 234 of file cmdline_parser.hh.

vector< CmdLineAtom > CmdLineParser::desc [private]
 

The desription of the cmd line.

Definition at line 239 of file cmdline_parser.hh.

string CmdLineParser::progName [private]
 

The name of the executable.

Definition at line 244 of file cmdline_parser.hh.


The documentation for this class was generated from the following files:
Generated at Tue Jul 9 21:06:01 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001