license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | // |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 5 | |
6 | // | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 7 | // Deal with the differences between Microsoft and GNU implemenations |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 8 | // of hash_map. Allows all platforms to use |base::hash_map| and |
9 | // |base::hash_set|. | ||||
[email protected] | 52a261f | 2009-03-03 15:01:12 | [diff] [blame] | 10 | // eg: |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 11 | // base::hash_map<int> my_map; |
12 | // base::hash_set<int> my_set; | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 13 | // |
14 | |||||
15 | #ifndef BASE_HASH_TABLES_H__ | ||||
16 | #define BASE_HASH_TABLES_H__ | ||||
17 | |||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 18 | #include "build/build_config.h" |
19 | |||||
20 | #if defined(COMPILER_MSVC) | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 21 | #include <hash_map> |
22 | #include <hash_set> | ||||
23 | namespace base { | ||||
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 24 | using stdext::hash_map; |
25 | using stdext::hash_set; | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 26 | } |
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 27 | #elif defined(COMPILER_GCC) |
[email protected] | aff38a3 | 2009-04-13 16:59:03 | [diff] [blame] | 28 | // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set |
29 | // being deprecated. We can get rid of this when we upgrade to VS2008 and we | ||||
30 | // can use <tr1/unordered_map> and <tr1/unordered_set>. | ||||
31 | #ifdef __DEPRECATED | ||||
32 | #define CHROME_OLD__DEPRECATED __DEPRECATED | ||||
33 | #undef __DEPRECATED | ||||
34 | #endif | ||||
35 | |||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 36 | #include <ext/hash_map> |
37 | #include <ext/hash_set> | ||||
[email protected] | aff38a3 | 2009-04-13 16:59:03 | [diff] [blame] | 38 | |
39 | #ifdef CHROME_OLD__DEPRECATED | ||||
40 | #define __DEPRECATED CHROME_OLD__DEPRECATED | ||||
41 | #undef CHROME_OLD__DEPRECATED | ||||
42 | #endif | ||||
43 | |||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 44 | #include <tr1/functional> |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 45 | namespace base { |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 46 | using __gnu_cxx::hash_map; |
47 | using __gnu_cxx::hash_set; | ||||
48 | } | ||||
49 | |||||
50 | // Implement string hash functions so that strings of various flavors can | ||||
51 | // be used as keys in STL maps and sets. | ||||
52 | namespace __gnu_cxx { | ||||
53 | |||||
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 54 | template<> |
55 | struct hash<wchar_t*> { | ||||
56 | size_t operator()(const wchar_t* s) const { | ||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 57 | return std::tr1::hash<const wchar_t*>()(s); |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 58 | } |
59 | }; | ||||
60 | |||||
61 | template<> | ||||
62 | struct hash<const wchar_t*> { | ||||
63 | size_t operator()(const wchar_t* s) const { | ||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 64 | return std::tr1::hash<const wchar_t*>()(s); |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 65 | } |
66 | }; | ||||
67 | |||||
68 | template<> | ||||
69 | struct hash<std::wstring> { | ||||
70 | size_t operator()(const std::wstring& s) const { | ||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 71 | return std::tr1::hash<std::wstring>()(s); |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 72 | } |
73 | }; | ||||
74 | |||||
75 | template<> | ||||
76 | struct hash<const std::wstring> { | ||||
77 | size_t operator()(const std::wstring& s) const { | ||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 78 | return std::tr1::hash<std::wstring>()(s); |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 79 | } |
80 | }; | ||||
81 | |||||
82 | template<> | ||||
83 | struct hash<std::string> { | ||||
84 | size_t operator()(const std::string& s) const { | ||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 85 | return std::tr1::hash<std::string>()(s); |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 86 | } |
87 | }; | ||||
88 | |||||
89 | template<> | ||||
90 | struct hash<const std::string> { | ||||
91 | size_t operator()(const std::string& s) const { | ||||
[email protected] | e5c3c14 | 2008-08-06 14:36:32 | [diff] [blame] | 92 | return std::tr1::hash<std::string>()(s); |
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 93 | } |
[email protected] | b7f0588 | 2009-02-22 01:21:56 | [diff] [blame] | 94 | }; |
95 | |||||
96 | template<> | ||||
97 | struct hash<long long> { | ||||
98 | size_t operator()(long long i) const { | ||||
99 | return std::tr1::hash<long>()((long) i); | ||||
100 | } | ||||
101 | }; | ||||
[email protected] | 2a4e5fbb | 2008-08-04 18:36:53 | [diff] [blame] | 102 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 103 | } |
104 | |||||
105 | #endif | ||||
106 | |||||
107 | #endif // BASE_HASH_TABLES_H__ |