license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [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 | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | // |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 5 | |
| 6 | // |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 7 | // Deal with the differences between Microsoft and GNU implemenations |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 8 | // of hash_map. Allows all platforms to use |base::hash_map| and |
| 9 | // |base::hash_set|. |
| 10 | // eg: |
| 11 | // base::hash_map<int> my_map; |
| 12 | // base::hash_set<int> my_set; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 13 | // |
| 14 | |
| 15 | #ifndef BASE_HASH_TABLES_H__ |
| 16 | #define BASE_HASH_TABLES_H__ |
| 17 | |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 18 | #include "build/build_config.h" |
| 19 | |
| 20 | #if defined(COMPILER_MSVC) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 21 | #include <hash_map> |
| 22 | #include <hash_set> |
| 23 | namespace base { |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 24 | using stdext::hash_map; |
| 25 | using stdext::hash_set; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 26 | } |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 27 | #elif defined(COMPILER_GCC) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 28 | #include <ext/hash_map> |
| 29 | #include <ext/hash_set> |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 30 | #include <tr1/functional> |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 31 | namespace base { |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 32 | using __gnu_cxx::hash_map; |
| 33 | using __gnu_cxx::hash_set; |
| 34 | } |
| 35 | |
| 36 | // Implement string hash functions so that strings of various flavors can |
| 37 | // be used as keys in STL maps and sets. |
| 38 | namespace __gnu_cxx { |
| 39 | |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 40 | template<> |
| 41 | struct hash<wchar_t*> { |
| 42 | size_t operator()(const wchar_t* s) const { |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 43 | return std::tr1::hash<const wchar_t*>()(s); |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 44 | } |
| 45 | }; |
| 46 | |
| 47 | template<> |
| 48 | struct hash<const wchar_t*> { |
| 49 | size_t operator()(const wchar_t* s) const { |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 50 | return std::tr1::hash<const wchar_t*>()(s); |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 51 | } |
| 52 | }; |
| 53 | |
| 54 | template<> |
| 55 | struct hash<std::wstring> { |
| 56 | size_t operator()(const std::wstring& s) const { |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 57 | return std::tr1::hash<std::wstring>()(s); |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 58 | } |
| 59 | }; |
| 60 | |
| 61 | template<> |
| 62 | struct hash<const std::wstring> { |
| 63 | size_t operator()(const std::wstring& s) const { |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 64 | return std::tr1::hash<std::wstring>()(s); |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 65 | } |
| 66 | }; |
| 67 | |
| 68 | template<> |
| 69 | struct hash<std::string> { |
| 70 | size_t operator()(const std::string& s) const { |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 71 | return std::tr1::hash<std::string>()(s); |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 72 | } |
| 73 | }; |
| 74 | |
| 75 | template<> |
| 76 | struct hash<const std::string> { |
| 77 | size_t operator()(const std::string& s) const { |
pinkerton@google.com | e3eb63f | 2008-08-06 23:36:32 +0900 | [diff] [blame] | 78 | return std::tr1::hash<std::string>()(s); |
pinkerton@google.com | 3f807de | 2008-08-05 03:36:53 +0900 | [diff] [blame] | 79 | } |
| 80 | }; |
| 81 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | #endif |
| 85 | |
| 86 | #endif // BASE_HASH_TABLES_H__ |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 87 | |