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.
Option
class: it parses the value of the option from the supplied string
. (Note that these are not member functions.)
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:
NULL
. Useful for easily setting global parameters, or filling a struct with parameter values without having to manually loop over and read all program option's values. 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 '
' 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] |
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::IntOption, util::FloatOption, util::DoubleOption, util::BoolOption, util::StringOption, util::FloatArrayOption, util::DoubleArrayOption, util::IntArrayOption, util::StringArrayOption, and util::RegionArrayOption.
virtual int util::Option::getInt | ( | ) | const [inline, virtual] |
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 [inline, virtual] |
Reimplemented in util::FloatOption.
virtual string util::Option::getString | ( | ) | const [inline, virtual] |
Reimplemented in util::StringOption.
virtual bool util::Option::getBool | ( | ) | const [inline, virtual] |
Reimplemented in util::BoolOption.
virtual string util::Option::getTypeName | ( | ) | const [inline, virtual] |
Return the type name of the option as a string.
Reimplemented in util::IntOption, util::FloatOption, util::DoubleOption, util::BoolOption, util::StringOption, util::FloatArrayOption, util::DoubleArrayOption, util::IntArrayOption, util::StringArrayOption, and util::RegionArrayOption.
virtual bool util::Option::needsValue | ( | ) | const [inline, virtual] |
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] |
Return the option's value as a string.
Implemented in util::IntOption, util::FloatOption, util::DoubleOption, util::BoolOption, util::StringOption, util::FloatArrayOption, util::DoubleArrayOption, util::IntArrayOption, util::StringArrayOption, and util::RegionArrayOption.
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