• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/build/buildd/coinutils-2.6.4/CoinUtils/src/CoinParam.hpp

Go to the documentation of this file.
00001 /* $Id: CoinParam.hpp 1191 2009-07-25 08:38:12Z forrest $ */
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 
00014 #include <vector>
00015 #include <string>
00016 
00072 class CoinParam
00073 {
00074  
00075 public:
00076 
00079 
00092   typedef enum { coinParamInvalid = 0,
00093                  coinParamAct, coinParamInt, coinParamDbl,
00094                  coinParamStr, coinParamKwd } CoinParamType ;
00095 
00103   typedef int (*CoinParamFunc)(CoinParam *param) ;
00104 
00106 
00113 
00116   CoinParam() ;
00117 
00124   CoinParam(std::string name, std::string help,
00125             double lower, double upper, double dflt = 0.0,
00126             bool display = true) ;
00127 
00132   CoinParam(std::string name, std::string help,
00133             int lower, int upper, int dflt = 0,
00134             bool display = true) ;
00135 
00150   CoinParam(std::string name, std::string help,
00151             std::string firstValue, int dflt, bool display = true) ;
00152 
00161   CoinParam(std::string name, std::string help,
00162             std::string dflt, bool display = true) ;
00163 
00166   CoinParam(std::string name, std::string help,
00167             bool display = true) ;
00168 
00171   CoinParam(const CoinParam &orig) ;
00172 
00175   virtual CoinParam *clone() ;
00176 
00179     CoinParam &operator=(const CoinParam &rhs) ;
00180 
00183   virtual ~CoinParam() ;
00184 
00186 
00189 
00192   void appendKwd(std::string kwd) ;
00193 
00198   int kwdIndex(std::string kwd) const ;
00199 
00203   std::string kwdVal() const ;
00204 
00211   void setKwdVal(int value, bool printIt = false) ;
00212 
00219   void setKwdVal(const std::string value ) ;
00220 
00224   void printKwds() const ;
00225 
00226 
00229   void setStrVal(std::string value) ;
00230 
00233   std::string strVal() const ;
00234 
00235 
00238   void setDblVal(double value) ;
00239 
00242   double dblVal() const ;
00243 
00244 
00247   void setIntVal(int value) ;
00248 
00251   int intVal() const ;
00252 
00253 
00256   inline void setShortHelp(const std::string help) { shortHelp_ = help ; } 
00257 
00260   inline std::string shortHelp() const { return (shortHelp_) ; } 
00261 
00267   inline void setLongHelp(const std::string help) { longHelp_ = help ; } 
00268 
00271   inline std::string longHelp() const { return (longHelp_) ; } 
00272 
00281   void printLongHelp() const ;
00282 
00284 
00287 
00290   inline CoinParamType type() const { return (type_) ; } 
00291 
00294   inline void setType(CoinParamType type) { type_ = type ; } 
00295 
00298   inline std::string  name() const { return (name_) ; } 
00299 
00302   inline void setName(std::string name) { name_ = name ; processName() ; } 
00303 
00311   int matches (std::string input) const ;
00312 
00319   std::string matchName() const ;
00320 
00327   inline void setDisplay(bool display) { display_ = display ; } 
00328 
00331   inline bool display() const { return (display_) ; } 
00332 
00335   inline CoinParamFunc pushFunc() { return (pushFunc_) ; } 
00336 
00339   inline void setPushFunc(CoinParamFunc func) { pushFunc_ = func ; }  
00340 
00343   inline CoinParamFunc pullFunc() { return (pullFunc_) ; } 
00344 
00347   inline void setPullFunc(CoinParamFunc func) { pullFunc_ = func ; } 
00348 
00350 
00351 private:
00352 
00355 
00357   void processName() ;
00358 
00360 
00363 
00364   CoinParamType type_ ;
00365 
00367   std::string name_ ;
00368 
00370   unsigned int lengthName_ ;
00371 
00375   unsigned int lengthMatch_ ;
00376 
00378   double lowerDblValue_ ;
00379 
00381   double upperDblValue_ ;
00382 
00384   double dblValue_ ;
00385 
00387   int lowerIntValue_ ;
00388 
00390   int upperIntValue_ ;
00391 
00393   int intValue_ ;
00394 
00396   std::string strValue_ ;
00397 
00399   std::vector<std::string> definedKwds_ ;
00400 
00403   int currentKwd_ ;
00404 
00406   CoinParamFunc pushFunc_ ;
00407 
00409   CoinParamFunc pullFunc_ ;
00410 
00412   std::string shortHelp_ ;
00413 
00415   std::string longHelp_ ;
00416 
00418   bool display_ ;
00420 
00421 } ;
00422 
00426 typedef std::vector<CoinParam*> CoinParamVec ;
00427 
00431 std::ostream &operator<< (std::ostream &s, const CoinParam &param) ;
00432 
00433 /*
00434   Bring in the utility functions for parameter handling (CbcParamUtils).
00435 */
00436 
00444 namespace CoinParamUtils {
00450   void setInputSrc(FILE *src) ;
00451 
00455   bool isCommandLine() ;
00456 
00460   bool isInteractive() ;
00461 
00469   std::string getStringField(int argc, const char *argv[], int *valid) ;
00470 
00478   int getIntField(int argc, const char *argv[], int *valid) ;
00479 
00487   double getDoubleField(int argc, const char *argv[], int *valid) ;
00488 
00501   int matchParam(const CoinParamVec &paramVec, std::string name,
00502                  int &matchNdx, int &shortCnt) ;
00503 
00534   std::string getCommand(int argc, const char *argv[],
00535                          const std::string prompt, std::string *pfx = 0) ;
00536 
00574   int lookupParam(std::string name, CoinParamVec &paramVec, 
00575                   int *matchCnt = 0, int *shortCnt = 0, int *queryCnt = 0) ;
00576 
00584   void printIt(const char *msg) ;
00585  void shortOrHelpOne(CoinParamVec &paramVec,int matchNdx, std::string
00602   name, int numQuery) ;
00603 
00612   void shortOrHelpMany(CoinParamVec &paramVec,
00613                        std::string name, int numQuery) ;
00614 
00620   void printGenericHelp() ;
00621 
00634   void printHelp(CoinParamVec &paramVec, int firstParam, int lastParam,
00635                  std::string prefix,
00636                  bool shortHelp, bool longHelp, bool hidden) ;
00637 }
00638 
00639 
00640 #endif  /* CoinParam_H */
00641 

Generated on Fri Oct 15 2010 18:21:02 by  doxygen 1.7.1