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

- File List
- File Members

# /home/coin/SVN-release/Osi-0.98.1/CoinUtils/src/CoinParam.hpp

Go to the documentation of this file.

    00001 #ifndef CoinParam_H
    00002 #define CoinParam_H
    00003
    00004 /*
    00005   Copyright (C) 2002, International Business Machines
    00006   Corporation and others.  All Rights Reserved.
    00007 */
    00008
    00013 #include <vector>
    00014 #include <string>
    00015
    00071 class CoinParam
    00072 {
    00073
    00074 public:
    00075
    00078
    00091   typedef enum { coinParamInvalid = 0,
    00092                  coinParamAct, coinParamInt, coinParamDbl,
    00093                  coinParamStr, coinParamKwd } CoinParamType ;
    00094
    00102   typedef int (*CoinParamFunc)(CoinParam *param) ;
    00103
    00105
    00112
    00115   CoinParam() ;
    00116
    00123   CoinParam(std::string name, std::string help,
    00124             double lower, double upper, double dflt = 0.0,
    00125             bool display = true) ;
    00126
    00131   CoinParam(std::string name, std::string help,
    00132             int lower, int upper, int dflt = 0,
    00133             bool display = true) ;
    00134
    00149   CoinParam(std::string name, std::string help,
    00150             std::string firstValue, int dflt, bool display = true) ;
    00151
    00160   CoinParam(std::string name, std::string help,
    00161             std::string dflt, bool display = true) ;
    00162
    00165   CoinParam(std::string name, std::string help,
    00166             bool display = true) ;
    00167
    00170   CoinParam(const CoinParam &orig) ;
    00171
    00174   virtual CoinParam *clone() ;
    00175
    00178     CoinParam &operator=(const CoinParam &rhs) ;
    00179
    00182   virtual ~CoinParam() ;
    00183
    00185
    00188
    00191   void appendKwd(std::string kwd) ;
    00192
    00197   int kwdIndex(std::string kwd) const ;
    00198
    00202   std::string kwdVal() const ;
    00203
    00210   void setKwdVal(int value, bool printIt = false) ;
    00211
    00218   void setKwdVal(const std::string value ) ;
    00219
    00223   void printKwds() const ;
    00224
    00225
    00228   void setStrVal(std::string value) ;
    00229
    00232   std::string strVal() const ;
    00233
    00234
    00237   void setDblVal(double value) ;
    00238
    00241   double dblVal() const ;
    00242
    00243
    00246   void setIntVal(int value) ;
    00247
    00250   int intVal() const ;
    00251
    00252
    00255   inline void setShortHelp(const std::string help) { shortHelp_ = help ; }
    00256
    00259   inline std::string shortHelp() const { return (shortHelp_) ; }
    00260
    00266   inline void setLongHelp(const std::string help) { longHelp_ = help ; }
    00267
    00270   inline std::string longHelp() const { return (longHelp_) ; }
    00271
    00280   void printLongHelp() const ;
    00281
    00283
    00286
    00289   inline CoinParamType type() const { return (type_) ; }
    00290
    00293   inline void setType(CoinParamType type) { type_ = type ; }
    00294
    00297   inline std::string  name() const { return (name_) ; }
    00298
    00301   inline void setName(std::string name) { name_ = name ; processName() ; }
    00302
    00310   int matches (std::string input) const ;
    00311
    00318   std::string matchName() const ;
    00319
    00326   inline void setDisplay(bool display) { display_ = display ; }
    00327
    00330   inline bool display() const { return (display_) ; }
    00331
    00334   inline CoinParamFunc pushFunc() { return (pushFunc_) ; }
    00335
    00338   inline void setPushFunc(CoinParamFunc func) { pushFunc_ = func ; }
    00339
    00342   inline CoinParamFunc pullFunc() { return (pullFunc_) ; }
    00343
    00346   inline void setPullFunc(CoinParamFunc func) { pullFunc_ = func ; }
    00347
    00349
    00350 private:
    00351
    00354
    00356   void processName() ;
    00357
    00359
    00362
    00363   CoinParamType type_ ;
    00364
    00366   std::string name_ ;
    00367
    00369   unsigned int lengthName_ ;
    00370
    00374   unsigned int lengthMatch_ ;
    00375
    00377   double lowerDblValue_ ;
    00378
    00380   double upperDblValue_ ;
    00381
    00383   double dblValue_ ;
    00384
    00386   int lowerIntValue_ ;
    00387
    00389   int upperIntValue_ ;
    00390
    00392   int intValue_ ;
    00393
    00395   std::string strValue_ ;
    00396
    00398   std::vector<std::string> definedKwds_ ;
    00399
    00402   int currentKwd_ ;
    00403
    00405   CoinParamFunc pushFunc_ ;
    00406
    00408   CoinParamFunc pullFunc_ ;
    00409
    00411   std::string shortHelp_ ;
    00412
    00414   std::string longHelp_ ;
    00415
    00417   bool display_ ;
    00419
    00420 } ;
    00421
    00425 typedef std::vector<CoinParam*> CoinParamVec ;
    00426
    00430 std::ostream &operator<< (std::ostream &s, const CoinParam &param) ;
    00431
    00432 /*
    00433   Bring in the utility functions for parameter handling (CbcParamUtils).
    00434 */
    00435
    00443 namespace CoinParamUtils {
    00449   void setInputSrc(FILE *src) ;
    00450
    00454   bool isCommandLine() ;
    00455
    00459   bool isInteractive() ;
    00460
    00468   std::string getStringField(int argc, const char *argv[], int *valid) ;
    00469
    00477   int getIntField(int argc, const char *argv[], int *valid) ;
    00478
    00486   double getDoubleField(int argc, const char *argv[], int *valid) ;
    00487
    00500   int matchParam(const CoinParamVec &paramVec, std::string name,
    00501                  int &matchNdx, int &shortCnt) ;
    00502
    00533   std::string getCommand(int argc, const char *argv[],
    00534                          const std::string prompt, std::string *pfx = 0) ;
    00535
    00573   int lookupParam(std::string name, CoinParamVec &paramVec,
    00574                   int *matchCnt = 0, int *shortCnt = 0, int *queryCnt = 0) ;
    00575
    00583   void printIt(const char *msg) ;
    00584  void shortOrHelpOne(CoinParamVec &paramVec,int matchNdx, std::string
    00601   name, int numQuery) ;
    00602
    00611   void shortOrHelpMany(CoinParamVec &paramVec,
    00612                        std::string name, int numQuery) ;
    00613
    00619   void printGenericHelp() ;
    00620
    00633   void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam,
    00634                  std::string prefix,
    00635                  bool shortHelp, bool longHelp, bool hidden) ;
    00636 }
    00637
    00638
    00639 #endif  /* CoinParam_H */
    00640