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) |
You may do your own consitency tests afterwards and throw your own InfoError's by calling ProgramInfo::throw_Error().
#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; }
------------------------------------------------------------------------------ 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>
|
test if string is the wanted argument. User-provided function returning true, if the passed string is the wanted argument.
Definition at line 196 of file Option.h. Referenced by OptionalCmdLineArgument::OptionalCmdLineArgument(), RepeatableCmdLineArgument::RepeatableCmdLineArgument(), and RepeatedCmdLineArgument::RepeatedCmdLineArgument(). |
|
NULL-terminated C-Array of pointers to CmdLineOption.
Definition at line 422 of file Option.h. Referenced by ProgramInfo::exclude(), and ProgramInfo::needOne(). |
|
Definition at line 289 of file Option.cpp. Referenced by RepeatedCmdLineArgumentOption::RepeatedCmdLineArgumentOption(). |
|
accepts every argument on command line
Referenced by OptionalCmdLineArgument::OptionalCmdLineArgument(). |
Contact me in case of errors or questions. This documentation is powered by . |
(C) 2000-2002 |