Clp  1.17.6
 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 2083 2019-01-06 19:38:09Z unxusr $ */
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 public:
80 
93  typedef enum { coinParamInvalid = 0,
99 
107  typedef int (*CoinParamFunc)(CoinParam *param);
108 
110 
117 
120  CoinParam();
121 
128  CoinParam(std::string name, std::string help,
129  double lower, double upper, double dflt = 0.0,
130  bool display = true);
131 
136  CoinParam(std::string name, std::string help,
137  int lower, int upper, int dflt = 0,
138  bool display = true);
139 
154  CoinParam(std::string name, std::string help,
155  std::string firstValue, int dflt, bool display = true);
156 
165  CoinParam(std::string name, std::string help,
166  std::string dflt, bool display = true);
167 
170  CoinParam(std::string name, std::string help,
171  bool display = true);
172 
175  CoinParam(const CoinParam &orig);
176 
179  virtual CoinParam *clone();
180 
183  CoinParam &operator=(const CoinParam &rhs);
184 
187  virtual ~CoinParam();
188 
190 
193 
196  void appendKwd(std::string kwd);
197 
202  int kwdIndex(std::string kwd) const;
203 
207  std::string kwdVal() const;
208 
215  void setKwdVal(int value, bool printIt = false);
216 
223  void setKwdVal(const std::string value);
224 
228  void printKwds() const;
229 
232  void setStrVal(std::string value);
233 
236  std::string strVal() const;
237 
240  void setDblVal(double value);
241 
244  double dblVal() const;
245 
248  void setIntVal(int value);
249 
252  int intVal() const;
253 
256  inline void setShortHelp(const std::string help) { shortHelp_ = help; }
257 
260  inline std::string shortHelp() const { return (shortHelp_); }
261 
267  inline void setLongHelp(const std::string help) { longHelp_ = help; }
268 
271  inline std::string longHelp() const { return (longHelp_); }
272 
281  void printLongHelp() const;
282 
284 
287 
290  inline CoinParamType type() const { return (type_); }
291 
294  inline void setType(CoinParamType type) { type_ = type; }
295 
298  inline std::string name() const { return (name_); }
299 
302  inline void setName(std::string name)
303  {
304  name_ = name;
305  processName();
306  }
307 
315  int matches(std::string input) const;
316 
323  std::string matchName() const;
324 
331  inline void setDisplay(bool display) { display_ = display; }
332 
335  inline bool display() const { return (display_); }
336 
339  inline CoinParamFunc pushFunc() { return (pushFunc_); }
340 
343  inline void setPushFunc(CoinParamFunc func) { pushFunc_ = func; }
344 
347  inline CoinParamFunc pullFunc() { return (pullFunc_); }
348 
351  inline void setPullFunc(CoinParamFunc func) { pullFunc_ = func; }
352 
354 
355 private:
358 
360  void processName();
361 
363 
368 
370  std::string name_;
371 
373  size_t lengthName_;
374 
378  size_t lengthMatch_;
379 
382 
385 
387  double dblValue_;
388 
391 
394 
397 
399  std::string strValue_;
400 
402  std::vector< std::string > definedKwds_;
403 
407 
410 
413 
415  std::string shortHelp_;
416 
418  std::string longHelp_;
419 
421  bool display_;
423 };
424 
428 typedef std::vector< CoinParam * > CoinParamVec;
429 
433 std::ostream &operator<<(std::ostream &s, const CoinParam &param);
434 
435 /*
436  Bring in the utility functions for parameter handling (CbcParamUtils).
437 */
438 
446 namespace CoinParamUtils {
452 void setInputSrc(FILE *src);
453 
457 bool isCommandLine();
458 
462 bool isInteractive();
463 
471 std::string getStringField(int argc, const char *argv[], int *valid);
472 
480 int getIntField(int argc, const char *argv[], int *valid);
481 
489 double getDoubleField(int argc, const char *argv[], int *valid);
490 
503 int matchParam(const CoinParamVec &paramVec, std::string name,
504  int &matchNdx, int &shortCnt);
505 
536 std::string getCommand(int argc, const char *argv[],
537  const std::string prompt, std::string *pfx = 0);
538 
576 int lookupParam(std::string name, CoinParamVec &paramVec,
577  int *matchCnt = 0, int *shortCnt = 0, int *queryCnt = 0);
578 
586 void printIt(const char *msg);
587 
604 void shortOrHelpOne(CoinParamVec &paramVec, int matchNdx, std::string name, int numQuery);
605 
614 void shortOrHelpMany(CoinParamVec &paramVec,
615  std::string name, int numQuery);
616 
622 void printGenericHelp();
623 
636 void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam,
637  std::string prefix,
638  bool shortHelp, bool longHelp, bool hidden);
639 }
640 
641 #endif /* CoinParam_H */
642 
643 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
644 */
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...
int intVal() const
Get the value of a integer parameter.
bool isCommandLine()
Returns true if command line parameters are being processed.
void shortOrHelpMany(CoinParamVec &paramVec, std::string name, int numQuery)
Utility routine to print help given multiple matches.
std::string strValue_
String parameter - current value.
Definition: CoinParam.hpp:399
CoinParam & operator=(const CoinParam &rhs)
Assignment.
CoinParamFunc pushFunc()
Get push function.
Definition: CoinParam.hpp:339
std::vector< CoinParam * > CoinParamVec
A type for a parameter vector.
Definition: CoinParam.hpp:428
int currentKwd_
Current value for a keyword parameter (index into definedKwds_)
Definition: CoinParam.hpp:406
std::string shortHelp() const
Retrieve the short help string.
Definition: CoinParam.hpp:260
std::string shortHelp_
Short help.
Definition: CoinParam.hpp:415
void setDblVal(double value)
Set the value of a double parameter.
void printIt(const char *msg)
Utility to print a long message as filled lines of text.
std::string longHelp_
Long help.
Definition: CoinParam.hpp:418
void setIntVal(int value)
Set the value of a integer parameter.
std::string getCommand(int argc, const char *argv[], const std::string prompt, std::string *pfx=0)
Get the next command keyword (name)
CoinParam()
Default constructor.
int kwdIndex(std::string kwd) const
Return the integer associated with the specified value-keyword.
void printLongHelp() const
Print long help.
A base class for `keyword value&#39; command line parameters.
Definition: CoinParam.hpp:75
void printIt(const char *msg)
Utility to print a long message as filled lines of text.
void printKwds() const
Prints the set of value-keywords defined for this keyword parameter.
void setLongHelp(const std::string help)
Add a long help message to a parameter.
Definition: CoinParam.hpp:267
void setInputSrc(FILE *src)
Take command input from the file specified by src.
void setPushFunc(CoinParamFunc func)
Set push function.
Definition: CoinParam.hpp:343
int(* CoinParamFunc)(CoinParam *param)
Type declaration for push and pull functions.
Definition: CoinParam.hpp:107
bool isInteractive()
Returns true if parameters are being obtained from stdin.
std::string name() const
Return the parameter keyword (name) string.
Definition: CoinParam.hpp:298
CoinParamFunc pushFunc_
Push function.
Definition: CoinParam.hpp:409
double dblVal() const
Get the value of a double parameter.
void processName()
Process a name for efficient matching.
virtual CoinParam * clone()
Clone.
void setName(std::string name)
Set the parameter keyword (name) string.
Definition: CoinParam.hpp:302
CoinParamFunc pullFunc_
Pull function.
Definition: CoinParam.hpp:412
std::string getStringField(int argc, const char *argv[], int *valid)
Attempt to read a string from the input.
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.
CoinParamType type_
Parameter type (see CoinParamType)
Definition: CoinParam.hpp:367
double lowerDblValue_
Lower bound on value for a double parameter.
Definition: CoinParam.hpp:381
std::string matchName() const
Return the parameter keyword (name) string formatted to show the minimum match length.
virtual ~CoinParam()
Destructor.
std::vector< std::string > definedKwds_
Set of valid value-keywords for a keyword parameter.
Definition: CoinParam.hpp:402
bool display() const
Get visibility of parameter.
Definition: CoinParam.hpp:335
CoinParamType
Enumeration for the types of parameters supported by CoinParam.
Definition: CoinParam.hpp:93
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.
void setShortHelp(const std::string help)
Add a short help string to a parameter.
Definition: CoinParam.hpp:256
CoinParamFunc pullFunc()
Get pull function.
Definition: CoinParam.hpp:347
size_t lengthName_
Length of parameter name.
Definition: CoinParam.hpp:373
double upperDblValue_
Upper bound on value for a double parameter.
Definition: CoinParam.hpp:384
void printGenericHelp()
Print a generic `how to use the command interface&#39; help message.
CoinParamType type() const
Return the type of the parameter.
Definition: CoinParam.hpp:290
int lowerIntValue_
Lower bound on value for an integer parameter.
Definition: CoinParam.hpp:390
bool display_
Display when processing lists of parameters?
Definition: CoinParam.hpp:421
std::string strVal() const
Get the value of a string parameter.
void setType(CoinParamType type)
Set the type of the parameter.
Definition: CoinParam.hpp:294
int getIntField(int argc, const char *argv[], int *valid)
Attempt to read an integer from the input.
int matches(std::string input) const
Check if the specified string matches the parameter keyword (name) string.
double dblValue_
Double parameter - current value.
Definition: CoinParam.hpp:387
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.
void setKwdVal(int value, bool printIt=false)
Set the value of the keyword parameter using the integer associated with a value-keyword.
std::string name_
Parameter name.
Definition: CoinParam.hpp:370
int upperIntValue_
Upper bound on value for an integer parameter.
Definition: CoinParam.hpp:393
void appendKwd(std::string kwd)
Add an additional value-keyword to a keyword parameter.
void setPullFunc(CoinParamFunc func)
Set pull function.
Definition: CoinParam.hpp:351
double getDoubleField(int argc, const char *argv[], int *valid)
Attempt to read a real (double) from the input.
std::ostream & operator<<(std::ostream &s, const CoinParam &param)
A stream output function for a CoinParam object.
size_t lengthMatch_
Minimum length required to declare a match for the parameter name.
Definition: CoinParam.hpp:378
void setStrVal(std::string value)
Set the value of a string parameter.
std::string kwdVal() const
Return the value-keyword that is the current value of the keyword parameter.
std::string longHelp() const
Retrieve the long help message.
Definition: CoinParam.hpp:271
int intValue_
Integer parameter - current value.
Definition: CoinParam.hpp:396
void setDisplay(bool display)
Set visibility of parameter.
Definition: CoinParam.hpp:331