Cgl 0.59.7

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinParam.hpp
Go to the documentation of this file.
1 /* $Id: CoinParam.hpp 1493 2011-11-01 16:56:07Z tkr $ */
2 #ifndef CoinParam_H
3 #define CoinParam_H
4
5 /*
6 Copyright (C) 2002, International Business Machines
7 Corporation and others. All Rights Reserved.
8
9 This code is licensed under the terms of the Eclipse Public License (EPL).
10 */
11
16 #include <vector>
17 #include <string>
18 #include <cstdio>
19
75 class CoinParam
76 {
77
78 public:
79
82
95 typedef enum { coinParamInvalid = 0,
96 coinParamAct, coinParamInt, coinParamDbl,
97 coinParamStr, coinParamKwd } CoinParamType ;
98
106 typedef int (*CoinParamFunc)(CoinParam *param) ;
107
109
116
119 CoinParam() ;
120
127 CoinParam(std::string name, std::string help,
128 double lower, double upper, double dflt = 0.0,
129 bool display = true) ;
130
135 CoinParam(std::string name, std::string help,
136 int lower, int upper, int dflt = 0,
137 bool display = true) ;
138
153 CoinParam(std::string name, std::string help,
154 std::string firstValue, int dflt, bool display = true) ;
155
164 CoinParam(std::string name, std::string help,
165 std::string dflt, bool display = true) ;
166
169 CoinParam(std::string name, std::string help,
170 bool display = true) ;
171
174 CoinParam(const CoinParam &orig) ;
175
178 virtual CoinParam *clone() ;
179
182 CoinParam &operator=(const CoinParam &rhs) ;
183
186 virtual ~CoinParam() ;
187
189
192
195 void appendKwd(std::string kwd) ;
196
201 int kwdIndex(std::string kwd) const ;
202
206 std::string kwdVal() const ;
207
214 void setKwdVal(int value, bool printIt = false) ;
215
222 void setKwdVal(const std::string value ) ;
223
227 void printKwds() const ;
228
229
232 void setStrVal(std::string value) ;
233
236 std::string strVal() const ;
237
238
241 void setDblVal(double value) ;
242
245 double dblVal() const ;
246
247
250 void setIntVal(int value) ;
251
254 int intVal() const ;
255
256
259 inline void setShortHelp(const std::string help) { shortHelp_ = help ; }
260
263 inline std::string shortHelp() const { return (shortHelp_) ; }
264
270 inline void setLongHelp(const std::string help) { longHelp_ = help ; }
271
274 inline std::string longHelp() const { return (longHelp_) ; }
275
284 void printLongHelp() const ;
285
287
290
293 inline CoinParamType type() const { return (type_) ; }
294
297 inline void setType(CoinParamType type) { type_ = type ; }
298
301 inline std::string name() const { return (name_) ; }
302
305 inline void setName(std::string name) { name_ = name ; processName() ; }
306
314 int matches (std::string input) const ;
315
322 std::string matchName() const ;
323
330 inline void setDisplay(bool display) { display_ = display ; }
331
334 inline bool display() const { return (display_) ; }
335
338 inline CoinParamFunc pushFunc() { return (pushFunc_) ; }
339
342 inline void setPushFunc(CoinParamFunc func) { pushFunc_ = func ; }
343
346 inline CoinParamFunc pullFunc() { return (pullFunc_) ; }
347
350 inline void setPullFunc(CoinParamFunc func) { pullFunc_ = func ; }
351
353
354 private:
355
358
360 void processName() ;
361
363
366 CoinParamType type_ ;
368
370 std::string name_ ;
371
373 size_t lengthName_ ;
374
378 size_t lengthMatch_ ;
379
381 double lowerDblValue_ ;
382
384 double upperDblValue_ ;
385
387 double dblValue_ ;
388
390 int lowerIntValue_ ;
391
393 int upperIntValue_ ;
394
396 int intValue_ ;
397
399 std::string strValue_ ;
400
402 std::vector<std::string> definedKwds_ ;
403
406 int currentKwd_ ;
407
409 CoinParamFunc pushFunc_ ;
410
412 CoinParamFunc pullFunc_ ;
413
415 std::string shortHelp_ ;
416
418 std::string longHelp_ ;
419
421 bool display_ ;
423
424 } ;
425
429 typedef std::vector<CoinParam*> CoinParamVec ;
430
434 std::ostream &operator<< (std::ostream &s, const CoinParam &param) ;
435
436 /*
437 Bring in the utility functions for parameter handling (CbcParamUtils).
438 */
439
447 namespace CoinParamUtils {
453 void setInputSrc(FILE *src) ;
454
458 bool isCommandLine() ;
459
463 bool isInteractive() ;
464
472 std::string getStringField(int argc, const char *argv[], int *valid) ;
473
481 int getIntField(int argc, const char *argv[], int *valid) ;
482
490 double getDoubleField(int argc, const char *argv[], int *valid) ;
491
504 int matchParam(const CoinParamVec &paramVec, std::string name,
505 int &matchNdx, int &shortCnt) ;
506
537 std::string getCommand(int argc, const char *argv[],
538 const std::string prompt, std::string *pfx = 0) ;
539
577 int lookupParam(std::string name, CoinParamVec &paramVec,
578 int *matchCnt = 0, int *shortCnt = 0, int *queryCnt = 0) ;
579
587 void printIt(const char *msg) ;
588 void shortOrHelpOne(CoinParamVec &paramVec,int matchNdx, std::string
605 name, int numQuery) ;
606
615 void shortOrHelpMany(CoinParamVec &paramVec,
616 std::string name, int numQuery) ;
617
623 void printGenericHelp() ;
624
637 void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam,
638 std::string prefix,
639 bool shortHelp, bool longHelp, bool hidden) ;
640 }
641
642
643 #endif /* CoinParam_H */
644
CoinParamUtils::matchParam
int matchParam(const CoinParamVec &paramVec, std::string name, int &matchNdx, int &shortCnt)
Scan a parameter vector for parameters whose keyword (name) string matches name using minimal match r...
CoinParam::intVal
int intVal() const
Get the value of a integer parameter.
CoinParamUtils::isCommandLine
bool isCommandLine()
Returns true if command line parameters are being processed.
CoinParamUtils::shortOrHelpMany
void shortOrHelpMany(CoinParamVec &paramVec, std::string name, int numQuery)
Utility routine to print help given multiple matches.
CoinParam::strValue_
std::string strValue_
String parameter - current value.
Definition: CoinParam.hpp:399
CoinParam::coinParamStr
Definition: CoinParam.hpp:97
CoinParam::operator=
CoinParam & operator=(const CoinParam &rhs)
Assignment.
CoinParam::pushFunc
CoinParamFunc pushFunc()
Get push function.
Definition: CoinParam.hpp:338
CoinParam::currentKwd_
int currentKwd_
Current value for a keyword parameter (index into definedKwds_)
Definition: CoinParam.hpp:406
CoinParam::shortHelp
std::string shortHelp() const
Retrieve the short help string.
Definition: CoinParam.hpp:263
CoinParam::shortHelp_
std::string shortHelp_
Short help.
Definition: CoinParam.hpp:415
CoinParam::setDblVal
void setDblVal(double value)
Set the value of a double parameter.
CoinParam::coinParamDbl
Definition: CoinParam.hpp:96
CoinParam::printIt
void printIt(const char *msg)
Utility to print a long message as filled lines of text.
CoinParam::coinParamInvalid
Definition: CoinParam.hpp:95
CoinParam::longHelp_
std::string longHelp_
Long help.
Definition: CoinParam.hpp:418
CoinParam::setIntVal
void setIntVal(int value)
Set the value of a integer parameter.
CoinParamUtils::getCommand
std::string getCommand(int argc, const char *argv[], const std::string prompt, std::string *pfx=0)
Get the next command keyword (name)
CoinParam::CoinParam
CoinParam()
Default constructor.
CoinParam::kwdIndex
int kwdIndex(std::string kwd) const
Return the integer associated with the specified value-keyword.
CoinParam::printLongHelp
void printLongHelp() const
Print long help.
CoinParam
A base class for `keyword value&#39; command line parameters.
Definition: CoinParam.hpp:75
CoinParamUtils::printIt
void printIt(const char *msg)
Utility to print a long message as filled lines of text.
CoinParam::printKwds
void printKwds() const
Prints the set of value-keywords defined for this keyword parameter.
CoinParam::setLongHelp
void setLongHelp(const std::string help)
Add a long help message to a parameter.
Definition: CoinParam.hpp:270
CoinParamUtils::setInputSrc
void setInputSrc(FILE *src)
Take command input from the file specified by src.
CoinParam::setPushFunc
void setPushFunc(CoinParamFunc func)
Set push function.
Definition: CoinParam.hpp:342
CoinParam::CoinParamFunc
int(* CoinParamFunc)(CoinParam *param)
Type declaration for push and pull functions.
Definition: CoinParam.hpp:106
CoinParamUtils::isInteractive
bool isInteractive()
Returns true if parameters are being obtained from stdin.
CoinParam::name
std::string name() const
Return the parameter keyword (name) string.
Definition: CoinParam.hpp:301
CoinParam::pushFunc_
CoinParamFunc pushFunc_
Push function.
Definition: CoinParam.hpp:409
CoinParam::dblVal
double dblVal() const
Get the value of a double parameter.
CoinParam::processName
void processName()
Process a name for efficient matching.
CoinParam::clone
virtual CoinParam * clone()
Clone.
CoinParam::setName
void setName(std::string name)
Set the parameter keyword (name) string.
Definition: CoinParam.hpp:305
CoinParam::pullFunc_
CoinParamFunc pullFunc_
Pull function.
Definition: CoinParam.hpp:412
CoinParamUtils::getStringField
std::string getStringField(int argc, const char *argv[], int *valid)
Attempt to read a string from the input.
CoinParamUtils::shortOrHelpOne
void shortOrHelpOne(CoinParamVec &paramVec, int matchNdx, std::string name, int numQuery)
Utility routine to print help given a short match or explicit request for help.
CoinParam::type_
CoinParamType type_
Parameter type (see CoinParamType)
Definition: CoinParam.hpp:367
CoinParam::lowerDblValue_
double lowerDblValue_
Lower bound on value for a double parameter.
Definition: CoinParam.hpp:381
CoinParam::matchName
std::string matchName() const
Return the parameter keyword (name) string formatted to show the minimum match length.
CoinParam::definedKwds_
std::vector< std::string > definedKwds_
Set of valid value-keywords for a keyword parameter.
Definition: CoinParam.hpp:402
CoinParam::coinParamAct
Definition: CoinParam.hpp:96
CoinParam::~CoinParam
virtual ~CoinParam()
Destructor.
CoinParam::coinParamInt
Definition: CoinParam.hpp:96
CoinParam::display
bool display() const
Get visibility of parameter.
Definition: CoinParam.hpp:334
CoinParam::CoinParamType
CoinParamType
Enumeration for the types of parameters supported by CoinParam.
Definition: CoinParam.hpp:95
CoinParamUtils::lookupParam
int lookupParam(std::string name, CoinParamVec &paramVec, int *matchCnt=0, int *shortCnt=0, int *queryCnt=0)
Look up the command keyword (name) in the parameter vector. Print help if requested.
CoinParam::setShortHelp
void setShortHelp(const std::string help)
Add a short help string to a parameter.
Definition: CoinParam.hpp:259
CoinParam::pullFunc
CoinParamFunc pullFunc()
Get pull function.
Definition: CoinParam.hpp:346
CoinParam::CoinParamVec
std::vector< CoinParam * > CoinParamVec
A type for a parameter vector.
Definition: CoinParam.hpp:429
CoinParam::lengthName_
size_t lengthName_
Length of parameter name.
Definition: CoinParam.hpp:373
CoinParam::upperDblValue_
double upperDblValue_
Upper bound on value for a double parameter.
Definition: CoinParam.hpp:384
CoinParamUtils::printGenericHelp
void printGenericHelp()
Print a generic `how to use the command interface&#39; help message.
CoinParam::type
CoinParamType type() const
Return the type of the parameter.
Definition: CoinParam.hpp:293
CoinParam::lowerIntValue_
int lowerIntValue_
Lower bound on value for an integer parameter.
Definition: CoinParam.hpp:390
CoinParam::display_
bool display_
Display when processing lists of parameters?
Definition: CoinParam.hpp:421
CoinParam::strVal
std::string strVal() const
Get the value of a string parameter.
CoinParam::setType
void setType(CoinParamType type)
Set the type of the parameter.
Definition: CoinParam.hpp:297
CoinParamUtils::getIntField
int getIntField(int argc, const char *argv[], int *valid)
Attempt to read an integer from the input.
CoinParam::matches
int matches(std::string input) const
Check if the specified string matches the parameter keyword (name) string.
CoinParam::dblValue_
double dblValue_
Double parameter - current value.
Definition: CoinParam.hpp:387
CoinParamUtils::printHelp
void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam, std::string prefix, bool shortHelp, bool longHelp, bool hidden)
Utility routine to print help messages for one or more parameters.
CoinParam::setKwdVal
void setKwdVal(int value, bool printIt=false)
Set the value of the keyword parameter using the integer associated with a value-keyword.
CoinParam::name_
std::string name_
Parameter name.
Definition: CoinParam.hpp:370
CoinParam::upperIntValue_
int upperIntValue_
Upper bound on value for an integer parameter.
Definition: CoinParam.hpp:393
CoinParam::appendKwd
void appendKwd(std::string kwd)
Add an additional value-keyword to a keyword parameter.
CoinParam::setPullFunc
void setPullFunc(CoinParamFunc func)
Set pull function.
Definition: CoinParam.hpp:350
CoinParamUtils::getDoubleField
double getDoubleField(int argc, const char *argv[], int *valid)
Attempt to read a real (double) from the input.
CoinParam::operator<<
std::ostream & operator<<(std::ostream &s, const CoinParam &param)
A stream output function for a CoinParam object.
CoinParam::lengthMatch_
size_t lengthMatch_
Minimum length required to declare a match for the parameter name.
Definition: CoinParam.hpp:378
CoinParam::setStrVal
void setStrVal(std::string value)
Set the value of a string parameter.
CoinParam::kwdVal
std::string kwdVal() const
Return the value-keyword that is the current value of the keyword parameter.
CoinParam::longHelp
std::string longHelp() const
Retrieve the long help message.
Definition: CoinParam.hpp:274
CoinParam::intValue_
int intValue_
Integer parameter - current value.
Definition: CoinParam.hpp:396
CoinParam::setDisplay
void setDisplay(bool display)
Set visibility of parameter.
Definition: CoinParam.hpp:330
CoinParam::coinParamKwd
Definition: CoinParam.hpp:97