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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #ifndef WTF_PassRefPtr_h | 21 #ifndef WTF_PassRefPtr_h |
22 #define WTF_PassRefPtr_h | 22 #define WTF_PassRefPtr_h |
23 | 23 |
24 #include "wtf/Assertions.h" | 24 #include "wtf/Assertions.h" |
25 #include "wtf/NullPtr.h" | 25 #include "wtf/NullPtr.h" |
26 #include "wtf/RawPtr.h" | 26 #include "wtf/RawPtr.h" |
27 #include "wtf/TypeTraits.h" | 27 #include "wtf/TypeTraits.h" |
28 | 28 |
29 namespace blink { | |
30 template<typename T> class RefCountedGarbageCollected; | |
31 } | |
32 | |
29 namespace WTF { | 33 namespace WTF { |
30 | 34 |
31 template<typename T> class RefPtr; | 35 template<typename T> class RefPtr; |
32 template<typename T> class PassRefPtr; | 36 template<typename T> class PassRefPtr; |
33 template<typename T> PassRefPtr<T> adoptRef(T*); | 37 template<typename T> PassRefPtr<T> adoptRef(T*); |
34 | 38 |
35 inline void adopted(const void*) { } | 39 inline void adopted(const void*) { } |
36 | 40 |
37 // requireAdoption() is not overloaded for WTF::RefCounted, which has a | 41 // requireAdoption() is not overloaded for WTF::RefCounted, which has a |
38 // built-in assumption that adoption is required. requireAdoption() is | 42 // built-in assumption that adoption is required. requireAdoption() is |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 return a.get() != b.get(); | 182 return a.get() != b.get(); |
179 } | 183 } |
180 | 184 |
181 template<typename T, typename U> inline bool operator!=(const RawPtr<T>& a, const PassRefPtr<U>& b) | 185 template<typename T, typename U> inline bool operator!=(const RawPtr<T>& a, const PassRefPtr<U>& b) |
182 { | 186 { |
183 return a.get() != b.get(); | 187 return a.get() != b.get(); |
184 } | 188 } |
185 | 189 |
186 template<typename T> PassRefPtr<T> adoptRef(T* p) | 190 template<typename T> PassRefPtr<T> adoptRef(T* p) |
187 { | 191 { |
192 static const bool notRefCountedGarbageCollected = !WTF::IsSubclassOfTemp late<typename WTF::RemoveConst<T>::Type, blink::RefCountedGarbageCollected>::val ue; | |
193 COMPILE_ASSERT(notRefCountedGarbageCollected, adoptRefIsNotAllowedForRef CountedGarbageCollected); | |
Mikhail
2014/10/14 11:05:10
wouldn't smth like
template<T> void adoptRef(con
tkent
2014/11/10 06:06:59
Mikhail's idea looks better.
This patch has a laye
haraken
2014/11/10 06:41:56
Hmm, it looks like I need your help.
When I add:
Mikhail
2014/11/10 10:10:57
yeah, sorry this trick does not work with function
| |
188 adopted(p); | 194 adopted(p); |
189 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); | 195 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); |
190 } | 196 } |
191 | 197 |
192 template<typename T, typename U> inline PassRefPtr<T> static_pointer_cast(co nst PassRefPtr<U>& p) | 198 template<typename T, typename U> inline PassRefPtr<T> static_pointer_cast(co nst PassRefPtr<U>& p) |
193 { | 199 { |
194 return adoptRef(static_cast<T*>(p.leakRef())); | 200 return adoptRef(static_cast<T*>(p.leakRef())); |
195 } | 201 } |
196 | 202 |
197 template<typename T> inline T* getPtr(const PassRefPtr<T>& p) | 203 template<typename T> inline T* getPtr(const PassRefPtr<T>& p) |
198 { | 204 { |
199 return p.get(); | 205 return p.get(); |
200 } | 206 } |
201 | 207 |
202 } // namespace WTF | 208 } // namespace WTF |
203 | 209 |
204 using WTF::PassRefPtr; | 210 using WTF::PassRefPtr; |
205 using WTF::adoptRef; | 211 using WTF::adoptRef; |
206 using WTF::static_pointer_cast; | 212 using WTF::static_pointer_cast; |
207 | 213 |
208 #endif // WTF_PassRefPtr_h | 214 #endif // WTF_PassRefPtr_h |
OLD | NEW |