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

fun::OtherSimpleCLParser Class Reference

This is another simple command-line parser. More...

#include <SimpleCLParser.h>

List of all members.

Public Methods

template<class AC> void add (const QString &flag, AC &val, const QString &descr, bool required=false)
 Adds a command-line flag to the list of arguments which will be looked for.

template<class AC> void addPositional (const QString &flag, AC &val, const QString &descr, bool required=false)
 Adds a positional command-line argument to the list of arguments which will be looked for.

void parse (int argc, char **argv)
 Parses the given arguments and puts their values into the variables passed to add().

void usage (const QString &msg=QString())
 Prints a formatted usage message to cerr and terminates the program.

void dispose ()
 Cleans up the storage allocated by calls to add().


Detailed Description

This is another simple command-line parser.

This one takes references to the variables which you want to fill from the command line, and

For example, if you take an input file & output file, some integer, and a boolean flag, you might declare these variables:

    QString infile("foo.in"), outfile("foo.out");
    int its = 10;
    bool hose = false;
  

and register the arguments (and their descriptions) like this:

    OtherSimpleCLParser args;
    args.add("i filename",    infile,  "the input file");
    args.add("o filename",    outfile, "the output file");
    args.add("it iterations", its,     "number of times to iterate");
    args.add("h",             hose,    "hose things up");
    ...
    args.parse(argc, argv);
  

If there were errors, a usage message was generated & printed, and the program was terminated. You can do additional checking afterwards:

    if (infile == outfile) args.usage("infile == outfile, you bozo");
  

When you're all done checking the command line arguments, let the OtherSimpleCLParser object go out of scope, or call its dispose() method. (The variables you gave it will continue to contain the values which were passed on the command line, of course.)

Definition at line 134 of file SimpleCLParser.h.


Member Function Documentation

template<class AC>
void fun::OtherSimpleCLParser::add const QString &    flag,
AC &    val,
const QString &    descr,
bool    required = false
 

Adds a command-line flag to the list of arguments which will be looked for.

Parameters:
flag  Either just the flag, or the flag, a space, and some indication of what argument is expected (like "f filename" or "s name").
val  A reference to the variable which will be set to the value read from the command line.
descr  A description of the command-line flag. This will be used in the message generated by usage(), if usage() is called.
required  If this is true, then failing to pass the flag on the command line will cause usage() to be called.

Definition at line 247 of file SimpleCLParser.h.

template<class AC>
void fun::OtherSimpleCLParser::addPositional const QString &    flag,
AC &    val,
const QString &    descr,
bool    required = false
 

Adds a positional command-line argument to the list of arguments which will be looked for.

Note that all required positional arguments must precede optional positional arguments. Also, a positional argument type which takes multiple arguments (like QStringList) will cause everything after it to never be received, because all the arguments will go into the QStringList. (OK, rereading that, it doesn't even make sense to me. Sorry!)

Parameters:
name  some indication of what argument is expected (like "filename" or "name").
val  A reference to the variable which will be set to the value read from the command line.
descr  A description of the command-line flag. This will be used in the message generated by usage(), if usage() is called.
required  If this is true, then failing to pass the flag on the command line will cause usage() to be called.

Definition at line 254 of file SimpleCLParser.h.

void fun::OtherSimpleCLParser::dispose  
 

Cleans up the storage allocated by calls to add().

Call this when you're done using the OtherSimpleCLParser (that is, after the last point when you'd call usage()), or just let it go out of scope.

Definition at line 417 of file SimpleCLParser.cpp.

void fun::OtherSimpleCLParser::parse int    argc,
char **    argv
 

Parses the given arguments and puts their values into the variables passed to add().

If there are errors, usage() is called.

Definition at line 207 of file SimpleCLParser.cpp.

References usage().

void fun::OtherSimpleCLParser::usage const QString &    msg = QString()
 

Prints a formatted usage message to cerr and terminates the program.

If a specific message is supplied, it's printed first.

Definition at line 326 of file SimpleCLParser.cpp.

Referenced by parse().


The documentation for this class was generated from the following files:
Generated on Mon Aug 11 14:06:56 2003 for libfunutil by doxygen1.2.18