LTL  2.0.x
Public Member Functions | Protected Attributes | Related Functions | List of all members
util::Option Class Referenceabstract

The base class for all options. More...

Inherited by util::BoolOption, util::DoubleArrayOption, util::DoubleOption, util::FloatArrayOption, util::FloatOption, util::IntArrayOption, util::IntOption, util::RegionArrayOption, util::StringArrayOption, and util::StringOption.

Public Member Functions

virtual void setValue (const string &s)=0 throw (UException)
 This function is the heart of the Option class: it parses the value of the option from the supplied string. More...
 
virtual string getTypeName () const
 Return the type name of the option as a string. More...
 
virtual bool needsValue () const
 
const string & getName () const
 Return the (long) option name. More...
 
char getCmdLineChar () const
 Return the short option char. More...
 
const string & getDefault () const
 Return the string representation of the default value. More...
 
const string & getUsage () const
 Return the help string. More...
 
virtual string toString () const =0
 Return the option's value as a string. More...
 
 Option (const char *name, const char *defaultVal, const char *usage, const char cmd)
 
 Option (const string &name, const string &defaultVal, const string &usage, const char cmd)
 
virtual ~Option () throw ()
 
virtual int getInt () const
 
virtual float getFloat () const
 
virtual string getString () const
 
virtual bool getBool () const
 

Protected Attributes

string name_
 long option name (e.g. –long-option or long-option=value) More...
 
string default_
 string representation of default value More...
 
string usage_
 help string More...
 
char cmdlinechar_
 short option char, for command line use More...
 

Related Functions

(Note that these are not member functions.)

ostream & operator<< (ostream &os, Option &op)
 

Detailed Description

The base class for all options.

All data is stored as strings. Conversion (parsing) to the actual type happens in derived specializations.

Constructing an option requires 4 (+1) parameters:

Constructor & Destructor Documentation

util::Option::Option ( const char *  name,
const char *  defaultVal,
const char *  usage,
const char  cmd 
)

ctors and dtor The parameters are

  • name The long option name, to be used with –option-name (command line), or option-name = (config file).
  • defaultVal string representation of default value
  • usage option description and help text
  • the short option character, for use with -c on the command line. Supply '\0' if no short option name is needed.
util::Option::Option ( const string &  name,
const string &  defaultVal,
const string &  usage,
const char  cmd 
)
virtual util::Option::~Option ( )
throw (
)
virtual

Member Function Documentation

virtual void util::Option::setValue ( const string &  s)
throw (UException
)
pure virtual

This function is the heart of the Option class: it parses the value of the option from the supplied string.

Implemented in util::RegionArrayOption, util::StringArrayOption, util::IntArrayOption, util::DoubleArrayOption, util::FloatArrayOption, util::StringOption, util::BoolOption, util::DoubleOption, util::FloatOption, and util::IntOption.

virtual int util::Option::getInt ( ) const
inlinevirtual

Acess the value of the option. Usually subclasses will not implement all of these, in fact, mostly just one of these.

Reimplemented in util::IntOption.

virtual float util::Option::getFloat ( ) const
inlinevirtual

Reimplemented in util::FloatOption.

virtual string util::Option::getString ( ) const
inlinevirtual

Reimplemented in util::StringOption.

virtual bool util::Option::getBool ( ) const
inlinevirtual

Reimplemented in util::BoolOption.

virtual string util::Option::getTypeName ( ) const
inlinevirtual
virtual bool util::Option::needsValue ( ) const
inlinevirtual

Return true if the option needs a value, false if it is a toggle-switch needing no value. On the command line, values are given as –long-option value, or -x value. In a config file, long-option = value. '#' can be used to delineate comments. See CommandLineReader and ConfigFileReader.

Reimplemented in util::BoolOption.

const string& util::Option::getName ( ) const

Return the (long) option name.

char util::Option::getCmdLineChar ( ) const

Return the short option char.

const string& util::Option::getDefault ( ) const

Return the string representation of the default value.

const string& util::Option::getUsage ( ) const

Return the help string.

virtual string util::Option::toString ( ) const
pure virtual

Member Data Documentation

string util::Option::name_
protected

long option name (e.g. –long-option or long-option=value)

string util::Option::default_
protected

string representation of default value

string util::Option::usage_
protected

help string

char util::Option::cmdlinechar_
protected

short option char, for command line use