JWS C++ Library
C++ language utility library
jwscxx::base::Options Class Reference

Collection of Options for processing. More...

#include <option.h>

Collaboration diagram for jwscxx::base::Options:

List of all members.

Public Member Functions

 Options ()
 Constructs an empty collection of options.
 ~Options ()
 Deletes a collection of options.
void add (Option *opt)
 Adds an option to the collection.
int process (int argc, char **argv) const throw (Arg_error)
 Processes the options in the collection from program command-line arguments.
void process (const char *fname) const throw (IO_error, Arg_error)
 Processes the options in the collection from a file.
void process (istream &in) const throw (Arg_error)
 Processes the options in the collection from an input stream.
void print (ostream &out=cerr, int width=20) const
 Prints the options in the collection to an output stream.

Private Member Functions

bool is_an_option (const char *arg) const
 Returns whether an argument is an option.

Private Attributes

list< Option * > opts
 Collection of Options.

Detailed Description

Collection of Options for processing.

Definition at line 297 of file option.h.


Constructor & Destructor Documentation

jwscxx::base::Options::Options ( ) [inline]

Constructs an empty collection of options.

Definition at line 302 of file option.h.

Options::~Options ( )

Deletes a collection of options.

Deletes all the Option in the collection.

Definition at line 606 of file option.cpp.


Member Function Documentation

void Options::add ( Option opt)

Adds an option to the collection.

Parameters:
optOption to add to the collection.
Note:
When the Options collection is deleted, all its Option are deleted as well.

Definition at line 621 of file option.cpp.

int Options::process ( int  argc,
char **  argv 
) const throw (Arg_error)

Processes the options in the collection from program command-line arguments.

Parameters:
argcNumber of arguments in argv.
argvArray of string arguments.
Exceptions:
jwscxx::base::Arg_errorError in processing an argument.
Returns:
The number of arguments that are not options.

Definition at line 635 of file option.cpp.

void Options::process ( const char *  fname) const throw (IO_error, Arg_error)

Processes the options in the collection from a file.

Parameters:
fnameFile to process the options from.
Exceptions:
IO_errorThere was a problem opening or reading from fname.
Arg_errorCould not process an option in the file.

Definition at line 675 of file option.cpp.

void Options::process ( istream &  in) const throw (Arg_error)

Processes the options in the collection from an input stream.

Parameters:
inInput stream to process the options from.
Exceptions:
Arg_errorCould not process an option in the file.

Definition at line 711 of file option.cpp.

void Options::print ( ostream &  out = cerr,
int  width = 20 
) const

Prints the options in the collection to an output stream.

The format for printing is as follows

   -O, --option-string  Option description.

The Option::desc may wrap to multiple lines, but will be aligned properly.

Parameters:
outOutput stream to print to.
widthWidth of the option name field to use.
Note:
The format for printing assumes an 80 character line width.
Exceptions:
Arg_errorMaximum width is 60.

Definition at line 784 of file option.cpp.

bool Options::is_an_option ( const char *  arg) const [private]

Returns whether an argument is an option.

Returns:
Whether an argument is an option.

Definition at line 795 of file option.cpp.


Member Data Documentation

Collection of Options.

Definition at line 341 of file option.h.


The documentation for this class was generated from the following files: