CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StringMap.h
Go to the documentation of this file.
1 #ifndef DataFormats_PatCandidates_StringMap_h
2 #define DataFormats_PatCandidates_StringMap_h
3 
4 #include <string>
5 #include <vector>
6 #include <algorithm> // for std::pair
7 
8 class StringMap {
9 public:
10  typedef std::pair<std::string, int32_t> value_type;
11  typedef std::vector<value_type> vector_type;
12  typedef vector_type::const_iterator const_iterator;
13 
14  void add(const std::string &string, int32_t value);
15  void sort();
16  void clear();
17 
21  int32_t operator[](const std::string &string) const;
22 
26  const std::string &operator[](int32_t number) const;
27 
28  const_iterator find(const std::string &string) const;
29  const_iterator find(int32_t number) const;
30 
31  const_iterator begin() const { return entries_.begin(); }
32  const_iterator end() const { return entries_.end(); }
33 
34  size_t size() const { return entries_.size(); }
35  class MatchByString {
36  public:
38  //MatchByString(const std::string &string) : string_(string) {}
39  bool operator()(const value_type &val, const std::string &string) const { return val.first < string; }
40  //bool operator()(const value_type &val) const { return string_ == val.first; }
41  private:
42  //const std::string &string_;
43  };
44  class MatchByNumber {
45  public:
46  MatchByNumber(int32_t number) : number_(number) {}
47  bool operator()(const value_type &val) const { return number_ == val.second; }
48 
49  private:
50  int32_t number_;
51  };
52 
53 private:
54  std::vector<std::pair<std::string, int32_t> > entries_;
55 };
56 
57 #endif
void add(const std::string &string, int32_t value)
Definition: StringMap.cc:3
std::vector< value_type > vector_type
Definition: StringMap.h:11
const_iterator end() const
Definition: StringMap.h:32
const_iterator begin() const
Definition: StringMap.h:31
int32_t operator[](const std::string &string) const
Definition: StringMap.cc:9
std::vector< std::pair< std::string, int32_t > > entries_
Definition: StringMap.h:54
void clear()
Definition: StringMap.cc:7
bool operator()(const value_type &val) const
Definition: StringMap.h:47
vector_type::const_iterator const_iterator
Definition: StringMap.h:12
MatchByNumber(int32_t number)
Definition: StringMap.h:46
const_iterator find(const std::string &string) const
Definition: StringMap.cc:20
std::pair< std::string, int32_t > value_type
Definition: StringMap.h:10
void sort()
Definition: StringMap.cc:5
size_t size() const
Definition: StringMap.h:34
bool operator()(const value_type &val, const std::string &string) const
Definition: StringMap.h:39