Archon::Utilities::Options Struct Reference

Collaboration diagram for Archon::Utilities::Options:

Collaboration graph
[legend]
List of all members.

Public Types

enum  WantArg { wantArg_never, wantArg_optional, wantArg_always }

Public Member Functions

 Options (bool treatNegativeNumbersAsOptions=false, Logger *logger=Logger::get())
 ~Options ()
template<typename T, typename D>
void addConfig (string shortName, string longName, T &var, T val, string description, WantArg wantArg, D domainChecker) throw (DefinitionException)
 Add a configuration parameter that can be used both as a command line switch and in a configuration file.
template<typename T>
void addConfig (string shortName, string longName, T &var, T val, string description, WantArg wantArg=wantArg_never) throw (DefinitionException)
 Same as template<typename T, typename D> addConfig(string, string, T &, T, string, WantArg, D) except that the domain checker is defaulted to Unrestricted<T>.
template<typename T, typename D>
void addSwitch (string shortName, string longName, T &var, T val, string description, WantArg wantArg, D domainChecker) throw (DefinitionException)
 Add an option that can be used only as a command line switch.
template<typename T>
void addSwitch (string shortName, string longName, T &var, T val, string description, WantArg wantArg=wantArg_never) throw (DefinitionException)
 Add an option that can be used only as a command line switch.
bool processCommandLine (int &argc, const char *argv[], bool switchesOnly=false)
 Apply the effects of the switches on the command line.
bool processConfigFile (string path) throw (FileAccessException)
 Apply the effects of a configuration file.
void saveConfigFile (string path) throw (FileAccessException)
 Save all the options and their values into the specified file in a format that is readable by processConfigFile.
string list (unsigned width=Term::getWidth())
 Print a description of the switches.

Static Public Member Functions

template<typename T>
static Range< Trange (T from, T to)

Classes

struct  Def
struct  DefinitionException
struct  DefVar
struct  DefVarBase
struct  FileAccessException
struct  IntByInt
 Utility type for grouping two integers. More...
struct  Parser
struct  Range
 Domain checker for a range. More...
struct  Unrestricted
 Domain checker for an unrestricted domain. More...

Detailed Description

Definition at line 36 of file options.H.


Member Function Documentation

template<typename T>
void Archon::Utilities::Options::addConfig string  shortName,
string  longName,
T var,
T  val,
string  description,
WantArg  wantArg = wantArg_never
throw (DefinitionException) [inline]
 

Same as template<typename T, typename D> addConfig(string, string, T &, T, string, WantArg, D) except that the domain checker is defaulted to Unrestricted<T>.

See also:
addConfig(string, string, T &, T, string, WantArg, D)

Definition at line 153 of file options.H.

template<typename T, typename D>
void Archon::Utilities::Options::addConfig string  shortName,
string  longName,
T var,
T  val,
string  description,
WantArg  wantArg,
domainChecker
throw (DefinitionException) [inline]
 

Add a configuration parameter that can be used both as a command line switch and in a configuration file.

Parameters:
shortName A one character name for this option when used as a command line switch with one hyphen prepended. Use the empty string if this option has no short name.
longName A multi character name for this option that can be used as a command line switch with two hyphens prepended or as an option identifier in a configuration file. Use the empty string if this option has no long name, but note that this implies that this option cannot be referenced from a configuration file.
var A reference to the variable in which the parameter value will be stored when parsing the command line and configuration files.
val The value that is stored in 'var' for options that do not require a value when specified and when no value is specified.
description The description for this option that is included when an option listing is produced.
domainChecker An instance of a class with a 'check' method like Unrestricted. This method will be called to determine wether the value is acceptable (within the allowed domain).
See also:
WantArg

Unrestricted

Note:
You can add options with variables of any type T as long as specializations of Parser<T>::parse and Parser<T>::format exists. Specializations are provided in options.C for the following types: bool, int, double, string.

Definition at line 135 of file options.H.

Referenced by Archon::Render::Test::main(), Archon::Display::Test::main(), Archon::SaiTestApps::Textviewer::main(), Archon::SaiTestApps::Spot::main(), Archon::SaiTestApps::Simple::main(), Archon::SaiTestApps::Molecule::main(), Archon::SaiTestApps::Filebrowser::main(), Archon::SaiTestApps::Cylinders::main(), Archon::SaiTestApps::Clock::main(), and Archon::Console3d::main().

template<typename T>
void Archon::Utilities::Options::addSwitch string  shortName,
string  longName,
T var,
T  val,
string  description,
WantArg  wantArg = wantArg_never
throw (DefinitionException) [inline]
 

Add an option that can be used only as a command line switch.

The meaning of the parameters are the same as for addConfig.

See also:
addConfig(string, string, T &, T, string, WantArg)

Definition at line 188 of file options.H.

template<typename T, typename D>
void Archon::Utilities::Options::addSwitch string  shortName,
string  longName,
T var,
T  val,
string  description,
WantArg  wantArg,
domainChecker
throw (DefinitionException) [inline]
 

Add an option that can be used only as a command line switch.

The meaning of the parameters are the same as for addConfig.

See also:
addConfig(string, string, T &, T, string, WantArg, D)

Definition at line 171 of file options.H.

Referenced by Archon::Render::Test::main(), Archon::Display::Test::main(), Archon::SaiTestApps::Textviewer::main(), Archon::SaiTestApps::Spot::main(), Archon::SaiTestApps::Simple::main(), Archon::SaiTestApps::Molecule::main(), Archon::SaiTestApps::Filebrowser::main(), Archon::SaiTestApps::Cylinders::main(), Archon::SaiTestApps::Clock::main(), and Archon::Console3d::main().

bool Archon::Utilities::Options::processCommandLine int &  argc,
const char *  argv[],
bool  switchesOnly = false
 

Apply the effects of the switches on the command line.

'argc' and 'argv' are adjusted so that all processed switches are filtered out.

Parameters:
switchesOnly If true then only the options that were added with 'addSwitch' will be processed. Other command line switches will be left in the command line. Also, no parse errors are reported for unknown switches and for left out switches. When this call is followed by a call with switchesOnly = false, then errors are reported for unknown switches.
Returns:
True if a parse error occured.

Definition at line 253 of file options.C.

References Archon::Utilities::Logger::log().

Referenced by Archon::Render::Test::main(), Archon::Display::Test::main(), Archon::SaiTestApps::Textviewer::main(), Archon::SaiTestApps::Spot::main(), Archon::SaiTestApps::Simple::main(), Archon::SaiTestApps::Molecule::main(), Archon::SaiTestApps::Filebrowser::main(), Archon::SaiTestApps::Cylinders::main(), Archon::SaiTestApps::Clock::main(), and Archon::Console3d::main().

bool Archon::Utilities::Options::processConfigFile string  path  )  throw (FileAccessException)
 

Apply the effects of a configuration file.

Returns:
True if a parse error occured.

Definition at line 520 of file options.C.

References Archon::Utilities::logger, Archon::Utilities::Stream::makeFileReader(), Archon::SaiTestApps::Filebrowser::path, and Archon::Utilities::Text::toString().

Referenced by Archon::Console3d::main().

void Archon::Utilities::Options::saveConfigFile string  path  )  throw (FileAccessException)
 

Save all the options and their values into the specified file in a format that is readable by processConfigFile.

Options that are added with addSwitch and options without a long name are not included.

Definition at line 620 of file options.C.

References Archon::Utilities::Stream::makeFileWriter(), and Archon::SaiTestApps::Filebrowser::path.

Referenced by Archon::Console3d::main().


The documentation for this struct was generated from the following files:
Generated on Sun Jul 30 22:57:45 2006 for Archon by  doxygen 1.4.4