Changeset 65130 in webkit for trunk/JavaScriptCore/wtf/RefPtr.h
- Timestamp:
- Aug 11, 2010, 12:08:23 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/RefPtr.h
r62674 r65130 33 33 enum PlacementNewAdoptType { PlacementNewAdopt }; 34 34 35 template 36 template 35 template<typename T> class PassRefPtr; 36 template<typename T> class NonNullPassRefPtr; 37 37 38 38 enum HashTableDeletedValueType { HashTableDeletedValue }; 39 39 40 template 40 template<typename T> class RefPtr : public FastAllocBase { 41 41 public: 42 42 ALWAYS_INLINE RefPtr() : m_ptr(0) { } 43 43 ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } 44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { T* ptr = m_ptr; refIfNotNull(ptr); } 45 // see comment in PassRefPtr.h for why this takes const reference 46 template <typename U> RefPtr(const PassRefPtr<U>&); 47 template <typename U> RefPtr(const NonNullPassRefPtr<U>&); 44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); } 45 template<typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { refIfNotNull(m_ptr); } 46 47 // See comments in PassRefPtr.h for an explanation of why these takes const references. 48 template<typename U> RefPtr(const PassRefPtr<U>&); 49 template<typename U> RefPtr(const NonNullPassRefPtr<U>&); 48 50 49 51 // Special constructor for cases where we overwrite an object in place. … … 55 57 56 58 ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); } 57 58 template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); } 59 59 60 60 T* get() const { return m_ptr; } 61 61 … … 76 76 RefPtr& operator=(const PassRefPtr<T>&); 77 77 RefPtr& operator=(const NonNullPassRefPtr<T>&); 78 template 79 template 80 template 78 template<typename U> RefPtr& operator=(const RefPtr<U>&); 79 template<typename U> RefPtr& operator=(const PassRefPtr<U>&); 80 template<typename U> RefPtr& operator=(const NonNullPassRefPtr<U>&); 81 81 82 82 void swap(RefPtr&); … … 88 88 }; 89 89 90 template <typename T> template<typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o)91 : m_ptr(o. releaseRef())92 { 93 } 94 95 template <typename T> template<typename U> inline RefPtr<T>::RefPtr(const NonNullPassRefPtr<U>& o)96 : m_ptr(o. releaseRef())97 { 98 } 99 100 template 90 template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o) 91 : m_ptr(o.leakRef()) 92 { 93 } 94 95 template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const NonNullPassRefPtr<U>& o) 96 : m_ptr(o.leakRef()) 97 { 98 } 99 100 template<typename T> inline void RefPtr<T>::clear() 101 101 { 102 102 T* ptr = m_ptr; … … 105 105 } 106 106 107 template 107 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o) 108 108 { 109 109 T* optr = o.get(); … … 115 115 } 116 116 117 template <typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)117 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o) 118 118 { 119 119 T* optr = o.get(); … … 125 125 } 126 126 127 template 127 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr) 128 128 { 129 129 refIfNotNull(optr); … … 134 134 } 135 135 136 template 137 { 138 T* ptr = m_ptr; 139 m_ptr = o. releaseRef();140 derefIfNotNull(ptr); 141 return *this; 142 } 143 144 template 145 { 146 T* ptr = m_ptr; 147 m_ptr = o. releaseRef();148 derefIfNotNull(ptr); 149 return *this; 150 } 151 152 template <typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o)153 { 154 T* ptr = m_ptr; 155 m_ptr = o. releaseRef();156 derefIfNotNull(ptr); 157 return *this; 158 } 159 160 template <typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<U>& o)161 { 162 T* ptr = m_ptr; 163 m_ptr = o. releaseRef();164 derefIfNotNull(ptr); 165 return *this; 166 } 167 168 template 136 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o) 137 { 138 T* ptr = m_ptr; 139 m_ptr = o.leakRef(); 140 derefIfNotNull(ptr); 141 return *this; 142 } 143 144 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<T>& o) 145 { 146 T* ptr = m_ptr; 147 m_ptr = o.leakRef(); 148 derefIfNotNull(ptr); 149 return *this; 150 } 151 152 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o) 153 { 154 T* ptr = m_ptr; 155 m_ptr = o.leakRef(); 156 derefIfNotNull(ptr); 157 return *this; 158 } 159 160 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<U>& o) 161 { 162 T* ptr = m_ptr; 163 m_ptr = o.leakRef(); 164 derefIfNotNull(ptr); 165 return *this; 166 } 167 168 template<class T> inline void RefPtr<T>::swap(RefPtr<T>& o) 169 169 { 170 170 std::swap(m_ptr, o.m_ptr); 171 171 } 172 172 173 template 173 template<class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b) 174 174 { 175 175 a.swap(b); 176 176 } 177 177 178 template 178 template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b) 179 179 { 180 180 return a.get() == b.get(); 181 181 } 182 182 183 template 183 template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b) 184 184 { 185 185 return a.get() == b; 186 186 } 187 187 188 template 188 template<typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b) 189 189 { 190 190 return a == b.get(); 191 191 } 192 192 193 template 193 template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b) 194 194 { 195 195 return a.get() != b.get(); 196 196 } 197 197 198 template 198 template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b) 199 199 { 200 200 return a.get() != b; 201 201 } 202 202 203 template 203 template<typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b) 204 204 { 205 205 return a != b.get(); 206 206 } 207 207 208 template 208 template<typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p) 209 209 { 210 210 return RefPtr<T>(static_cast<T*>(p.get())); 211 211 } 212 212 213 template 213 template<typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p) 214 214 { 215 215 return RefPtr<T>(const_cast<T*>(p.get())); 216 216 } 217 217 218 template 218 template<typename T> inline T* getPtr(const RefPtr<T>& p) 219 219 { 220 220 return p.get();
Note:
See TracChangeset
for help on using the changeset viewer.