CoinUtils  trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CoinParam.hpp
Go to the documentation of this file.
00001 /* $Id$ */
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 #include <cstdio>
00019 
00075 class CoinParam
00076 {
00077  
00078 public:
00079 
00082 
00095   typedef enum { coinParamInvalid = 0,
00096                  coinParamAct, coinParamInt, coinParamDbl,
00097                  coinParamStr, coinParamKwd } CoinParamType ;
00098 
00106   typedef int (*CoinParamFunc)(CoinParam *param) ;
00107 
00109 
00116 
00119   CoinParam() ;
00120 
00127   CoinParam(std::string name, std::string help,
00128             double lower, double upper, double dflt = 0.0,
00129             bool display = true) ;
00130 
00135   CoinParam(std::string name, std::string help,
00136             int lower, int upper, int dflt = 0,
00137             bool display = true) ;
00138 
00153   CoinParam(std::string name, std::string help,
00154             std::string firstValue, int dflt, bool display = true) ;
00155 
00164   CoinParam(std::string name, std::string help,
00165             std::string dflt, bool display = true) ;
00166 
00169   CoinParam(std::string name, std::string help,
00170             bool display = true) ;
00171 
00174   CoinParam(const CoinParam &orig) ;
00175 
00178   virtual CoinParam *clone() ;
00179 
00182     CoinParam &operator=(const CoinParam &rhs) ;
00183 
00186   virtual ~CoinParam() ;
00187 
00189 
00192 
00195   void appendKwd(std::string kwd) ;
00196 
00201   int kwdIndex(std::string kwd) const ;
00202 
00206   std::string kwdVal() const ;
00207 
00214   void setKwdVal(int value, bool printIt = false) ;
00215 
00222   void setKwdVal(const std::string value ) ;
00223 
00227   void printKwds() const ;
00228 
00229 
00232   void setStrVal(std::string value) ;
00233 
00236   std::string strVal() const ;
00237 
00238 
00241   void setDblVal(double value) ;
00242 
00245   double dblVal() const ;
00246 
00247 
00250   void setIntVal(int value) ;
00251 
00254   int intVal() const ;
00255 
00256 
00259   inline void setShortHelp(const std::string help) { shortHelp_ = help ; } 
00260 
00263   inline std::string shortHelp() const { return (shortHelp_) ; } 
00264 
00270   inline void setLongHelp(const std::string help) { longHelp_ = help ; } 
00271 
00274   inline std::string longHelp() const { return (longHelp_) ; } 
00275 
00284   void printLongHelp() const ;
00285 
00287 
00290 
00293   inline CoinParamType type() const { return (type_) ; } 
00294 
00297   inline void setType(CoinParamType type) { type_ = type ; } 
00298 
00301   inline std::string  name() const { return (name_) ; } 
00302 
00305   inline void setName(std::string name) { name_ = name ; processName() ; } 
00306 
00314   int matches (std::string input) const ;
00315 
00322   std::string matchName() const ;
00323 
00330   inline void setDisplay(bool display) { display_ = display ; } 
00331 
00334   inline bool display() const { return (display_) ; } 
00335 
00338   inline CoinParamFunc pushFunc() { return (pushFunc_) ; } 
00339 
00342   inline void setPushFunc(CoinParamFunc func) { pushFunc_ = func ; }  
00343 
00346   inline CoinParamFunc pullFunc() { return (pullFunc_) ; } 
00347 
00350   inline void setPullFunc(CoinParamFunc func) { pullFunc_ = func ; } 
00351 
00353 
00354 private:
00355 
00358 
00360   void processName() ;
00361 
00363 
00366 
00367   CoinParamType type_ ;
00368 
00370   std::string name_ ;
00371 
00373   size_t lengthName_ ;
00374 
00378   size_t lengthMatch_ ;
00379 
00381   double lowerDblValue_ ;
00382 
00384   double upperDblValue_ ;
00385 
00387   double dblValue_ ;
00388 
00390   int lowerIntValue_ ;
00391 
00393   int upperIntValue_ ;
00394 
00396   int intValue_ ;
00397 
00399   std::string strValue_ ;
00400 
00402   std::vector<std::string> definedKwds_ ;
00403 
00406   int currentKwd_ ;
00407 
00409   CoinParamFunc pushFunc_ ;
00410 
00412   CoinParamFunc pullFunc_ ;
00413 
00415   std::string shortHelp_ ;
00416 
00418   std::string longHelp_ ;
00419 
00421   bool display_ ;
00423 
00424 } ;
00425 
00429 typedef std::vector<CoinParam*> CoinParamVec ;
00430 
00434 std::ostream &operator<< (std::ostream &s, const CoinParam &param) ;
00435 
00436 /*
00437   Bring in the utility functions for parameter handling (CbcParamUtils).
00438 */
00439 
00447 namespace CoinParamUtils {
00453   void setInputSrc(FILE *src) ;
00454 
00458   bool isCommandLine() ;
00459 
00463   bool isInteractive() ;
00464 
00472   std::string getStringField(int argc, const char *argv[], int *valid) ;
00473 
00481   int getIntField(int argc, const char *argv[], int *valid) ;
00482 
00490   double getDoubleField(int argc, const char *argv[], int *valid) ;
00491 
00504   int matchParam(const CoinParamVec &paramVec, std::string name,
00505                  int &matchNdx, int &shortCnt) ;
00506 
00537   std::string getCommand(int argc, const char *argv[],
00538                          const std::string prompt, std::string *pfx = 0) ;
00539 
00577   int lookupParam(std::string name, CoinParamVec &paramVec, 
00578                   int *matchCnt = 0, int *shortCnt = 0, int *queryCnt = 0) ;
00579 
00587   void printIt(const char *msg) ;
00588  void shortOrHelpOne(CoinParamVec &paramVec,int matchNdx, std::string
00605   name, int numQuery) ;
00606 
00615   void shortOrHelpMany(CoinParamVec &paramVec,
00616                        std::string name, int numQuery) ;
00617 
00623   void printGenericHelp() ;
00624 
00637   void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam,
00638                  std::string prefix,
00639                  bool shortHelp, bool longHelp, bool hidden) ;
00640 }
00641 
00642 
00643 #endif  /* CoinParam_H */
00644 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines