Changeset 11727 in webkit for trunk/JavaScriptCore/kxmlcore/PassRefPtr.h
- Timestamp:
- Dec 22, 2005, 8:48:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kxmlcore/PassRefPtr.h
r11684 r11727 44 44 PassRefPtr() : m_ptr(0) {} 45 45 PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } 46 PassRefPtr(const RefPtr<T>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }47 46 PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {} 47 template <typename U> PassRefPtr(PassRefPtr<U>& o) : m_ptr(o.release()) { } 48 48 49 49 ~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); } … … 56 56 T *release() { T *tmp = m_ptr; m_ptr = 0; return tmp; } 57 57 58 static PassRefPtr<T> adopt(T *ptr) 59 { 60 PassRefPtr result; 61 result.m_ptr = ptr; 62 return result; 58 template <typename U> static PassRefPtr<T> adopt(U* ptr) 59 { 60 PassRefPtr result((PassRefPtr_Ref<T>(ptr))); 61 return result; 63 62 } 64 63 … … 72 71 operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::get : 0; } 73 72 74 PassRefPtr& operator=(const RefPtr<T>&);75 73 PassRefPtr& operator=(T *); 76 74 PassRefPtr& operator=(PassRefPtr&); 75 template <typename U> PassRefPtr& operator=(PassRefPtr<U>&); 76 template <typename U> PassRefPtr& operator=(const RefPtr<U>&); 77 77 78 78 PassRefPtr(PassRefPtr_Ref<T> ref) : m_ptr(ref.m_ptr) { } … … 86 86 } 87 87 88 template<typename U> 89 operator PassRefPtr_Ref<U>() 90 { 91 return PassRefPtr_Ref<U>(release()); 92 } 93 94 template<typename U> 95 operator PassRefPtr<U>() 96 { 97 return PassRefPtr<U>(this->release()); 98 } 88 template <typename U> operator PassRefPtr_Ref<U>() { return PassRefPtr_Ref<U>(release()); } 89 template <typename U> operator PassRefPtr<U>() { return PassRefPtr_Ref<U>(release()); } 99 90 100 91 private: … … 102 93 }; 103 94 104 template < class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<T>& o)95 template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<U>& o) 105 96 { 106 97 T *optr = o.m_ptr; … … 113 104 } 114 105 115 template < class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T *optr)106 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr) 116 107 { 117 108 if (optr) … … 123 114 } 124 115 125 template < classT> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<T>& ref)116 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<T>& ref) 126 117 { 127 118 T *optr = ref.release(); … … 132 123 } 133 124 134 template <class T> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<T>& b) 125 template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<U>& ref) 126 { 127 T *optr = ref.release(); 128 if (T *ptr = m_ptr) 129 ptr->deref(); 130 m_ptr = optr; 131 return *this; 132 } 133 134 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b) 135 135 { 136 136 return a.get() == b.get(); 137 137 } 138 138 139 template < class T> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<T>& b)139 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<U>& b) 140 140 { 141 141 return a.get() == b.get(); 142 142 } 143 143 144 template < class T> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<T>& b)144 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<U>& b) 145 145 { 146 146 return a.get() == b.get(); 147 147 } 148 148 149 template < class T> inline bool operator==(const PassRefPtr<T>& a, const T *b)149 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b) 150 150 { 151 151 return a.get() == b; 152 152 } 153 153 154 template < class T> inline bool operator==(const T *a, const PassRefPtr<T>& b)154 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<U>& b) 155 155 { 156 156 return a == b.get(); 157 157 } 158 158 159 template < class T> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<T>& b)159 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b) 160 160 { 161 161 return a.get() != b.get(); 162 162 } 163 163 164 template < class T> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<T>& b)164 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b) 165 165 { 166 166 return a.get() != b.get(); 167 167 } 168 168 169 template < class T> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<T>& b)169 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<U>& b) 170 170 { 171 171 return a.get() != b.get(); 172 172 } 173 173 174 template < class T> inline bool operator!=(const PassRefPtr<T>& a, const T *b)174 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b) 175 175 { 176 176 return a.get() != b; 177 177 } 178 178 179 template < class T> inline bool operator!=(const T *a, const PassRefPtr<T>& b)179 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<U>& b) 180 180 { 181 181 return a != b.get(); 182 182 } 183 183 184 template < class T, classU> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)184 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p) 185 185 { 186 186 return PassRefPtr<T>::adopt(static_cast<T *>(p.release())); 187 187 } 188 188 189 template < class T, classU> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)189 template <typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p) 190 190 { 191 191 return PassRefPtr<T>::adopt(const_cast<T *>(p.release()));
Note:
See TracChangeset
for help on using the changeset viewer.