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

- File List
- File Members

# /home/coin/SVN-release/Alps-1.3.0/CoinUtils/src/CoinParam.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinParam.hpp 1448 2011-06-19 15:34:41Z stefan $ */
    00002 #ifndef CoinParam_H
    00003 #define CoinParam_H
    00004
    00005 /*
    00006   Copyright (C) 2002, International Business Machines
    00007   Corporation and others.  All Rights Reserved.
    00008
    00009   This code is licensed under the terms of the Eclipse Public License (EPL).
    00010 */
    00011
    00016 #include <vector>
    00017 #include <string>
    00018
    00074 class CoinParam
    00075 {
    00076
    00077 public:
    00078
    00081
    00094   typedef enum { coinParamInvalid = 0,
    00095                  coinParamAct, coinParamInt, coinParamDbl,
    00096                  coinParamStr, coinParamKwd } CoinParamType ;
    00097
    00105   typedef int (*CoinParamFunc)(CoinParam *param) ;
    00106
    00108
    00115
    00118   CoinParam() ;
    00119
    00126   CoinParam(std::string name, std::string help,
    00127             double lower, double upper, double dflt = 0.0,
    00128             bool display = true) ;
    00129
    00134   CoinParam(std::string name, std::string help,
    00135             int lower, int upper, int dflt = 0,
    00136             bool display = true) ;
    00137
    00152   CoinParam(std::string name, std::string help,
    00153             std::string firstValue, int dflt, bool display = true) ;
    00154
    00163   CoinParam(std::string name, std::string help,
    00164             std::string dflt, bool display = true) ;
    00165
    00168   CoinParam(std::string name, std::string help,
    00169             bool display = true) ;
    00170
    00173   CoinParam(const CoinParam &orig) ;
    00174
    00177   virtual CoinParam *clone() ;
    00178
    00181     CoinParam &operator=(const CoinParam &rhs) ;
    00182
    00185   virtual ~CoinParam() ;
    00186
    00188
    00191
    00194   void appendKwd(std::string kwd) ;
    00195
    00200   int kwdIndex(std::string kwd) const ;
    00201
    00205   std::string kwdVal() const ;
    00206
    00213   void setKwdVal(int value, bool printIt = false) ;
    00214
    00221   void setKwdVal(const std::string value ) ;
    00222
    00226   void printKwds() const ;
    00227
    00228
    00231   void setStrVal(std::string value) ;
    00232
    00235   std::string strVal() const ;
    00236
    00237
    00240   void setDblVal(double value) ;
    00241
    00244   double dblVal() const ;
    00245
    00246
    00249   void setIntVal(int value) ;
    00250
    00253   int intVal() const ;
    00254
    00255
    00258   inline void setShortHelp(const std::string help) { shortHelp_ = help ; }
    00259
    00262   inline std::string shortHelp() const { return (shortHelp_) ; }
    00263
    00269   inline void setLongHelp(const std::string help) { longHelp_ = help ; }
    00270
    00273   inline std::string longHelp() const { return (longHelp_) ; }
    00274
    00283   void printLongHelp() const ;
    00284
    00286
    00289
    00292   inline CoinParamType type() const { return (type_) ; }
    00293
    00296   inline void setType(CoinParamType type) { type_ = type ; }
    00297
    00300   inline std::string  name() const { return (name_) ; }
    00301
    00304   inline void setName(std::string name) { name_ = name ; processName() ; }
    00305
    00313   int matches (std::string input) const ;
    00314
    00321   std::string matchName() const ;
    00322
    00329   inline void setDisplay(bool display) { display_ = display ; }
    00330
    00333   inline bool display() const { return (display_) ; }
    00334
    00337   inline CoinParamFunc pushFunc() { return (pushFunc_) ; }
    00338
    00341   inline void setPushFunc(CoinParamFunc func) { pushFunc_ = func ; }
    00342
    00345   inline CoinParamFunc pullFunc() { return (pullFunc_) ; }
    00346
    00349   inline void setPullFunc(CoinParamFunc func) { pullFunc_ = func ; }
    00350
    00352
    00353 private:
    00354
    00357
    00359   void processName() ;
    00360
    00362
    00365
    00366   CoinParamType type_ ;
    00367
    00369   std::string name_ ;
    00370
    00372   size_t lengthName_ ;
    00373
    00377   size_t lengthMatch_ ;
    00378
    00380   double lowerDblValue_ ;
    00381
    00383   double upperDblValue_ ;
    00384
    00386   double dblValue_ ;
    00387
    00389   int lowerIntValue_ ;
    00390
    00392   int upperIntValue_ ;
    00393
    00395   int intValue_ ;
    00396
    00398   std::string strValue_ ;
    00399
    00401   std::vector<std::string> definedKwds_ ;
    00402
    00405   int currentKwd_ ;
    00406
    00408   CoinParamFunc pushFunc_ ;
    00409
    00411   CoinParamFunc pullFunc_ ;
    00412
    00414   std::string shortHelp_ ;
    00415
    00417   std::string longHelp_ ;
    00418
    00420   bool display_ ;
    00422
    00423 } ;
    00424
    00428 typedef std::vector<CoinParam*> CoinParamVec ;
    00429
    00433 std::ostream &operator<< (std::ostream &s, const CoinParam &param) ;
    00434
    00435 /*
    00436   Bring in the utility functions for parameter handling (CbcParamUtils).
    00437 */
    00438
    00446 namespace CoinParamUtils {
    00452   void setInputSrc(FILE *src) ;
    00453
    00457   bool isCommandLine() ;
    00458
    00462   bool isInteractive() ;
    00463
    00471   std::string getStringField(int argc, const char *argv[], int *valid) ;
    00472
    00480   int getIntField(int argc, const char *argv[], int *valid) ;
    00481
    00489   double getDoubleField(int argc, const char *argv[], int *valid) ;
    00490
    00503   int matchParam(const CoinParamVec &paramVec, std::string name,
    00504                  int &matchNdx, int &shortCnt) ;
    00505
    00536   std::string getCommand(int argc, const char *argv[],
    00537                          const std::string prompt, std::string *pfx = 0) ;
    00538
    00576   int lookupParam(std::string name, CoinParamVec &paramVec,
    00577                   int *matchCnt = 0, int *shortCnt = 0, int *queryCnt = 0) ;
    00578
    00586   void printIt(const char *msg) ;
    00587  void shortOrHelpOne(CoinParamVec &paramVec,int matchNdx, std::string
    00604   name, int numQuery) ;
    00605
    00614   void shortOrHelpMany(CoinParamVec &paramVec,
    00615                        std::string name, int numQuery) ;
    00616
    00622   void printGenericHelp() ;
    00623
    00636   void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam,
    00637                  std::string prefix,
    00638                  bool shortHelp, bool longHelp, bool hidden) ;
    00639 }
    00640
    00641
    00642 #endif  /* CoinParam_H */
    00643