CmdlineOptionManager Class Reference

OptionManager implementation for command-line parsing. More...

#include <Component/CmdlineOptionManager.H>

Inheritance diagram for CmdlineOptionManager:
Inheritance graph
[legend]
Collaboration diagram for CmdlineOptionManager:
Collaboration graph
[legend]

List of all members.

Classes

struct  Impl

Public Member Functions

Model option database

void allowOptions (const int mask)
 Only allow ModelOptionDef's that match the given mask.
virtual void requestOption (OptionedModelParam &p, const bool useMyVal=false)
 ModelComponent objects may request a command-line option here.
virtual void unRequestOption (OptionedModelParam &p)
 Request the removal of a param from the command-line options.
virtual void requestOptionAlias (const ModelOptionDef *def)
 Users may request model option aliases.
virtual void setOptionValString (const ModelOptionDef *def, const std::string &val)
 Set an option value.
virtual std::string getOptionValString (const ModelOptionDef *def)
 Get an option value.
virtual bool isOptionRequested (const ModelOptionDef *def) const
 Check if anybody has requested the given option.
Alternative access to internal options

These functions may be useful for alternative methods of displaying the help for command-line options (e.g. in the Qt ModelManagerWizard).

virtual uint numOptionDefs () const
 Get the number of ModelOptionDef objects in our list.
virtual uint getOptionDefs (const ModelOptionDef **arr, uint narr)
 Get ModelOptionDef objects from our list, up to the size of the given array.
virtual const ModelOptionDeffindOptionDef (const char *name) const
 Get the ModelOptionDef for the given name.
virtual bool isOptionDefUsed (const ModelOptionDef *def) const
 Query if the given ModelOptionDef is used in this program.
Command-line parsing

bool parseCommandLine (const int argc, const char **argv, const char *usage, const int minarg, const int maxarg)
 Parse all command-line options and set our params.
bool parseCommandLineCore (const int argc, const char **argv, const std::string &context=std::string())
 The core of parseCommandLine().
bool parseCommandLineCore (const char *args, const std::string &context=std::string())
uint numArgs () const
 Get the total number of command-line arguments.
std::string getArg (const uint num) const
 Get a command-line argument, by number.
uint numExtraArgs () const
 Get the number of available extra (non-option) command-line args.
std::string getExtraArg (const uint num) const
 Get an extra command-line arg, by number.
void clearExtraArgs ()
 Clear our list of leftover command-line arguments.

Detailed Description

OptionManager implementation for command-line parsing.

Definition at line 44 of file CmdlineOptionManager.H.


Member Function Documentation

void CmdlineOptionManager::allowOptions ( const int  mask  ) 

Only allow ModelOptionDef's that match the given mask.

This mask is used to filter requestOption() calls -- if the ModelOptionDef's filterFlag isn't part of ModelManager's current mask, then the requestOption() is ignored.

Definition at line 577 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::exportMask.

Referenced by ModelManager::allowOptions().

void CmdlineOptionManager::clearExtraArgs (  ) 

Clear our list of leftover command-line arguments.

Definition at line 1158 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::extraArgs.

Referenced by ModelManager::clearExtraArgs().

const ModelOptionDef * CmdlineOptionManager::findOptionDef ( const char *  name  )  const [virtual]

Get the ModelOptionDef for the given name.

Aborts if there is no such ModelOptionDef.

Implements OptionManager.

Definition at line 752 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::opts.

Referenced by ModelManager::findOptionDef().

string CmdlineOptionManager::getArg ( const uint  num  )  const

Get a command-line argument, by number.

Includes argv[0] as well as both option and non-option args.

Definition at line 1127 of file CmdlineOptionManager.C.

References CmdlineOptionManager::Impl::allArgs, and ASSERT.

Referenced by ModelManager::start1().

string CmdlineOptionManager::getExtraArg ( const uint  num  )  const

Get an extra command-line arg, by number.

Definition at line 1146 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::extraArgs.

Referenced by ModelManager::getExtraArg().

uint CmdlineOptionManager::getOptionDefs ( const ModelOptionDef **  arr,
uint  narr 
) [virtual]

Get ModelOptionDef objects from our list, up to the size of the given array.

Returns the number of array entries that were actually filled with valid ModelOptionDef pointers.

Implements OptionManager.

Definition at line 726 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::opts.

Referenced by ModelManager::getOptionDefs().

string CmdlineOptionManager::getOptionValString ( const ModelOptionDef def  )  [virtual]

Get an option value.

The value returned here is the value currently held by the ModelManager. This value is updated in three cases: 1) when a new component requests the option using requestOption() with useMyVal true; 2) when setOptionValString() is called, and 3) when the command-line arguments are parsed by ParseCommandLine, if a value for this option has been specified in the command line. If ModelComponent objects modify their local ModelParam values for their local parameter with this name, the value returned here will not be affected.

Implements OptionManager.

Definition at line 698 of file CmdlineOptionManager.C.

References ASSERT, CmdlineOptionManager::Impl::opts, and dummy_namespace_to_avoid_gcc411_bug_CmdlineOptionManager_C::OptionInfo::val.

Referenced by ModelManager::getOptionValString().

bool CmdlineOptionManager::isOptionDefUsed ( const ModelOptionDef def  )  const [virtual]

Query if the given ModelOptionDef is used in this program.

Implements OptionManager.

Definition at line 768 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::opts.

Referenced by ModelManager::isOptionDefUsed().

bool CmdlineOptionManager::isOptionRequested ( const ModelOptionDef def  )  const [virtual]

Check if anybody has requested the given option.

Implements OptionManager.

Definition at line 710 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::opts.

Referenced by ModelManager::isOptionRequested().

uint CmdlineOptionManager::numArgs (  )  const

Get the total number of command-line arguments.

Includes argv[0] as well as both option and non-option args.

Definition at line 1120 of file CmdlineOptionManager.C.

References CmdlineOptionManager::Impl::allArgs, and ASSERT.

Referenced by ModelManager::start1().

uint CmdlineOptionManager::numExtraArgs (  )  const

Get the number of available extra (non-option) command-line args.

Definition at line 1139 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::extraArgs.

Referenced by ModelManager::numExtraArgs().

uint CmdlineOptionManager::numOptionDefs (  )  const [virtual]

Get the number of ModelOptionDef objects in our list.

Implements OptionManager.

Definition at line 718 of file CmdlineOptionManager.C.

References ASSERT, and CmdlineOptionManager::Impl::opts.

Referenced by ModelManager::numOptionDefs().

bool CmdlineOptionManager::parseCommandLine ( const int  argc,
const char **  argv,
const char *  usage,
const int  minarg,
const int  maxarg 
)

Parse all command-line options and set our params.

This function will create a set of command-line options from our current collection of OptionedModelParam objects. It will then parse the command-line arguments and set the various option values accordingly, using a call to setOptionValString(). Any left-over args (i.e., not formatted as options) will be available through getExtraArg(), and if the number of such extra args is not within the specified minarg/maxarg bounds, a usage message and optionlist will be printed out (also printed out if a '--help' option is encountered). To decide which options should be exported by your various ModelComponent objects, typically you will call exportOptions() on the manager, which will propagate the call to all registered components. Here we have an additional default behavior that if exportOptions() has not been called on us, we will call it with an order to export all options, just before we start parsing the command-line. So, if you want to export all options, you don't have to do anything; if you want to only export special classes of options, then you will need to call exportOptions() manually some time before you parse the command-line. Returns true upon fully successful parse.

Parameters:
argc the number of command-line args
argv the command-line args
usage a textual description of the expected usage format, describing only what the non-option arguments should be (e.g., "<input.ppm> <output.ppm>")
minarg the minimum number of non-optional arguments
maxarg the maximum number of non-optional args, or -1 if unbounded

Definition at line 786 of file CmdlineOptionManager.C.

References ASSERT, CmdlineOptionManager::Impl::extraArgs, and parseCommandLineCore().

Referenced by ModelManager::parseCommandLine().

bool CmdlineOptionManager::parseCommandLineCore ( const int  argc,
const char **  argv,
const std::string context = std::string() 
)

The core of parseCommandLine().

This may be called recursively to handle command-line aliases. Note: beware that the first element of argv will be ignored (as it usually is the program name).

Definition at line 824 of file CmdlineOptionManager.C.

References CmdlineOptionManager::Impl::allArgs, ASSERT, CmdlineOptionManager::Impl::extraArgs, GVX_ERR_CONTEXT, OPT_ShowHelpMessage, CmdlineOptionManager::Impl::opts, setOptionValString(), rutz::sfmt(), and sformat().

Referenced by parseCommandLine(), and ModelManager::parseCommandLineCore().

void CmdlineOptionManager::requestOption ( OptionedModelParam p,
const bool  useMyVal = false 
) [virtual]

ModelComponent objects may request a command-line option here.

Parameters:
p the ModelParam data member of c corresponding to the option
useMyVal if true, we will do a setOptionValString() using the current value of the parameter, so that this value will be propagated to all OptionedModelParam objects that have requested this option and will become the new command-line default value. If false, the ModelParam p will be updated to the current value of the option. So, use useMyVal=true if your component wishes to push its current parameter value as the default for everyone using this option, and use false if your component wishes to use the current default instead.

Implements OptionManager.

Definition at line 584 of file CmdlineOptionManager.C.

References ASSERT, ModelOptionDef::exportFlag, CmdlineOptionManager::Impl::exportMask, ModelParamBase::getValString(), ModelOptionDef::longoptname, ModelOptionDef::name, CmdlineOptionManager::Impl::opts, dummy_namespace_to_avoid_gcc411_bug_CmdlineOptionManager_C::OptionInfo::params, setOptionValString(), and ModelParamBase::setValString().

Referenced by ModelManager::requestOption().

void CmdlineOptionManager::requestOptionAlias ( const ModelOptionDef def  )  [virtual]

Users may request model option aliases.

Parameters:
name the name of the option alias, from ModelOptionDefs.C

Implements OptionManager.

Definition at line 647 of file CmdlineOptionManager.C.

References ASSERT, ModelOptionDef::exportFlag, CmdlineOptionManager::Impl::exportMask, ModelOptionDef::longoptname, ModelOptionDef::name, CmdlineOptionManager::Impl::opts, and dummy_namespace_to_avoid_gcc411_bug_CmdlineOptionManager_C::OptionInfo::params.

Referenced by ModelManager::requestOptionAlias().

void CmdlineOptionManager::setOptionValString ( const ModelOptionDef def,
const std::string val 
) [virtual]

Set an option value.

All ModelParam objects associated this ModelOptionDef will be updated with the new value. Will throw a fatal error if the model has been started (see ModelComponent::start()).

Implements OptionManager.

Definition at line 671 of file CmdlineOptionManager.C.

References ASSERT, ModelOptionDef::name, CmdlineOptionManager::Impl::opts, dummy_namespace_to_avoid_gcc411_bug_CmdlineOptionManager_C::OptionInfo::params, and dummy_namespace_to_avoid_gcc411_bug_CmdlineOptionManager_C::OptionInfo::val.

Referenced by parseCommandLineCore(), requestOption(), and ModelManager::setOptionValString().

void CmdlineOptionManager::unRequestOption ( OptionedModelParam p  )  [virtual]

Request the removal of a param from the command-line options.

Parameters:
p the ModelParam data member of c corresponding to the option

Implements OptionManager.

Definition at line 628 of file CmdlineOptionManager.C.

References ASSERT, ModelOptionDef::longoptname, ModelOptionDef::name, CmdlineOptionManager::Impl::opts, and dummy_namespace_to_avoid_gcc411_bug_CmdlineOptionManager_C::OptionInfo::params.

Referenced by ModelManager::unRequestOption().


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:20:52 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3