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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 template<typename T> ALWAYS_INLINE void derefIfNotNull(T* ptr) | 54 template<typename T> ALWAYS_INLINE void derefIfNotNull(T* ptr) |
55 { | 55 { |
56 if (LIKELY(ptr != 0)) | 56 if (LIKELY(ptr != 0)) |
57 ptr->deref(); | 57 ptr->deref(); |
58 } | 58 } |
59 | 59 |
60 template<typename T> class PassRefPtr { | 60 template<typename T> class PassRefPtr { |
| 61 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(PassRefPtr); |
61 public: | 62 public: |
62 PassRefPtr() : m_ptr(0) { } | 63 PassRefPtr() : m_ptr(0) { } |
| 64 PassRefPtr(std::nullptr_t) : m_ptr(0) { } |
63 PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } | 65 PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } |
64 template<typename U> PassRefPtr(const RawPtr<U>& ptr, EnsurePtrConvertib
leArgDecl(U, T)) : m_ptr(ptr.get()) { refIfNotNull(m_ptr); } | 66 template<typename U> PassRefPtr(const RawPtr<U>& ptr, EnsurePtrConvertib
leArgDecl(U, T)) : m_ptr(ptr.get()) { refIfNotNull(m_ptr); } |
65 explicit PassRefPtr(T& ptr) : m_ptr(&ptr) { m_ptr->ref(); } | 67 explicit PassRefPtr(T& ptr) : m_ptr(&ptr) { m_ptr->ref(); } |
66 // It somewhat breaks the type system to allow transfer of ownership out
of | 68 // It somewhat breaks the type system to allow transfer of ownership out
of |
67 // a const PassRefPtr. However, it makes it much easier to work with Pas
sRefPtr | 69 // a const PassRefPtr. However, it makes it much easier to work with Pas
sRefPtr |
68 // temporaries, and we don't have a need to use real const PassRefPtrs a
nyway. | 70 // temporaries, and we don't have a need to use real const PassRefPtrs a
nyway. |
69 PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { } | 71 PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { } |
70 template<typename U> PassRefPtr(const PassRefPtr<U>& o, EnsurePtrConvert
ibleArgDecl(U, T)) : m_ptr(o.leakRef()) { } | 72 template<typename U> PassRefPtr(const PassRefPtr<U>& o, EnsurePtrConvert
ibleArgDecl(U, T)) : m_ptr(o.leakRef()) { } |
71 | 73 |
72 ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); } | 74 ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return p.get(); | 179 return p.get(); |
178 } | 180 } |
179 | 181 |
180 } // namespace WTF | 182 } // namespace WTF |
181 | 183 |
182 using WTF::PassRefPtr; | 184 using WTF::PassRefPtr; |
183 using WTF::adoptRef; | 185 using WTF::adoptRef; |
184 using WTF::static_pointer_cast; | 186 using WTF::static_pointer_cast; |
185 | 187 |
186 #endif // WTF_PassRefPtr_h | 188 #endif // WTF_PassRefPtr_h |
OLD | NEW |