source: webkit/trunk/JavaScriptCore/wtf/HashTraits.h@ 35900

Last change on this file since 35900 was 35900, checked in by [email protected], 17 years ago

2008-08-23 Cameron Zwarich <[email protected]>

Rubber-stamped by Mark Rowe.

Remove modelines.

JavaScriptCore:

  • API/APICast.h:
  • API/JSBase.cpp:
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSClassRef.cpp:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSProfilerPrivate.cpp:
  • API/JSStringRef.cpp:
  • API/JSStringRefBSTR.cpp:
  • API/JSStringRefCF.cpp:
  • API/JSValueRef.cpp:
  • API/tests/JSNode.c:
  • API/tests/JSNode.h:
  • API/tests/JSNodeList.c:
  • API/tests/JSNodeList.h:
  • API/tests/Node.c:
  • API/tests/Node.h:
  • API/tests/NodeList.c:
  • API/tests/NodeList.h:
  • API/tests/minidom.c:
  • API/tests/minidom.js:
  • API/tests/testapi.c:
  • API/tests/testapi.js:
  • JavaScriptCore.pro:
  • kjs/FunctionConstructor.h:
  • kjs/FunctionPrototype.h:
  • kjs/JSArray.h:
  • kjs/JSString.h:
  • kjs/JSWrapperObject.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.h:
  • kjs/lexer.h:
  • kjs/lookup.h:
  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/HashCountedSet.h:
  • wtf/HashFunctions.h:
  • wtf/HashIterators.h:
  • wtf/HashMap.h:
  • wtf/HashSet.h:
  • wtf/HashTable.h:
  • wtf/HashTraits.h:
  • wtf/ListHashSet.h:
  • wtf/ListRefPtr.h:
  • wtf/Noncopyable.h:
  • wtf/OwnArrayPtr.h:
  • wtf/OwnPtr.h:
  • wtf/PassRefPtr.h:
  • wtf/Platform.h:
  • wtf/RefPtr.h:
  • wtf/RefPtrHashMap.h:
  • wtf/RetainPtr.h:
  • wtf/UnusedParam.h:
  • wtf/Vector.h:
  • wtf/VectorTraits.h:
  • wtf/unicode/Unicode.h:
  • wtf/unicode/icu/UnicodeIcu.h:

WebCore:

  • WebCore.pro:
  • bridge/testbindings.cpp:
  • dom/DocPtr.h:
  • loader/SubstituteData.h:
  • page/Chrome.cpp:
  • page/Chrome.h:
  • page/ChromeClient.h:
  • page/Frame.h:
  • page/FrameLoadRequest.h:
  • page/FrameTree.cpp:
  • page/FrameTree.h:
  • page/Page.h:
  • page/mac/ChromeMac.mm:
  • platform/network/HTTPHeaderMap.h:
  • platform/network/ResourceErrorBase.cpp:
  • platform/network/ResourceErrorBase.h:
  • platform/network/ResourceHandleInternal.h:
  • platform/network/ResourceRequestBase.cpp:
  • platform/network/ResourceRequestBase.h:
  • platform/network/ResourceResponseBase.cpp:
  • platform/network/ResourceResponseBase.h:
  • platform/network/cf/ResourceError.h:
  • platform/network/cf/ResourceRequest.h:
  • platform/network/cf/ResourceRequestCFNet.h:
  • platform/network/cf/ResourceResponse.h:
  • platform/network/cf/ResourceResponseCFNet.h:
  • platform/network/curl/ResourceError.h:
  • platform/network/curl/ResourceRequest.h:
  • platform/network/curl/ResourceResponse.h:
  • platform/network/mac/ResourceError.h:
  • platform/network/mac/ResourceErrorMac.mm:
  • platform/network/mac/ResourceRequest.h:
  • platform/network/mac/ResourceRequestMac.mm:
  • platform/network/mac/ResourceResponse.h:
  • platform/network/mac/ResourceResponseMac.mm:
  • platform/network/qt/ResourceError.h:
  • platform/network/qt/ResourceRequest.h:
  • platform/network/qt/ResourceResponse.h:
  • platform/network/soup/CookieJarSoup.cpp:
  • platform/network/soup/ResourceError.h:
  • platform/network/soup/ResourceRequest.h:
  • platform/network/soup/ResourceResponse.h:
  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
1/*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef WTF_HashTraits_h
22#define WTF_HashTraits_h
23
24#include "Assertions.h"
25#include "HashFunctions.h"
26#include <utility>
27#include <limits>
28
29namespace WTF {
30
31 using std::pair;
32 using std::make_pair;
33
34 template<typename T> struct IsInteger { static const bool value = false; };
35 template<> struct IsInteger<bool> { static const bool value = true; };
36 template<> struct IsInteger<char> { static const bool value = true; };
37 template<> struct IsInteger<signed char> { static const bool value = true; };
38 template<> struct IsInteger<unsigned char> { static const bool value = true; };
39 template<> struct IsInteger<short> { static const bool value = true; };
40 template<> struct IsInteger<unsigned short> { static const bool value = true; };
41 template<> struct IsInteger<int> { static const bool value = true; };
42 template<> struct IsInteger<unsigned int> { static const bool value = true; };
43 template<> struct IsInteger<long> { static const bool value = true; };
44 template<> struct IsInteger<unsigned long> { static const bool value = true; };
45 template<> struct IsInteger<long long> { static const bool value = true; };
46 template<> struct IsInteger<unsigned long long> { static const bool value = true; };
47
48#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
49 template<> struct IsInteger<wchar_t> { static const bool value = true; };
50#endif
51
52 COMPILE_ASSERT(IsInteger<bool>::value, WTF_IsInteger_bool_true);
53 COMPILE_ASSERT(IsInteger<char>::value, WTF_IsInteger_char_true);
54 COMPILE_ASSERT(IsInteger<signed char>::value, WTF_IsInteger_signed_char_true);
55 COMPILE_ASSERT(IsInteger<unsigned char>::value, WTF_IsInteger_unsigned_char_true);
56 COMPILE_ASSERT(IsInteger<short>::value, WTF_IsInteger_short_true);
57 COMPILE_ASSERT(IsInteger<unsigned short>::value, WTF_IsInteger_unsigned_short_true);
58 COMPILE_ASSERT(IsInteger<int>::value, WTF_IsInteger_int_true);
59 COMPILE_ASSERT(IsInteger<unsigned int>::value, WTF_IsInteger_unsigned_int_true);
60 COMPILE_ASSERT(IsInteger<long>::value, WTF_IsInteger_long_true);
61 COMPILE_ASSERT(IsInteger<unsigned long>::value, WTF_IsInteger_unsigned_long_true);
62 COMPILE_ASSERT(IsInteger<long long>::value, WTF_IsInteger_long_long_true);
63 COMPILE_ASSERT(IsInteger<unsigned long long>::value, WTF_IsInteger_unsigned_long_long_true);
64
65#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
66 COMPILE_ASSERT(IsInteger<wchar_t>::value, WTF_IsInteger_wchar_t_true);
67#endif
68
69 COMPILE_ASSERT(!IsInteger<char*>::value, WTF_IsInteger_char_pointer_false);
70 COMPILE_ASSERT(!IsInteger<const char* >::value, WTF_IsInteger_const_char_pointer_false);
71 COMPILE_ASSERT(!IsInteger<volatile char* >::value, WTF_IsInteger_volatile_char_pointer__false);
72 COMPILE_ASSERT(!IsInteger<double>::value, WTF_IsInteger_double_false);
73 COMPILE_ASSERT(!IsInteger<float>::value, WTF_IsInteger_float_false);
74
75 template<typename T> struct HashTraits;
76
77 template<bool isInteger, typename T> struct GenericHashTraitsBase;
78
79 template<typename T> struct GenericHashTraitsBase<false, T> {
80 static const bool emptyValueIsZero = false;
81 static const bool needsDestruction = true;
82 };
83
84 // default integer traits disallow both 0 and -1 as keys (max value instead of -1 for unsigned)
85 template<typename T> struct GenericHashTraitsBase<true, T> {
86 static const bool emptyValueIsZero = true;
87 static const bool needsDestruction = false;
88 static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1); }
89 static bool isDeletedValue(T value) { return value == static_cast<T>(-1); }
90 };
91
92 template<typename T> struct GenericHashTraits : GenericHashTraitsBase<IsInteger<T>::value, T> {
93 typedef T TraitType;
94 static T emptyValue() { return T(); }
95 };
96
97 template<typename T> struct HashTraits : GenericHashTraits<T> { };
98
99 template<typename T> struct FloatHashTraits : GenericHashTraits<T> {
100 static const bool needsDestruction = false;
101 static T emptyValue() { return std::numeric_limits<T>::infinity(); }
102 static void constructDeletedValue(T& slot) { slot = -std::numeric_limits<T>::infinity(); }
103 static bool isDeletedValue(T value) { return value == -std::numeric_limits<T>::infinity(); }
104 };
105
106 template<> struct HashTraits<float> : FloatHashTraits<float> { };
107 template<> struct HashTraits<double> : FloatHashTraits<double> { };
108
109 template<typename P> struct HashTraits<P*> : GenericHashTraits<P*> {
110 static const bool emptyValueIsZero = true;
111 static const bool needsDestruction = false;
112 static void constructDeletedValue(P*& slot) { slot = reinterpret_cast<P*>(-1); }
113 static bool isDeletedValue(P* value) { return value == reinterpret_cast<P*>(-1); }
114 };
115
116 template<typename P> struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > {
117 static const bool emptyValueIsZero = true;
118 static void constructDeletedValue(RefPtr<P>& slot) { new (&slot) RefPtr<P>(HashTableDeletedValue); }
119 static bool isDeletedValue(const RefPtr<P>& value) { return value.isHashTableDeletedValue(); }
120 };
121
122 // special traits for pairs, helpful for their use in HashMap implementation
123
124 template<typename FirstTraitsArg, typename SecondTraitsArg>
125 struct PairHashTraits : GenericHashTraits<pair<typename FirstTraitsArg::TraitType, typename SecondTraitsArg::TraitType> > {
126 typedef FirstTraitsArg FirstTraits;
127 typedef SecondTraitsArg SecondTraits;
128 typedef pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType> TraitType;
129
130 static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero;
131 static TraitType emptyValue() { return make_pair(FirstTraits::emptyValue(), SecondTraits::emptyValue()); }
132
133 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
134
135 static void constructDeletedValue(TraitType& slot) { FirstTraits::constructDeletedValue(slot.first); }
136 static bool isDeletedValue(const TraitType& value) { return FirstTraits::isDeletedValue(value.first); }
137 };
138
139 template<typename First, typename Second>
140 struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { };
141
142} // namespace WTF
143
144using WTF::HashTraits;
145using WTF::PairHashTraits;
146
147#endif // WTF_HashTraits_h
Note: See TracBrowser for help on using the repository browser.