Changeset 65130 in webkit for trunk/JavaScriptCore/wtf/RetainPtr.h
- Timestamp:
- Aug 11, 2010, 12:08:23 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/RetainPtr.h
r63562 r65130 1 1 /* 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 49 49 #endif 50 50 51 template 51 template<typename T> class RetainPtr { 52 52 public: 53 53 typedef typename RemovePointer<T>::Type ValueType; … … 68 68 ~RetainPtr() { if (PtrType ptr = m_ptr) CFRelease(ptr); } 69 69 70 template <typename U> RetainPtr(const RetainPtr<U>& o) : m_ptr(o.get()) { if (PtrType ptr = m_ptr) CFRetain(ptr); }70 template<typename U> RetainPtr(const RetainPtr<U>&); 71 71 72 72 PtrType get() const { return m_ptr; } 73 74 PtrType releaseRef() { PtrType tmp = m_ptr; m_ptr = 0; return tmp; } 75 73 74 void clear(); 75 PtrType leakRef() WARN_UNUSED_RETURN; 76 76 77 PtrType operator->() const { return m_ptr; } 77 78 … … 83 84 84 85 RetainPtr& operator=(const RetainPtr&); 85 template 86 template<typename U> RetainPtr& operator=(const RetainPtr<U>&); 86 87 RetainPtr& operator=(PtrType); 87 template 88 template<typename U> RetainPtr& operator=(U*); 88 89 89 90 void adoptCF(PtrType); … … 92 93 void swap(RetainPtr&); 93 94 95 // FIXME: Remove releaseRef once we change all callers to call leakRef instead. 96 PtrType releaseRef() { return leakRef(); } 97 94 98 private: 95 99 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } … … 98 102 }; 99 103 100 template <typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<T>& o) 104 template<typename T> template<typename U> inline RetainPtr<T>::RetainPtr(const RetainPtr<U>& o) 105 : m_ptr(o.get()) 106 { 107 if (PtrType ptr = m_ptr) 108 CFRetain(ptr); 109 } 110 111 template<typename T> inline void RetainPtr<T>::clear() 112 { 113 if (PtrType ptr = m_ptr) { 114 m_ptr = 0; 115 CFRelease(ptr); 116 } 117 } 118 119 template<typename T> inline typename RetainPtr<T>::PtrType RetainPtr<T>::leakRef() 120 { 121 PtrType ptr = m_ptr; 122 m_ptr = 0; 123 return ptr; 124 } 125 126 template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<T>& o) 101 127 { 102 128 PtrType optr = o.get(); … … 110 136 } 111 137 112 template <typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<U>& o)138 template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<U>& o) 113 139 { 114 140 PtrType optr = o.get(); … … 122 148 } 123 149 124 template 125 { 126 if (optr) 127 CFRetain(optr); 128 PtrType ptr = m_ptr; 129 m_ptr = optr; 130 if (ptr) 131 CFRelease(ptr); 132 return *this; 133 } 134 135 template 136 { 137 PtrType ptr = m_ptr; 138 m_ptr = optr; 139 if (ptr) 140 CFRelease(ptr); 141 } 142 143 template 150 template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(PtrType optr) 151 { 152 if (optr) 153 CFRetain(optr); 154 PtrType ptr = m_ptr; 155 m_ptr = optr; 156 if (ptr) 157 CFRelease(ptr); 158 return *this; 159 } 160 161 template<typename T> inline void RetainPtr<T>::adoptCF(PtrType optr) 162 { 163 PtrType ptr = m_ptr; 164 m_ptr = optr; 165 if (ptr) 166 CFRelease(ptr); 167 } 168 169 template<typename T> inline void RetainPtr<T>::adoptNS(PtrType optr) 144 170 { 145 171 adoptNSReference(optr); … … 151 177 } 152 178 153 template <typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)154 { 155 if (optr) 156 CFRetain(optr); 157 PtrType ptr = m_ptr; 158 m_ptr = optr; 159 if (ptr) 160 CFRelease(ptr); 161 return *this; 162 } 163 164 template <classT> inline void RetainPtr<T>::swap(RetainPtr<T>& o)179 template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr) 180 { 181 if (optr) 182 CFRetain(optr); 183 PtrType ptr = m_ptr; 184 m_ptr = optr; 185 if (ptr) 186 CFRelease(ptr); 187 return *this; 188 } 189 190 template<typename T> inline void RetainPtr<T>::swap(RetainPtr<T>& o) 165 191 { 166 192 std::swap(m_ptr, o.m_ptr); 167 193 } 168 194 169 template <classT> inline void swap(RetainPtr<T>& a, RetainPtr<T>& b)195 template<typename T> inline void swap(RetainPtr<T>& a, RetainPtr<T>& b) 170 196 { 171 197 a.swap(b); 172 198 } 173 199 174 template 200 template<typename T, typename U> inline bool operator==(const RetainPtr<T>& a, const RetainPtr<U>& b) 175 201 { 176 202 return a.get() == b.get(); 177 203 } 178 204 179 template 205 template<typename T, typename U> inline bool operator==(const RetainPtr<T>& a, U* b) 180 206 { 181 207 return a.get() == b; 182 208 } 183 209 184 template 210 template<typename T, typename U> inline bool operator==(T* a, const RetainPtr<U>& b) 185 211 { 186 212 return a == b.get(); 187 213 } 188 214 189 template 215 template<typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, const RetainPtr<U>& b) 190 216 { 191 217 return a.get() != b.get(); 192 218 } 193 219 194 template 220 template<typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, U* b) 195 221 { 196 222 return a.get() != b; 197 223 } 198 224 199 template 225 template<typename T, typename U> inline bool operator!=(T* a, const RetainPtr<U>& b) 200 226 { 201 227 return a != b.get();
Note:
See TracChangeset
for help on using the changeset viewer.