File indexing completed on 2023-03-17 10:50:56
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
0019
0020
0021 int32_t operator[](const std::string &string) const;
0022
0023
0024
0025
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
0039 bool operator()(const value_type &val, const std::string &string) const { return val.first < string; }
0040
0041 private:
0042
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