230 struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> {
<= 継承
231 static const bool emptyValueIsZero = true;
232 static const bool needsDestruction = true;
233 static const FontPlatformData& emptyValue()
234 {
235 DEFINE_STATIC_LOCAL(FontPlatformData, key, (0.f, false, false));
236 return key;
237 }
238 static void constructDeletedValue(FontPlatformData& slot)
239 {
240 new (&slot) FontPlatformData(HashTableDeletedValue);
241 }
242 static bool isDeletedValue(const FontPlatformData& value)
243 {
244 return value.isHashTableDeletedValue();
245 }
246 };
247
248 typedef HashMap<FontPlatformData, pair<SimpleFontData*, unsigned>,
FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
249
250 static FontDataCache* gFontDataCache = 0;
215
216 struct FontDataCacheKeyHash {
217 static unsigned hash(const FontPlatformData& platformData)
218 {
219 return platformData.hash();
220 }
221
222 static bool equal(const FontPlatformData& a, const FontPlatformData& b)
223 {
224 return a == b;
225 }
226
227 static const bool safeToCompareToEmptyOrDeleted = true;
228 };
29 namespace WTF {
30
31 class String;
32
33 using std::pair;
34 using std::make_pair;
35
36 template<typename T> struct HashTraits;
37
38 template<bool isInteger, typename T> struct GenericHashTraitsBase;
39
40 template<typename T> struct GenericHashTraitsBase<false, T> {
41 static const bool emptyValueIsZero = false;
42 static const bool needsDestruction = true;
43 };
44
45
46 template<typename T> struct GenericHashTraitsBase<true, T> {
47 static const bool emptyValueIsZero = true;
48 static const bool needsDestruction = false;
49 static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1); }
50 static bool isDeletedValue(T value) { return value == static_cast<T>(-1); }
51 };
52
53 template<typename T> struct GenericHashTraits : GenericHashTraitsBase<IsInteger<T>::value, T> {
54 typedef T TraitType;
55 static T emptyValue() { return T(); }
56 };
57
26 namespace WTF {
27
28 template<typename PairType> struct PairFirstExtractor;
29
30 template<typename KeyArg, typename MappedArg, typename HashArg = typename DefaultHash<KeyArg>::Hash,
31 typename KeyTraitsArg = HashTraits<KeyArg>, typename MappedTraitsArg = HashTraits<MappedArg> >
32 class HashMap {
33 WTF_MAKE_FAST_ALLOCATED;
34 private:
35 typedef KeyTraitsArg KeyTraits;
36 typedef MappedTraitsArg MappedTraits;
37 typedef PairHashTraits<KeyTraits, MappedTraits> ValueTraits;
38
39 public:
40 typedef typename KeyTraits::TraitType KeyType;
41 typedef typename MappedTraits::TraitType MappedType;
42 typedef typename ValueTraits::TraitType ValueType;
43
44 private:
45 typedef HashArg HashFunctions;
46
47 typedef HashTable<KeyType, ValueType, PairFirstExtractor<ValueType>,
48 HashFunctions, ValueTraits, KeyTraits> HashTableType;
49
50 public:
51 typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator;
52 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator;
53
54 void swap(HashMap&);
55
56 int size() const;
57 int capacity() const;
58 bool isEmpty() const;
59
60
61 iterator begin();
62 iterator end();
63 const_iterator begin() const;
64 const_iterator end() const;
65
66 iterator find(const KeyType&);
67 const_iterator find(const KeyType&) const;
68 bool contains(const KeyType&) const;
69 MappedType get(const KeyType&) const;
70
71
72
73
74 pair<iterator, bool> set(const KeyType&, const MappedType&);
75
76
77
78
79 pair<iterator, bool> add(const KeyType&, const MappedType&);
80
81 void remove(const KeyType&);
82 void remove(iterator);
83 void clear();
84
85 MappedType take(const KeyType&);
86
87
88
89
90
91
92 template<typename T, typename HashTranslator> iterator find(const T&);
93 template<typename T, typename HashTranslator> const_iterator find(const T&) const;
94 template<typename T, typename HashTranslator> bool contains(const T&) const;
95
96
97
98
99
100
101
102 template<typename T, typename HashTranslator> pair<iterator, bool> add(const T&, const MappedType&);
103
104 void checkConsistency() const;
105
106 private:
107 pair<iterator, bool> inlineAdd(const KeyType&, const MappedType&);
108
109 HashTableType m_impl;
110 };