]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/stringpool.h
79632e00b386fe3aa4419a5ac0509098b209ed6b
[thirdparty/binutils-gdb.git] / gold / stringpool.h
1 // stringpool.h -- a string pool for gold -*- C++ -*-
2
3 #include <string>
4 #include <list>
5
6 // Stringpool
7 // Manage a pool of unique strings.
8
9 #ifndef GOLD_STRINGPOOL_H
10 #define GOLD_STRINGPOOL_H
11
12 namespace gold
13 {
14
15 class Stringpool
16 {
17 public:
18 Stringpool();
19
20 ~Stringpool();
21
22 // Add a string to the pool. This returns a canonical permanent
23 // pointer to the string.
24 const char* add(const char*);
25
26 const char* add(const std::string& s)
27 { return this->add(s.c_str()); }
28
29 // Add the prefix of a string to the pool.
30 const char* add(const char *, size_t);
31
32 private:
33 Stringpool(const Stringpool&);
34 Stringpool& operator=(const Stringpool&);
35
36 struct stringdata
37 {
38 // Length of data in buffer.
39 size_t len;
40 // Allocated size of buffer.
41 size_t alc;
42 // Buffer.
43 char data[1];
44 };
45
46 const char* add_string(const char*);
47
48 struct Stringpool_hash
49 {
50 size_t
51 operator()(const char*) const;
52 };
53
54 struct Stringpool_eq
55 {
56 bool
57 operator()(const char* p1, const char* p2) const
58 { return strcmp(p1, p2) == 0; }
59 };
60
61 #ifdef HAVE_TR1_UNORDERED_SET
62 typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
63 std::allocator<const char*>,
64 true> String_set_type;
65 #else
66 typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
67 std::allocator<const char*> > String_set_type;
68 #endif
69
70 String_set_type string_set_;
71 std::list<stringdata*> strings_;
72 };
73
74 } // End namespace gold.
75
76 #endif // !defined(GOLD_STRINGPOOL_H)