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

Option that takes an argument. More...

#include <option.h>

Inheritance diagram for jwscxx::base::Option_with_arg:
Collaboration diagram for jwscxx::base::Option_with_arg:

List of all members.

Public Member Functions

 Option_with_arg (char s_name, const char *l_name, const char *desc, void(*func)(const char *arg) throw(Arg_error)) throw (Arg_error)
 Constructs an Option that takes an argument.
int process (int argc, char **argv) const throw (Arg_error)
 Processes an Option from program command-line arguments.
void print (ostream &out, int width) const throw (Arg_error)
 Prints an Option to an output stream.

Protected Member Functions

const char * get_l_name_arg (const char *str) const
 Gets the argument for the Option from its long name.

Protected Attributes

void(* func )(const char *arg)
 Function to process an Option with an argument.

Detailed Description

Option that takes an argument.

An option is specified on the command-line as follows

   --option-string=arg
   -O arg

where

   Option::l_name = "option-string"
   Option::s_name = 'O'

Specifying an option in a file is similar, but only the Option::l_name can be used, for instance

   option-string=arg

Definition at line 192 of file option.h.


Constructor & Destructor Documentation

Option_with_arg::Option_with_arg ( char  s_name,
const char *  l_name,
const char *  desc,
void(*)(const char *arg) throw func(Arg_error  
) throw (Arg_error)

Constructs an Option that takes an argument.

Parameters:
s_nameShort name for the Option.
l_nameLong name for the Option.
descOption description.
funcFunction to process the Option.

Definition at line 177 of file option.cpp.


Member Function Documentation

int Option_with_arg::process ( int  argc,
char **  argv 
) const throw (Arg_error) [virtual]

Processes an Option from program command-line arguments.

Parameters:
argcNumber of command-line arguments.
argvThe command-line arguments.
Returns:
If this Option is in the arguments, its index is returned; otherwise < 0.
Exceptions:
Arg_errorError in processing the Option.

Implements jwscxx::base::Option.

Definition at line 200 of file option.cpp.

void Option_with_arg::print ( ostream &  out,
int  width 
) const throw (Arg_error) [virtual]

Prints an Option to an output stream.

The format for printing is as follows

   -O, --option-string=ARG  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.

Implements jwscxx::base::Option.

Definition at line 237 of file option.cpp.

const char * Option_with_arg::get_l_name_arg ( const char *  str) const [protected]

Gets the argument for the Option from its long name.

Parameters:
strString to get the Option argument from.
Returns:
If the argument is not in str, 0 is returned; otherwise a pointer to the argument in str.

Definition at line 374 of file option.cpp.


Member Data Documentation

void(* jwscxx::base::Option_with_arg::func)(const char *arg) [protected]

Function to process an Option with an argument.

Must be able to handle arg == 0.

Definition at line 228 of file option.h.


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