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

rs::cmdline Namespace Reference

Comfortable command line interface. More...


Compounds

class  CmdLineHelpText
 Helptext used for several CmdLine..-Items. More...

class  CmdLineOption
 A command line switch without an argument. More...

class  CmdLineArgument
 A command line argument. More...

class  RepeatableCmdLineArgument
 base class for optional and/or repeated command line arguments. More...

class  OptionalCmdLineArgument
 An optional and repeatable command line argument. More...

class  RepeatedCmdLineArgument
 A repeatable command line argument. More...

class  CmdLineArgumentOption
 A command line option which has to be followed by an argument. More...

class  RepeatedCmdLineArgumentOption
 an option with a repeatable argument. More...

class  CmdLineAnnotation
 A annotation for some command line arguments. More...

class  ProgramInfo
 Global program information. More...


Typedefs

typedef bool(* CmdLineArgumentPredicate )(const std::string *arg)
 test if string is the wanted argument. More...

typedef CmdLineOption ** CmdLineOptionArray
 NULL-terminated C-Array of pointers to CmdLineOption. More...


Functions

bool acceptAnyArgument (const string *)
bool acceptAnyArgument (const std::string *arg)


Detailed Description

Comfortable command line interface.

Warning:
You'll have to change MAIL_CONTACT() and COPYRIGHT_BY()
Usage description:
Now it is ensured that command line was interpreted and all dependencies were verified.

You may do your own consitency tests afterwards and throw your own InfoError's by calling ProgramInfo::throw_Error().

Usage example:
#include <Option.h>

using namespace std;
using namespace rs::cmdline;
using namespace rs::err;

// every program has to create a ProgrammInfo
static ProgramInfo demoInfo("Demo", 1, 0, "Demonstrate command line usage");

static CmdLineArgument input("input", "name of the file to read");
static OptionalCmdLineArgument output("output", "name of the file to write (write to console if omitted)");

static CmdLineOption caseSensitive('c', "Be case sensitive");
static CmdLineOption caseInsensitive('i', "Be case insensitive");

static CmdLineArgumentOption verbose('v', "level", "Verbose output (level: 0=least 5=most)", "1");

static CmdLineOption *case_options[] = { &caseSensitive, &caseInsensitive, 0 };

int main(int argc, char *argv[])
{
    try {
        demoInfo.init(argc, argv); // pass command line to demoInfo
        demoInfo.needOne(case_options); // we need -c or -i
        demoInfo.exclude(caseSensitive, caseInsensitive); // but we don't want both

        // now we are sure command line satisfies our needs..

        // input is always set
        cout << "input='" << input.get() << "'\n";

        if (output) { // test if output was given
            cout << "output='" << output.get() << "'\n";
        }
        else {
            cout << "output not specified\n";
        }

        if (caseSensitive) {
            cout << "Option -c was given on the command line\n";
        }
        if (caseInsensitive) {
            cout << "Option -i was given on the command line\n";
        }
        // verbose is always set (because it has a default value)
        cout << "verbose level is " << verbose.get() << "\n";
    }
    catch (Error& err) {
        err.print(cerr); // here the error is displayed (see output below)
    }

    return 0;
}
If anything goes wrong, then an InfoError is raised which displays sth like:
 ------------------------------------------------------------------------------
 Demo 1.00   ---   (C) Jan 13 2003 by Mr.Nobody
 ------------------------------------------------------------------------------
 Purpose: Demonstrate command line usage
 Usage  : Demo <opts> <input> [<output>]

 <input> ::= name of the file to read
 <output>::= name of the file to write (write to console if omitted)

 <opts>::= -c        Be case sensitive
           -i        Be case insensitive
           -v<level> Verbose output (level: 0=least 5=most) [Default='1']
 ------------------------------------------------------------------------------
 Contact: mr.nobody@domain.de
 ------------------------------------------------------------------------------

Error in Demo: Missing arguments: <input>


Typedef Documentation

CmdLineArgumentPredicate
 

test if string is the wanted argument.

User-provided function returning true, if the passed string is the wanted argument.

Note:
If the passed string pointer is NULL, the function should return
  • true only if argument should be missing
  • false otherwise (i.e. if further arguments are needed)
Predefined functions:

Definition at line 196 of file Option.h.

Referenced by OptionalCmdLineArgument::OptionalCmdLineArgument(), RepeatableCmdLineArgument::RepeatableCmdLineArgument(), and RepeatedCmdLineArgument::RepeatedCmdLineArgument().

typedef CmdLineOption** CmdLineOptionArray
 

NULL-terminated C-Array of pointers to CmdLineOption.

Definition at line 422 of file Option.h.

Referenced by ProgramInfo::exclude(), and ProgramInfo::needOne().


Function Documentation

bool acceptAnyArgument const string *   
 

Definition at line 289 of file Option.cpp.

Referenced by RepeatedCmdLineArgumentOption::RepeatedCmdLineArgumentOption().

bool acceptAnyArgument const std::string *    arg
 

accepts every argument on command line

See also:
RepeatedCmdLineArgument

Referenced by OptionalCmdLineArgument::OptionalCmdLineArgument().


Contact me in case of errors or questions.
This documentation is powered by Doxygen.
(C) 2000-2002 Doxygen