Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:23

0001 // -*- C++ -*-
0002 
0003 #if !defined(VariableMapCont_H)
0004 #define VariableMapCont_H
0005 
0006 #include <map>
0007 #include <vector>
0008 #include <string>
0009 
0010 namespace optutl {
0011 
0012   class VariableMapCont {
0013   public:
0014     //////////////////////
0015     // Public Constants //
0016     //////////////////////
0017 
0018     // typedefs
0019     typedef std::vector<int> IVec;
0020     typedef std::vector<double> DVec;
0021     typedef std::vector<std::string> SVec;
0022     typedef std::map<std::string, int> SIMap;
0023     typedef std::map<std::string, double> SDMap;
0024     typedef std::map<std::string, bool> SBMap;
0025     typedef std::map<std::string, std::string> SSMap;
0026     typedef std::map<std::string, IVec> SIVecMap;
0027     typedef std::map<std::string, DVec> SDVecMap;
0028     typedef std::map<std::string, SVec> SSVecMap;
0029     // Iterators
0030     typedef IVec::iterator IVecIter;
0031     typedef DVec::iterator DVecIter;
0032     typedef SVec::iterator SVecIter;
0033     typedef SIMap::iterator SIMapIter;
0034     typedef SDMap::iterator SDMapIter;
0035     typedef SBMap::iterator SBMapIter;
0036     typedef SSMap::iterator SSMapIter;
0037     typedef SIVecMap::iterator SIVecMapIter;
0038     typedef SDVecMap::iterator SDVecMapIter;
0039     typedef SSVecMap::iterator SSVecMapIter;
0040     // constant iterators
0041     typedef IVec::const_iterator IVecConstIter;
0042     typedef DVec::const_iterator DVecConstIter;
0043     typedef SVec::const_iterator SVecConstIter;
0044     typedef SIMap::const_iterator SIMapConstIter;
0045     typedef SDMap::const_iterator SDMapConstIter;
0046     typedef SBMap::const_iterator SBMapConstIter;
0047     typedef SSMap::const_iterator SSMapConstIter;
0048     typedef SIVecMap::const_iterator SIVecMapConstIter;
0049     typedef SDVecMap::const_iterator SDVecMapConstIter;
0050     typedef SSVecMap::const_iterator SSVecMapConstIter;
0051 
0052     // constants
0053     static const int kDefaultInteger;
0054     static const double kDefaultDouble;
0055     static const std::string kDefaultString;
0056     static const bool kDefaultBool;
0057     static const IVec kEmptyIVec;
0058     static const DVec kEmptyDVec;
0059     static const SVec kEmptySVec;
0060 
0061     enum OptionType {
0062       kNone = 0,
0063       kInteger,
0064       kDouble,
0065       kString,
0066       kBool,
0067       kIntegerVector,
0068       kDoubleVector,
0069       kStringVector,
0070       kNumOptionTypes
0071     };
0072 
0073     /////////////
0074     // friends //
0075     /////////////
0076     // tells particle data how to print itself out
0077     friend std::ostream &operator<<(std::ostream &o_stream, const VariableMapCont &rhs);
0078 
0079     //////////////////////////
0080     //            _         //
0081     // |\/|      |_         //
0082     // |  |EMBER | UNCTIONS //
0083     //                      //
0084     //////////////////////////
0085 
0086     /////////////////////////////////
0087     // Constructors and Destructor //
0088     /////////////////////////////////
0089     VariableMapCont();
0090 
0091     //////////////////////////////
0092     // Regular Member Functions //
0093     //////////////////////////////
0094 
0095     // prints out '--help' screen, then exits.
0096     void help();
0097 
0098     // returns OptionType (or kNone (0)) of a given option.
0099     OptionType hasVariable(std::string key);
0100     OptionType hasOption(std::string key) { return hasVariable(key); }
0101 
0102     // Add variable to option maps.  'key' is passed in by copy
0103     // because it is modified in place.
0104     void addOption(std::string key, OptionType type, const std::string &description = "");
0105     void addOption(std::string key, OptionType type, const std::string &description, int defaultValue);
0106     void addOption(std::string key, OptionType type, const std::string &description, double defaultValue);
0107     void addOption(std::string key, OptionType type, const std::string &description, const std::string &defaultValue);
0108     void addOption(std::string key, OptionType type, const std::string &description, const char *defaultValue);
0109     void addOption(std::string key, OptionType type, const std::string &description, bool defaultValue);
0110     //   addVariable works just like addOption, but has no description.
0111     void addVariable(std::string key, OptionType type) { addOption(key, type, ""); }
0112     void addVariable(std::string key, OptionType type, int defaultValue) { addOption(key, type, "", defaultValue); }
0113     void addVariable(std::string key, OptionType type, double defaultValue) { addOption(key, type, "", defaultValue); }
0114     void addVariable(std::string key, OptionType type, const std::string &defaultValue) {
0115       addOption(key, type, "", defaultValue);
0116     }
0117     void addVariable(std::string key, OptionType type, const char *defaultValue) {
0118       addOption(key, type, "", defaultValue);
0119     }
0120     void addVariable(std::string key, OptionType type, bool defaultValue) { addOption(key, type, "", defaultValue); }
0121 
0122     // some of the guts of above
0123     void _checkKey(std::string &key, const std::string &description = "");
0124 
0125     int &integerValue(std::string key);
0126     double &doubleValue(std::string key);
0127     std::string &stringValue(std::string key);
0128     bool &boolValue(std::string key);
0129     IVec &integerVector(std::string key);
0130     DVec &doubleVector(std::string key);
0131     SVec &stringVector(std::string key);
0132 
0133     /////////////////////////////
0134     // Static Member Functions //
0135     /////////////////////////////
0136 
0137     // converts a string to lower case characters
0138     static void lowercaseString(std::string &arg);
0139 
0140     // converts a single character to lower case
0141     static char toLower(char &ch);
0142 
0143   protected:
0144     // returns true if a variable has been modified from the command
0145     // line.
0146     bool _valueHasBeenModified(const std::string &key);
0147 
0148     /////////////////////////
0149     // Private Member Data //
0150     /////////////////////////
0151 
0152     SIMap m_integerMap;
0153     SDMap m_doubleMap;
0154     SSMap m_stringMap;
0155     SBMap m_boolMap;
0156     SIVecMap m_integerVecMap;
0157     SDVecMap m_doubleVecMap;
0158     SSVecMap m_stringVecMap;
0159     SBMap m_variableModifiedMap;
0160     SSMap m_variableDescriptionMap;
0161   };
0162 
0163 }  // namespace optutl
0164 #endif  // VariableMapCont_H