2006-09-29 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / gold / stringpool.h
CommitLineData
14bfc3f5
ILT
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
12namespace gold
13{
14
15class 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
274e99f9 61#ifdef HAVE_TR1_UNORDERED_SET
14bfc3f5
ILT
62 typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
63 std::allocator<const char*>,
64 true> String_set_type;
274e99f9
ILT
65#else
66 typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
67 std::allocator<const char*> > String_set_type;
68#endif
69
14bfc3f5
ILT
70 String_set_type string_set_;
71 std::list<stringdata*> strings_;
72};
73
74} // End namespace gold.
75
76#endif // !defined(GOLD_STRINGPOOL_H)
This page took 0.027494 seconds and 4 git commands to generate.