| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reser
ved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reser
ved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 template <typename U> PassRefPtr(const RefPtr<U>&, EnsurePtrConvertibleArgDe
cl(U, T)); | 74 template <typename U> PassRefPtr(const RefPtr<U>&, EnsurePtrConvertibleArgDe
cl(U, T)); |
| 75 | 75 |
| 76 T* get() const { return m_ptr; } | 76 T* get() const { return m_ptr; } |
| 77 | 77 |
| 78 T* leakRef() const WARN_UNUSED_RETURN; | 78 T* leakRef() const WARN_UNUSED_RETURN; |
| 79 | 79 |
| 80 T& operator*() const { return *m_ptr; } | 80 T& operator*() const { return *m_ptr; } |
| 81 T* operator->() const { return m_ptr; } | 81 T* operator->() const { return m_ptr; } |
| 82 | 82 |
| 83 bool operator!() const { return !m_ptr; } | 83 bool operator!() const { return !m_ptr; } |
| 84 | 84 explicit operator bool() const { return m_ptr; } |
| 85 // This conversion operator allows implicit conversion to bool but not to | |
| 86 // other integer types. | |
| 87 typedef T* (PassRefPtr::*UnspecifiedBoolType); | |
| 88 operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::m_ptr : 0
; } | |
| 89 | 85 |
| 90 friend PassRefPtr adoptRef<T>(T*); | 86 friend PassRefPtr adoptRef<T>(T*); |
| 91 | 87 |
| 92 private: | 88 private: |
| 93 enum AdoptRefTag { AdoptRef }; | 89 enum AdoptRefTag { AdoptRef }; |
| 94 PassRefPtr(T* ptr, AdoptRefTag) : m_ptr(ptr) {} | 90 PassRefPtr(T* ptr, AdoptRefTag) : m_ptr(ptr) {} |
| 95 | 91 |
| 96 PassRefPtr& operator=(const PassRefPtr&) | 92 PassRefPtr& operator=(const PassRefPtr&) |
| 97 { | 93 { |
| 98 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); | 94 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a,
U* b) | 131 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a,
U* b) |
| 136 { | 132 { |
| 137 return a.get() == b; | 133 return a.get() == b; |
| 138 } | 134 } |
| 139 | 135 |
| 140 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<
U>& b) | 136 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<
U>& b) |
| 141 { | 137 { |
| 142 return a == b.get(); | 138 return a == b.get(); |
| 143 } | 139 } |
| 144 | 140 |
| 141 template <typename T> inline bool operator==(const PassRefPtr<T>& a, std::nullpt
r_t) |
| 142 { |
| 143 return !a.get(); |
| 144 } |
| 145 |
| 146 template <typename T> inline bool operator==(std::nullptr_t, const PassRefPtr<T>
& b) |
| 147 { |
| 148 return !b.get(); |
| 149 } |
| 150 |
| 145 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const PassRefPtr<U>& b) | 151 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const PassRefPtr<U>& b) |
| 146 { | 152 { |
| 147 return a.get() != b.get(); | 153 return a.get() != b.get(); |
| 148 } | 154 } |
| 149 | 155 |
| 150 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const RefPtr<U>& b) | 156 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const RefPtr<U>& b) |
| 151 { | 157 { |
| 152 return a.get() != b.get(); | 158 return a.get() != b.get(); |
| 153 } | 159 } |
| 154 | 160 |
| 155 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con
st PassRefPtr<U>& b) | 161 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con
st PassRefPtr<U>& b) |
| 156 { | 162 { |
| 157 return a.get() != b.get(); | 163 return a.get() != b.get(); |
| 158 } | 164 } |
| 159 | 165 |
| 160 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
U* b) | 166 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
U* b) |
| 161 { | 167 { |
| 162 return a.get() != b; | 168 return a.get() != b; |
| 163 } | 169 } |
| 164 | 170 |
| 165 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<
U>& b) | 171 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<
U>& b) |
| 166 { | 172 { |
| 167 return a != b.get(); | 173 return a != b.get(); |
| 168 } | 174 } |
| 169 | 175 |
| 176 template <typename T> inline bool operator!=(const PassRefPtr<T>& a, std::nullpt
r_t) |
| 177 { |
| 178 return a.get(); |
| 179 } |
| 180 |
| 181 template <typename T> inline bool operator!=(std::nullptr_t, const PassRefPtr<T>
& b) |
| 182 { |
| 183 return b.get(); |
| 184 } |
| 185 |
| 170 template <typename T> PassRefPtr<T> adoptRef(T* p) | 186 template <typename T> PassRefPtr<T> adoptRef(T* p) |
| 171 { | 187 { |
| 172 adopted(p); | 188 adopted(p); |
| 173 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); | 189 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); |
| 174 } | 190 } |
| 175 | 191 |
| 176 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const
PassRefPtr<U>& p) | 192 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const
PassRefPtr<U>& p) |
| 177 { | 193 { |
| 178 return adoptRef(static_cast<T*>(p.leakRef())); | 194 return adoptRef(static_cast<T*>(p.leakRef())); |
| 179 } | 195 } |
| 180 | 196 |
| 181 template <typename T> inline T* getPtr(const PassRefPtr<T>& p) | 197 template <typename T> inline T* getPtr(const PassRefPtr<T>& p) |
| 182 { | 198 { |
| 183 return p.get(); | 199 return p.get(); |
| 184 } | 200 } |
| 185 | 201 |
| 186 } // namespace WTF | 202 } // namespace WTF |
| 187 | 203 |
| 188 using WTF::PassRefPtr; | 204 using WTF::PassRefPtr; |
| 189 using WTF::adoptRef; | 205 using WTF::adoptRef; |
| 190 using WTF::static_pointer_cast; | 206 using WTF::static_pointer_cast; |
| 191 | 207 |
| 192 #endif // WTF_PassRefPtr_h | 208 #endif // WTF_PassRefPtr_h |
| OLD | NEW |