1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#ifndef DataFormats_PatCandidates_StringMap_h
#define DataFormats_PatCandidates_StringMap_h
#include <string>
#include <vector>
#include <algorithm> // for std::pair
class StringMap {
public:
typedef std::pair<std::string, int32_t> value_type;
typedef std::vector<value_type> vector_type;
typedef vector_type::const_iterator const_iterator;
void add(const std::string &string, int32_t value);
void sort();
void clear();
/// return associated number, or -1 if no one is found
/// in case the association is not unque, the choice of the returned value is undetermined
/// note: works only after it's sorted
int32_t operator[](const std::string &string) const;
/// return associated string, or "" if none is there
/// in case the association is not unque, the choice of the returned value is undetermined
/// note: works only after it's sorted
const std::string &operator[](int32_t number) const;
const_iterator find(const std::string &string) const;
const_iterator find(int32_t number) const;
const_iterator begin() const { return entries_.begin(); }
const_iterator end() const { return entries_.end(); }
size_t size() const { return entries_.size(); }
class MatchByString {
public:
MatchByString() {}
//MatchByString(const std::string &string) : string_(string) {}
bool operator()(const value_type &val, const std::string &string) const { return val.first < string; }
//bool operator()(const value_type &val) const { return string_ == val.first; }
private:
//const std::string &string_;
};
class MatchByNumber {
public:
MatchByNumber(int32_t number) : number_(number) {}
bool operator()(const value_type &val) const { return number_ == val.second; }
private:
int32_t number_;
};
private:
std::vector<std::pair<std::string, int32_t> > entries_;
};
#endif
|