Changeset 12162 in webkit for trunk/JavaScriptCore/kxmlcore/HashTraits.h
- Timestamp:
- Jan 17, 2006, 8:33:55 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kxmlcore/HashTraits.h
r11962 r12162 2 2 /* 3 3 * This file is part of the KDE libraries 4 * Copyright (C) 2005 Apple Computer, Inc.4 * Copyright (C) 2005, 2006 Apple Computer, Inc. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 30 30 31 31 using std::pair; 32 32 33 33 template <typename T> struct IsInteger { static const bool value = false; }; 34 34 template <> struct IsInteger<bool> { static const bool value = true; }; … … 44 44 template <> struct IsInteger<long long> { static const bool value = true; }; 45 45 template <> struct IsInteger<unsigned long long> { static const bool value = true; }; 46 47 template<typename T> 48 struct GenericHashTraits { 46 47 template<typename T> struct GenericHashTraits { 49 48 typedef T TraitType; 50 49 static const bool emptyValueIsZero = IsInteger<T>::value; … … 53 52 }; 54 53 55 template<typename T> 56 struct HashTraits : GenericHashTraits<T> { 57 }; 54 template<typename T> struct HashTraits : GenericHashTraits<T> { }; 58 55 59 // may not be appropriate for all uses since it would disallow 0 and -1 as keys 60 template<> 61 struct HashTraits<int> : GenericHashTraits<int> { 56 // may not be appropriate for all uses since it disallows 0 and -1 as keys 57 template<> struct HashTraits<int> : GenericHashTraits<int> { 62 58 static TraitType deletedValue() { return -1; } 63 59 }; 64 60 65 template<typename P> 66 struct HashTraits<P *> : GenericHashTraits<P *> { 67 typedef P *TraitType; 61 template<typename P> struct HashTraits<P*> : GenericHashTraits<P*> { 62 typedef P* TraitType; 68 63 static const bool emptyValueIsZero = true; 69 64 static const bool needsDestruction = false; 70 static TraitType emptyValue() { return reinterpret_cast<P *>(0); }71 static TraitType deletedValue() { return reinterpret_cast<P 65 static TraitType emptyValue() { return 0; } 66 static TraitType deletedValue() { return reinterpret_cast<P*>(-1); } 72 67 }; 73 68 74 template<typename P> 75 struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > { 69 template<typename P> struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > { 76 70 static const bool emptyValueIsZero = true; 77 71 }; 78 72 79 template<typename T, typename Traits> 80 class DeletedValueAssigner; 73 template<typename T, typename Traits> class DeletedValueAssigner; 81 74 82 template<typename T, typename Traits> 83 inline void assignDeleted(T& location) 75 template<typename T, typename Traits> inline void assignDeleted(T& location) 84 76 { 85 77 DeletedValueAssigner<T, Traits>::assignDeletedValue(location); … … 96 88 static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero; 97 89 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction; 98 99 static TraitType emptyValue() 90 91 static TraitType emptyValue() 100 92 { 101 93 return TraitType(FirstTraits::emptyValue(), SecondTraits::emptyValue()); 102 94 } 103 95 104 static TraitType deletedValue() 96 static TraitType deletedValue() 105 97 { 106 98 return TraitType(FirstTraits::deletedValue(), SecondTraits::emptyValue()); … … 115 107 116 108 template<typename First, typename Second> 117 struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { 118 }; 109 struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { }; 119 110 120 template<typename T, typename Traits> 121 struct DeletedValueAssigner 122 { 123 static void assignDeletedValue(T& location) 124 { 125 location = Traits::deletedValue(); 126 } 111 template<typename T, typename Traits> struct DeletedValueAssigner { 112 static void assignDeletedValue(T& location) { location = Traits::deletedValue(); } 127 113 }; 128 114 … … 130 116 struct DeletedValueAssigner<pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>, PairHashTraits<FirstTraits, SecondTraits> > 131 117 { 132 static void assignDeletedValue(pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>& location) 133 { 118 static void assignDeletedValue(pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>& location) 119 { 134 120 PairHashTraits<FirstTraits, SecondTraits>::assignDeletedValue(location); 135 121 } … … 139 125 struct DeletedValueAssigner<pair<First, Second>, HashTraits<pair<First, Second> > > 140 126 { 141 static void assignDeletedValue(pair<First, Second>& location) 142 { 127 static void assignDeletedValue(pair<First, Second>& location) 128 { 143 129 HashTraits<pair<First, Second> >::assignDeletedValue(location); 144 130 }
Note:
See TracChangeset
for help on using the changeset viewer.