-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilenameInternTable.hxx
49 lines (35 loc) · 944 Bytes
/
FilenameInternTable.hxx
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
#ifndef __FilenameInternTable_hxx__
#define __FilenameInternTable_hxx__
#include <sys/types.h>
#include <vector>
#include <string>
#include <unordered_map>
class FilenameInternTable
{
public:
typedef std::vector<std::string>::size_type id_type;
const id_type id(const std::string& fname)
{
if (id_lookup_.count(fname) == 0) /* new filename */ {
table_.push_back(fname);
id_lookup_[fname] = table_.size() - 1;
}
return id_lookup_.at(fname);
}
const id_type id(const std::string& fname) const
{
return id_lookup_.at(fname);
}
const std::string& name(const id_type& id) const
{
return table_[id];
}
const std::vector<std::string>::size_type size() const
{
return table_.size();
}
private:
std::unordered_map<std::string, id_type> id_lookup_;
std::vector<std::string> table_;
};
#endif // include guard