Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:55

0001 #ifndef DD_READMAPTYPE_H
0002 #define DD_READMAPTYPE_H
0003 
0004 #include <string>
0005 #include <map>
0006 
0007 namespace dddDetails {
0008   void errorReadMapType(const std::string& key);
0009 }
0010 
0011 //! a std::map<std::string,YourType> that offers a const operator[key]; if key is not stored in the std::map, a cms::Exception is thrown
0012 /** otherwise, the ReadMapType works the same as std::map<std::string,YourType> */
0013 template <class V>
0014 class ReadMapType : public std::map<std::string, V> {
0015 public:
0016   ReadMapType() : std::map<std::string, V>() {}
0017 
0018   const V& operator[](const std::string& key) const {
0019     typename std::map<std::string, V>::const_iterator it = this->find(key);
0020     if (it == this->end())
0021       dddDetails::errorReadMapType(key);
0022     return it->second;
0023   }
0024 
0025   V& operator[](const std::string& key) { return std::map<std::string, V>::operator[](key); }
0026 };
0027 
0028 #endif  // DD_READMAPTYE_H