Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_PatCandidates_StringMap_h
0002 #define DataFormats_PatCandidates_StringMap_h
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <algorithm>  // for std::pair
0007 
0008 class StringMap {
0009 public:
0010   typedef std::pair<std::string, int32_t> value_type;
0011   typedef std::vector<value_type> vector_type;
0012   typedef vector_type::const_iterator const_iterator;
0013 
0014   void add(const std::string &string, int32_t value);
0015   void sort();
0016   void clear();
0017 
0018   /// return associated number, or -1 if no one is found
0019   /// in case the association is not unque, the choice of the returned value is undetermined
0020   /// note: works only after it's sorted
0021   int32_t operator[](const std::string &string) const;
0022 
0023   /// return associated string, or "" if none is there
0024   /// in case the association is not unque, the choice of the returned value is undetermined
0025   /// note: works only after it's sorted
0026   const std::string &operator[](int32_t number) const;
0027 
0028   const_iterator find(const std::string &string) const;
0029   const_iterator find(int32_t number) const;
0030 
0031   const_iterator begin() const { return entries_.begin(); }
0032   const_iterator end() const { return entries_.end(); }
0033 
0034   size_t size() const { return entries_.size(); }
0035   class MatchByString {
0036   public:
0037     MatchByString() {}
0038     //MatchByString(const std::string &string) : string_(string) {}
0039     bool operator()(const value_type &val, const std::string &string) const { return val.first < string; }
0040     //bool operator()(const value_type &val) const { return string_ == val.first; }
0041   private:
0042     //const std::string &string_;
0043   };
0044   class MatchByNumber {
0045   public:
0046     MatchByNumber(int32_t number) : number_(number) {}
0047     bool operator()(const value_type &val) const { return number_ == val.second; }
0048 
0049   private:
0050     int32_t number_;
0051   };
0052 
0053 private:
0054   std::vector<std::pair<std::string, int32_t> > entries_;
0055 };
0056 
0057 #endif