CoinParam

A base class for keyword value command line parameters.

A base class for keyword value command line parameters.

Description

The underlying paradigm is that a parameter specifies an action to be performed on a target object. The base class provides two function pointers, a push function and a pull function. By convention, a push function will set some value in the target object or perform some action using the target object. A pull function will retrieve some value from the target object. This is only a convention, however; CoinParam and associated utilities make no use of these functions and have no hardcoded notion of how they should be used. The action to be performed, and the target object, will be specific to a particular application. It is expected that users will derive application-specific parameter classes from this base class. A derived class will typically add fields and methods to set/get a code for the action to be performed (often, an enum class) and the target object (often, a pointer or reference). Facilities provided by the base class and associated utility routines include: Support for common parameter types with numeric, string, or keyword values. Support for short and long help messages. Pointers to push and pull functions as described above. Command line parsing and keyword matching. All utility routines are declared in the CoinParamUtils namespace. The base class recognises five types of parameters: actions (which require no value); numeric parameters with integer or real (double) values; keyword parameters, where the value is one of a defined set of value-keywords; and string parameters (where the value is a string). The base class supports the definition of a valid range, a default value, and short and long help messages for a parameter. As defined by the CoinParamFunc typedef, push and pull functions should take a single parameter, a pointer to a CoinParam. Typically this object will actually be a derived class as described above, and the implementation function will have access to all capabilities of CoinParam and of the derived class. When specified as command line parameters, the expected syntax is -keyword value or -keyword=value. You can also use the Gnu double-dash style, --keyword. Spaces around the = will not work. The keyword (name) for a parameter can be defined with an ! to mark the minimal match point. For example, allow!ableGap will be considered matched by the strings allow, allowa, allowab, etc. Similarly, the value-keyword strings for keyword parameters can be defined with ! to mark the minimal match point. Matching of keywords and value-keywords is not case sensitive.

Public Methods

CoinParam

Default constructor.

 CoinParam()

CoinParam

Constructor for a parameter with a double value.

 CoinParam(std::string name, std::string help, double lower = -, double upper, std::string longHelp = "", CoinDisplayPriority displayPriority)

Parameters:

CoinParam

Constructor for a parameter with an integer value.

 CoinParam(std::string name, std::string help, int lower = -, int upper, std::string longHelp = "", CoinDisplayPriority displayPriority)

Parameters:

CoinParam

Constructor for any parameter taking a string (or no) value (all others). Type is not optional to resolve ambiguity.

 CoinParam(std::string name, CoinParamType type, std::string help, std::string longHelp = "", CoinDisplayPriority displayPriority)

Parameters:

CoinParam

Copy constructor.

 CoinParam(const CoinParam & orig)

Parameters:

clone

Clone.

CoinParam * clone()

operator=

Assignment.

CoinParam & operator=(const CoinParam & rhs)

Parameters:

~CoinParam

Destructor.

 ~CoinParam()

setup

These mirror the constructors with the addition of long help.

void setup(std::string name, std::string help, double lower = -, double upper, std::string longHelp = "", CoinDisplayPriority display)

Parameters:

setup

void setup(std::string name, std::string help, int lower = -, int upper, std::string longHelp = "", CoinDisplayPriority display)

Parameters:

setup

void setup(std::string name, std::string help, std::string longHelp = "", CoinDisplayPriority display)

Parameters:

setVal

int setVal(std::string value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setVal

int setVal(double value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setVal

int setVal(int value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setDefault

int setDefault(std::string value, std::string * message = NULL)

Parameters:

setDefault

int setDefault(double value, std::string * message = NULL)

Parameters:

setDefault

int setDefault(int value, std::string * message = NULL)

Parameters:

restoreDefault

int restoreDefault()

getVal

int getVal(std::string & value)

Parameters:

getVal

int getVal(double & value)

Parameters:

getVal

int getVal(int & value)

Parameters:

readValue

int readValue(std::deque< std::string > & inputQueue, std::string & value, std::string * message = NULL)

Parameters:

readValue

int readValue(std::deque< std::string > & inputQueue, int & value, std::string * message = NULL)

Parameters:

readValue

int readValue(std::deque< std::string > & inputQueue, double & value, std::string * message = NULL)

Parameters:

appendKwd

Add an additional value-keyword to a keyword parameter.

void appendKwd(std::string kwd, int index)

Parameters:

appendKwd

Add an additional value-keyword to a keyword parameter, generating sequential mode values.

void appendKwd(std::string kwd)

Parameters:

kwdToMode

Return the integer associated with the specified value-keyword.

int kwdToMode(std::string kwd)

Parameters:

kwdVal

Return the value-keyword that is the current value of the keyword parameter.

std::string kwdVal()

modeVal

Return the integer mode value of the current keyword parameter.

int modeVal()

modeString

Return the string for an integer mode of keyword parameter.

std::string modeString(int value)

Parameters:

setModeVal

Set the value of the keyword parameter using the integer associated with a value-keyword.

int setModeVal(int value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setModeValDefault

Set the default value of the keyword parameter using the integer associated with a value-keyword.

int setModeValDefault(int value, std::string * message = NULL)

Parameters:

setKwdVal

Set the value of the keyword parameter using a value-keyword string.

int setKwdVal(const std::string value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setKwdValDefault

Set the default value of the keyword parameter using a value-keyword string.

int setKwdValDefault(const std::string value, std::string * message = NULL)

Parameters:

printKwds

Prints the set of value-keywords defined for this keyword parameter.

std::string printKwds()

definedKwds

Set of valid value-keywords for a keyword parameter.

const std::map< std::string, int > & definedKwds()

definedKwdsSorted

Valid value-keywords for a keyword parameter sorted by integer mode.

std::vector< std::string > definedKwdsSorted()

setStrVal

Set the value of a string parameter.

int setStrVal(std::string value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setStrValDefault

Set the default value of a string parameter.

int setStrValDefault(std::string value, std::string * message = NULL)

Parameters:

strVal

Get the value of a string parameter.

std::string strVal()

setDirName

Set the value of a directory parameter.

int setDirName(std::string value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setDirNameDefault

Set the default value of a directory parameter.

int setDirNameDefault(std::string value, std::string * message = NULL)

Parameters:

dirName

Get the value of a directory parameter.

std::string dirName()

setFileName

Set the value of a file name parameter.

int setFileName(std::string value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setFileNameDefault

Set the default value of a file name parameter.

int setFileNameDefault(std::string value, std::string * message = NULL)

Parameters:

fileName

Get the value of a file name parameter.

std::string fileName()

setDblVal

Set the value of a double parameter.

int setDblVal(double value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setDblValDefault

Set the default value of a double parameter.

int setDblValDefault(double value, std::string * message = NULL)

Parameters:

dblVal

Get the value of a double parameter.

double dblVal()

setLowerDblVal

Set the lower value of an double parameter.

void setLowerDblVal(double value)

Parameters:

lowerDblVal

Get the lower value of a double parameter.

double lowerDblVal()

setUpperDblVal

Set the upper value of a double parameter.

void setUpperDblVal(double value)

Parameters:

upperDblVal

Get the upper value of a double parameter.

double upperDblVal()

setIntVal

Set the value of a integer parameter.

int setIntVal(int value, std::string * message = NULL, ParamPushMode pMode)

Parameters:

setIntValDefault

Set the value of a integer parameter.

int setIntValDefault(int value, std::string * message = NULL)

Parameters:

intVal

Get the value of a integer parameter.

int intVal()

setLowerIntVal

Set the lower value of an integer parameter.

void setLowerIntVal(int value)

Parameters:

lowerIntVal

Get the lower value of a integer parameter.

int lowerIntVal()

setUpperIntVal

Set the upper value of a integer parameter.

void setUpperIntVal(int value)

Parameters:

upperIntVal

Get the upper value of a integer parameter.

int upperIntVal()

printOptions

Print possible options for a keyword parameter.

void printOptions(std::string * message = NULL)

Parameters:

setShortHelp

Add a short help string to a parameter.

void setShortHelp(const std::string help)

Parameters:

shortHelp

Retrieve the short help string.

std::string shortHelp()

setLongHelp

Add a long help message to a parameter.

void setLongHelp(const std::string help)

Parameters:

longHelp

Retrieve the long help message.

std::string longHelp()

printLongHelp

Print long help.

std::string printLongHelp()

type

Return the type of the parameter.

CoinParamType type()

setType

Set the type of the parameter.

void setType(CoinParamType type)

Parameters:

name

Return the parameter keyword (name) string.

std::string name()

setName

Set the parameter keyword (name) string.

void setName(std::string name)

Parameters:

matches

Check if the specified string matches the parameter keyword (name) string.

int matches(std::string input)

Parameters:

matchName

Return the parameter keyword (name) string formatted to show the minimum match length.

std::string matchName()

lengthMatchName

Return the length of the formatted paramter name for printing.

int lengthMatchName()

setDisplayPriority

Set visibility of parameter.

void setDisplayPriority(CoinDisplayPriority display)

Parameters:

getDisplayPriority

Get visibility of parameter.

CoinDisplayPriority getDisplayPriority()

pushFunc

Get push function.

CoinParamFunc pushFunc()

setPushFunc

Set push function.

void setPushFunc(CoinParamFunc func)

Parameters:

pullFunc

Get pull function.

CoinParamFunc pullFunc()

setPullFunc

Set pull function.

void setPullFunc(CoinParamFunc func)

Parameters:

operator<<

A stream output function for a CoinParam object.

COINUTILSLIB_EXPORT std::ostream & operator<<(std::ostream & s, const CoinParam & param)

Parameters:

matchParam

Scan a parameter vector for parameters whose keyword (name) string matches name using minimal match rules.

COINUTILSLIB_EXPORT int matchParam(const CoinParamVec & paramVec, std::string name, int & matchNdx, int & shortCnt)

Parameters:

lookupParam

Look up the command keyword (name) in the parameter vector. Print help if requested.

COINUTILSLIB_EXPORT int lookupParam(std::string name, CoinParamVec & paramVec, int * matchCnt = 0, int * shortCnt = 0, int * queryCnt = 0)

Parameters:

printIt

Utility to print a long message as filled lines of text.

COINUTILSLIB_EXPORT void printIt(const char * msg)

Parameters:

shortOrHelpOne

Utility routine to print help given a short match or explicit request for help.

COINUTILSLIB_EXPORT void shortOrHelpOne(CoinParamVec & paramVec, int matchNdx, std::string name, int numQuery)

Parameters:

shortOrHelpMany

Utility routine to print help given multiple matches.

COINUTILSLIB_EXPORT void shortOrHelpMany(CoinParamVec & paramVec, std::string name, int numQuery)

Parameters:

printGenericHelp

Print a generic how to use the command interface help message.

COINUTILSLIB_EXPORT void printGenericHelp()

printHelp

Utility routine to print help messages for one or more parameters.

COINUTILSLIB_EXPORT void printHelp(CoinParamVec & paramVec, int firstParam, int lastParam, std::string prefix, bool shortHelp, bool longHelp, bool hidden)

Parameters:

Source

Header: layer-0/CoinUtils/src/CoinParam.hpp