| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 { | 63 { |
| 64 PassRefPtr<T> tmp = adoptRef(m_ptr); | 64 PassRefPtr<T> tmp = adoptRef(m_ptr); |
| 65 m_ptr = nullptr; | 65 m_ptr = nullptr; |
| 66 return tmp; | 66 return tmp; |
| 67 } | 67 } |
| 68 | 68 |
| 69 T& operator*() const { return *m_ptr; } | 69 T& operator*() const { return *m_ptr; } |
| 70 ALWAYS_INLINE T* operator->() const { return m_ptr; } | 70 ALWAYS_INLINE T* operator->() const { return m_ptr; } |
| 71 | 71 |
| 72 bool operator!() const { return !m_ptr; } | 72 bool operator!() const { return !m_ptr; } |
| 73 | 73 explicit operator bool() const { return m_ptr; } |
| 74 // This conversion operator allows implicit conversion to bool but not to | |
| 75 // other integer types. | |
| 76 typedef T* (RefPtr::*UnspecifiedBoolType); | |
| 77 operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; } | |
| 78 | 74 |
| 79 RefPtr& operator=(RefPtr o) { swap(o); return *this; } | 75 RefPtr& operator=(RefPtr o) { swap(o); return *this; } |
| 80 RefPtr& operator=(std::nullptr_t) { clear(); return *this; } | 76 RefPtr& operator=(std::nullptr_t) { clear(); return *this; } |
| 81 // This is required by HashMap<RefPtr>>. | 77 // This is required by HashMap<RefPtr>>. |
| 82 template <typename U> RefPtr& operator=(RefPtrValuePeeker<U>); | 78 template <typename U> RefPtr& operator=(RefPtrValuePeeker<U>); |
| 83 | 79 |
| 84 void swap(RefPtr&); | 80 void swap(RefPtr&); |
| 85 | 81 |
| 86 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } | 82 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } |
| 87 | 83 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U*
b) | 124 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U*
b) |
| 129 { | 125 { |
| 130 return a.get() == b; | 126 return a.get() == b; |
| 131 } | 127 } |
| 132 | 128 |
| 133 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>&
b) | 129 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>&
b) |
| 134 { | 130 { |
| 135 return a == b.get(); | 131 return a == b.get(); |
| 136 } | 132 } |
| 137 | 133 |
| 134 template <typename T> inline bool operator==(const RefPtr<T>& a, std::nullptr_t) |
| 135 { |
| 136 return !a.get(); |
| 137 } |
| 138 |
| 139 template <typename T> inline bool operator==(std::nullptr_t, const RefPtr<T>& b) |
| 140 { |
| 141 return !b.get(); |
| 142 } |
| 143 |
| 138 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con
st RefPtr<U>& b) | 144 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con
st RefPtr<U>& b) |
| 139 { | 145 { |
| 140 return a.get() != b.get(); | 146 return a.get() != b.get(); |
| 141 } | 147 } |
| 142 | 148 |
| 143 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U*
b) | 149 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U*
b) |
| 144 { | 150 { |
| 145 return a.get() != b; | 151 return a.get() != b; |
| 146 } | 152 } |
| 147 | 153 |
| 148 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>&
b) | 154 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>&
b) |
| 149 { | 155 { |
| 150 return a != b.get(); | 156 return a != b.get(); |
| 151 } | 157 } |
| 152 | 158 |
| 159 template <typename T> inline bool operator!=(const RefPtr<T>& a, std::nullptr_t) |
| 160 { |
| 161 return a.get(); |
| 162 } |
| 163 |
| 164 template <typename T> inline bool operator!=(std::nullptr_t, const RefPtr<T>& b) |
| 165 { |
| 166 return b.get(); |
| 167 } |
| 168 |
| 153 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const Ref
Ptr<U>& p) | 169 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const Ref
Ptr<U>& p) |
| 154 { | 170 { |
| 155 return RefPtr<T>(static_cast<T*>(p.get())); | 171 return RefPtr<T>(static_cast<T*>(p.get())); |
| 156 } | 172 } |
| 157 | 173 |
| 158 template <typename T> inline T* getPtr(const RefPtr<T>& p) | 174 template <typename T> inline T* getPtr(const RefPtr<T>& p) |
| 159 { | 175 { |
| 160 return p.get(); | 176 return p.get(); |
| 161 } | 177 } |
| 162 | 178 |
| 163 template <typename T> class RefPtrValuePeeker { | 179 template <typename T> class RefPtrValuePeeker { |
| 164 DISALLOW_NEW(); | 180 DISALLOW_NEW(); |
| 165 public: | 181 public: |
| 166 ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) {} | 182 ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) {} |
| 167 ALWAYS_INLINE RefPtrValuePeeker(std::nullptr_t): m_ptr(nullptr) {} | 183 ALWAYS_INLINE RefPtrValuePeeker(std::nullptr_t): m_ptr(nullptr) {} |
| 168 template <typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get())
{} | 184 template <typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get())
{} |
| 169 template <typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get
()) {} | 185 template <typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get
()) {} |
| 170 | 186 |
| 171 ALWAYS_INLINE operator T*() const { return m_ptr; } | 187 ALWAYS_INLINE operator T*() const { return m_ptr; } |
| 172 private: | 188 private: |
| 173 T* m_ptr; | 189 T* m_ptr; |
| 174 }; | 190 }; |
| 175 | 191 |
| 176 } // namespace WTF | 192 } // namespace WTF |
| 177 | 193 |
| 178 using WTF::RefPtr; | 194 using WTF::RefPtr; |
| 179 using WTF::static_pointer_cast; | 195 using WTF::static_pointer_cast; |
| 180 | 196 |
| 181 #endif // WTF_RefPtr_h | 197 #endif // WTF_RefPtr_h |
| OLD | NEW |