OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 ALWAYS_INLINE ~PassRefPtr() { DerefIfNotNull(ptr_); } | 80 ALWAYS_INLINE ~PassRefPtr() { DerefIfNotNull(ptr_); } |
81 | 81 |
82 template <typename U> | 82 template <typename U> |
83 PassRefPtr(const RefPtr<U>&, EnsurePtrConvertibleArgDecl(U, T)); | 83 PassRefPtr(const RefPtr<U>&, EnsurePtrConvertibleArgDecl(U, T)); |
84 template <typename U> | 84 template <typename U> |
85 PassRefPtr(RefPtr<U>&&, EnsurePtrConvertibleArgDecl(U, T)); | 85 PassRefPtr(RefPtr<U>&&, EnsurePtrConvertibleArgDecl(U, T)); |
86 | 86 |
87 T* Get() const { return ptr_; } | 87 T* Get() const { return ptr_; } |
88 | 88 |
89 WARN_UNUSED_RESULT T* LeakRef() const; | 89 WARN_UNUSED_RESULT T* LeakRef(); |
90 | 90 |
91 T& operator*() const { return *ptr_; } | 91 T& operator*() const { return *ptr_; } |
92 T* operator->() const { return ptr_; } | 92 T* operator->() const { return ptr_; } |
93 | 93 |
94 bool operator!() const { return !ptr_; } | 94 bool operator!() const { return !ptr_; } |
95 explicit operator bool() const { return ptr_ != nullptr; } | 95 explicit operator bool() const { return ptr_ != nullptr; } |
96 | 96 |
97 friend PassRefPtr AdoptRef<T>(T*); | 97 friend PassRefPtr AdoptRef<T>(T*); |
98 | 98 |
99 private: | 99 private: |
100 enum AdoptRefTag { kAdoptRef }; | 100 enum AdoptRefTag { kAdoptRef }; |
101 PassRefPtr(T* ptr, AdoptRefTag) : ptr_(ptr) {} | 101 PassRefPtr(T* ptr, AdoptRefTag) : ptr_(ptr) {} |
102 | 102 |
103 PassRefPtr& operator=(const PassRefPtr&) { | 103 PassRefPtr& operator=(const PassRefPtr&) { |
104 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); | 104 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); |
105 return *this; | 105 return *this; |
106 } | 106 } |
107 | 107 |
108 mutable T* ptr_; | 108 T* ptr_; |
109 }; | 109 }; |
110 | 110 |
111 template <typename T> | 111 template <typename T> |
112 PassRefPtr<T> WrapPassRefPtr(T* ptr) { | 112 PassRefPtr<T> WrapPassRefPtr(T* ptr) { |
113 return PassRefPtr<T>(ptr); | 113 return PassRefPtr<T>(ptr); |
114 } | 114 } |
115 | 115 |
116 template <typename T> | 116 template <typename T> |
117 template <typename U> | 117 template <typename U> |
118 inline PassRefPtr<T>::PassRefPtr(const RefPtr<U>& o, | 118 inline PassRefPtr<T>::PassRefPtr(const RefPtr<U>& o, |
119 EnsurePtrConvertibleArgDefn(U, T)) | 119 EnsurePtrConvertibleArgDefn(U, T)) |
120 : ptr_(o.Get()) { | 120 : ptr_(o.Get()) { |
121 T* ptr = ptr_; | 121 T* ptr = ptr_; |
122 RefIfNotNull(ptr); | 122 RefIfNotNull(ptr); |
123 } | 123 } |
124 | 124 |
125 template <typename T> | 125 template <typename T> |
126 template <typename U> | 126 template <typename U> |
127 inline PassRefPtr<T>::PassRefPtr(RefPtr<U>&& o, | 127 inline PassRefPtr<T>::PassRefPtr(RefPtr<U>&& o, |
128 EnsurePtrConvertibleArgDefn(U, T)) | 128 EnsurePtrConvertibleArgDefn(U, T)) |
129 : ptr_(o.LeakRef()) {} | 129 : ptr_(o.LeakRef()) {} |
130 | 130 |
131 template <typename T> | 131 template <typename T> |
132 inline T* PassRefPtr<T>::LeakRef() const { | 132 inline T* PassRefPtr<T>::LeakRef() { |
133 T* ptr = ptr_; | 133 T* ptr = ptr_; |
134 ptr_ = nullptr; | 134 ptr_ = nullptr; |
135 return ptr; | 135 return ptr; |
136 } | 136 } |
137 | 137 |
138 template <typename T, typename U> | 138 template <typename T, typename U> |
139 inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b) { | 139 inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b) { |
140 return a.Get() == b.Get(); | 140 return a.Get() == b.Get(); |
141 } | 141 } |
142 | 142 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 inline T* GetPtr(const PassRefPtr<T>& p) { | 215 inline T* GetPtr(const PassRefPtr<T>& p) { |
216 return p.Get(); | 216 return p.Get(); |
217 } | 217 } |
218 | 218 |
219 } // namespace WTF | 219 } // namespace WTF |
220 | 220 |
221 using WTF::PassRefPtr; | 221 using WTF::PassRefPtr; |
222 using WTF::AdoptRef; | 222 using WTF::AdoptRef; |
223 | 223 |
224 #endif // WTF_PassRefPtr_h | 224 #endif // WTF_PassRefPtr_h |
OLD | NEW |