blob: 5e50cfc29a7dc2dd580cb8910a96ec420df2f6a5 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commitd7cae122008-07-26 21:49:384//
[email protected]2a4e5fbb2008-08-04 18:36:535
6//
initial.commitd7cae122008-07-26 21:49:387// Deal with the differences between Microsoft and GNU implemenations
[email protected]2a4e5fbb2008-08-04 18:36:538// of hash_map. Allows all platforms to use |base::hash_map| and
9// |base::hash_set|.
[email protected]52a261f2009-03-03 15:01:1210// eg:
[email protected]2a4e5fbb2008-08-04 18:36:5311// base::hash_map<int> my_map;
12// base::hash_set<int> my_set;
initial.commitd7cae122008-07-26 21:49:3813//
14
15#ifndef BASE_HASH_TABLES_H__
16#define BASE_HASH_TABLES_H__
17
[email protected]e5c3c142008-08-06 14:36:3218#include "build/build_config.h"
19
20#if defined(COMPILER_MSVC)
initial.commitd7cae122008-07-26 21:49:3821#include <hash_map>
22#include <hash_set>
23namespace base {
[email protected]2a4e5fbb2008-08-04 18:36:5324using stdext::hash_map;
25using stdext::hash_set;
initial.commitd7cae122008-07-26 21:49:3826}
[email protected]e5c3c142008-08-06 14:36:3227#elif defined(COMPILER_GCC)
[email protected]aff38a32009-04-13 16:59:0328// 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.commitd7cae122008-07-26 21:49:3836#include <ext/hash_map>
37#include <ext/hash_set>
[email protected]aff38a32009-04-13 16:59:0338
39#ifdef CHROME_OLD__DEPRECATED
40#define __DEPRECATED CHROME_OLD__DEPRECATED
41#undef CHROME_OLD__DEPRECATED
42#endif
43
[email protected]e5c3c142008-08-06 14:36:3244#include <tr1/functional>
initial.commitd7cae122008-07-26 21:49:3845namespace base {
[email protected]2a4e5fbb2008-08-04 18:36:5346using __gnu_cxx::hash_map;
47using __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.
52namespace __gnu_cxx {
53
[email protected]2a4e5fbb2008-08-04 18:36:5354template<>
55struct hash<wchar_t*> {
56 size_t operator()(const wchar_t* s) const {
[email protected]e5c3c142008-08-06 14:36:3257 return std::tr1::hash<const wchar_t*>()(s);
[email protected]2a4e5fbb2008-08-04 18:36:5358 }
59};
60
61template<>
62struct hash<const wchar_t*> {
63 size_t operator()(const wchar_t* s) const {
[email protected]e5c3c142008-08-06 14:36:3264 return std::tr1::hash<const wchar_t*>()(s);
[email protected]2a4e5fbb2008-08-04 18:36:5365 }
66};
67
68template<>
69struct hash<std::wstring> {
70 size_t operator()(const std::wstring& s) const {
[email protected]e5c3c142008-08-06 14:36:3271 return std::tr1::hash<std::wstring>()(s);
[email protected]2a4e5fbb2008-08-04 18:36:5372 }
73};
74
75template<>
76struct hash<const std::wstring> {
77 size_t operator()(const std::wstring& s) const {
[email protected]e5c3c142008-08-06 14:36:3278 return std::tr1::hash<std::wstring>()(s);
[email protected]2a4e5fbb2008-08-04 18:36:5379 }
80};
81
82template<>
83struct hash<std::string> {
84 size_t operator()(const std::string& s) const {
[email protected]e5c3c142008-08-06 14:36:3285 return std::tr1::hash<std::string>()(s);
[email protected]2a4e5fbb2008-08-04 18:36:5386 }
87};
88
89template<>
90struct hash<const std::string> {
91 size_t operator()(const std::string& s) const {
[email protected]e5c3c142008-08-06 14:36:3292 return std::tr1::hash<std::string>()(s);
[email protected]2a4e5fbb2008-08-04 18:36:5393 }
[email protected]b7f05882009-02-22 01:21:5694};
95
96template<>
97struct hash<long long> {
98 size_t operator()(long long i) const {
99 return std::tr1::hash<long>()((long) i);
100 }
101};
[email protected]2a4e5fbb2008-08-04 18:36:53102
initial.commitd7cae122008-07-26 21:49:38103}
104
105#endif
106
107#endif // BASE_HASH_TABLES_H__