Public Types
Public Methods
Detailed Description
template<class t> string tostring (const t obj)
|
bool string_to_T (bool &b, const string& s)
|
bool string_to_T (string& d, const string& s)
|
bool string_to_T (int& i, const string& s)
|
bool string_to_T (float& v, const string& s)
|
Provides behaviour common to all option types. Actual options are
declared using the templated Option class. The
OptionParser class can be used to parse command lines.
See also: Option, OptionParser
ostream& operator<< (ostream &os, const BaseOption& o)
|
Template class adding type specific behaviour to BaseOption. Define
one of these per program supported option.
Throw this exception if an error occured inside the Options package.
Throw this exception if no matching option was found during parsing.
X_MissingArgument (class) |
If an option should have had an argument but didn't then throw this
exception.
X_InvalidArgument (class) |
A class for parsing command line arguments into Option objects. The
following example demonstrates the principle:
#include "options.h"
// $Id: opttst.cc,v 1.3 2001/02/08 18:34:07 flitney Exp flitney $
using namespace Utilities;
Option<bool> verbose(string("-V,--verbose"), false,
string("switch on diagnostic messages"),
false, BaseOption::no_argument);
Option<bool> help(string("-h,--help"), false,
string("display this message"),
false, BaseOption::no_argument);
Option<float> dof(string("-d,--dof"), 100.0,
string("number of degrees of freedom"),
true, BaseOption::requires_argument);
Option<string> mask(string("-m,--mask"), string("mask"),
string("brain mask volume"),
true, BaseOption::requires_argument);
Option<string> resid(string("-r,--res"), string("res4d"),
string("4d `residual-of-fit' image"),
true, BaseOption::requires_argument);
Option<int> segid(string("-s,--shared-seg-id"), -1,
"shared memory segment ID",
false, BaseOption::requires_argument);
string title =
"opttst (Version 1.0)\n\n\
Copyright(c) 2000, University of Oxford\n\
Dave Flitney";
string examples =
"opttst --dof=<number> --mask=<filename> --res=<filename>\n\
opttst -d <number> -m <filename> -r <filename>\n\
opttst --verbose\n";
int main(unsigned int argc, char **argv) {
OptionParser options(title, examples);
try {
options.add(verbose);
options.add(help);
options.add(segid);
options.add(dof);
options.add(mask);
options.add(resid);
for(unsigned int a = options.parse_command_line(argc, argv);
a < argc; a++)
cout << argv[a] << endl;
if(help.value() ||
!options.check_compulsory_arguments())
options.usage();
if(verbose.value()) {
cout << "verbose = " << verbose.value() << endl;
cout << "help = " << help.value() << endl;
cout << "segid = " << segid.value() << endl;
cout << "dof = " << dof.value() << endl;
cout << "mask = " << mask.value() << endl;
cout << "resid = " << resid.value() << endl;
}
} catch(X_OptionError& e) {
options.usage();
cerr << endl << e.what() << endl;
} catch(std::exception &e) {
cerr << e.what() << endl;
}
}
See also: BaseOption, Option
inline ostream& operator<< (ostream& ostr, const TimingFunction* t)
|
Generated by: flitney@mace.fmrib.ox.ac.uk on Thu Feb 22 17:32:45 2001, using kdoc 2.0a36. |