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 15 matching lines...) Expand all Loading... |
26 #include <algorithm> | 26 #include <algorithm> |
27 #include "wtf/HashTableDeletedValueType.h" | 27 #include "wtf/HashTableDeletedValueType.h" |
28 #include "wtf/PassRefPtr.h" | 28 #include "wtf/PassRefPtr.h" |
29 #include "wtf/RawPtr.h" | 29 #include "wtf/RawPtr.h" |
30 | 30 |
31 namespace WTF { | 31 namespace WTF { |
32 | 32 |
33 template<typename T> class PassRefPtr; | 33 template<typename T> class PassRefPtr; |
34 | 34 |
35 template<typename T> class RefPtr { | 35 template<typename T> class RefPtr { |
| 36 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(RefPtr); |
| 37 WTF_DISALLOW_ZERO_ASSIGNMENT(RefPtr); |
36 public: | 38 public: |
37 ALWAYS_INLINE RefPtr() : m_ptr(0) { } | 39 ALWAYS_INLINE RefPtr() : m_ptr(0) { } |
| 40 ALWAYS_INLINE RefPtr(std::nullptr_t) : m_ptr(0) { } |
38 ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } | 41 ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } |
39 template<typename U> RefPtr(const RawPtr<U>& ptr, EnsurePtrConvertibleAr
gDecl(U, T)) : m_ptr(ptr.get()) { refIfNotNull(m_ptr); } | 42 template<typename U> RefPtr(const RawPtr<U>& ptr, EnsurePtrConvertibleAr
gDecl(U, T)) : m_ptr(ptr.get()) { refIfNotNull(m_ptr); } |
40 ALWAYS_INLINE explicit RefPtr(T& ref) : m_ptr(&ref) { m_ptr->ref(); } | 43 ALWAYS_INLINE explicit RefPtr(T& ref) : m_ptr(&ref) { m_ptr->ref(); } |
41 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_
ptr); } | 44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_
ptr); } |
42 template<typename U> RefPtr(const RefPtr<U>& o, EnsurePtrConvertibleArgD
ecl(U, T)) : m_ptr(o.get()) { refIfNotNull(m_ptr); } | 45 template<typename U> RefPtr(const RefPtr<U>& o, EnsurePtrConvertibleArgD
ecl(U, T)) : m_ptr(o.get()) { refIfNotNull(m_ptr); } |
43 | 46 |
44 // See comments in PassRefPtr.h for an explanation of why this takes a c
onst reference. | 47 // See comments in PassRefPtr.h for an explanation of why this takes a c
onst reference. |
45 template<typename U> RefPtr(const PassRefPtr<U>&, EnsurePtrConvertibleAr
gDecl(U, T)); | 48 template<typename U> RefPtr(const PassRefPtr<U>&, EnsurePtrConvertibleAr
gDecl(U, T)); |
46 | 49 |
47 // Hash table deleted values, which are only constructed and never copie
d or destroyed. | 50 // Hash table deleted values, which are only constructed and never copie
d or destroyed. |
(...skipping 12 matching lines...) Expand all Loading... |
60 | 63 |
61 bool operator!() const { return !m_ptr; } | 64 bool operator!() const { return !m_ptr; } |
62 | 65 |
63 // This conversion operator allows implicit conversion to bool but not t
o other integer types. | 66 // This conversion operator allows implicit conversion to bool but not t
o other integer types. |
64 typedef T* (RefPtr::*UnspecifiedBoolType); | 67 typedef T* (RefPtr::*UnspecifiedBoolType); |
65 operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0
; } | 68 operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0
; } |
66 | 69 |
67 RefPtr& operator=(const RefPtr&); | 70 RefPtr& operator=(const RefPtr&); |
68 RefPtr& operator=(T*); | 71 RefPtr& operator=(T*); |
69 RefPtr& operator=(const PassRefPtr<T>&); | 72 RefPtr& operator=(const PassRefPtr<T>&); |
70 #if !COMPILER_SUPPORTS(CXX_NULLPTR) | |
71 RefPtr& operator=(std::nullptr_t) { clear(); return *this; } | 73 RefPtr& operator=(std::nullptr_t) { clear(); return *this; } |
72 #endif | 74 |
73 template<typename U> RefPtr<T>& operator=(const RefPtr<U>&); | 75 template<typename U> RefPtr<T>& operator=(const RefPtr<U>&); |
74 template<typename U> RefPtr<T>& operator=(const PassRefPtr<U>&); | 76 template<typename U> RefPtr<T>& operator=(const PassRefPtr<U>&); |
75 template<typename U> RefPtr<T>& operator=(const RawPtr<U>&); | 77 template<typename U> RefPtr<T>& operator=(const RawPtr<U>&); |
76 | 78 |
77 void swap(RefPtr&); | 79 void swap(RefPtr&); |
78 | 80 |
79 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } | 81 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } |
80 | 82 |
81 private: | 83 private: |
82 T* m_ptr; | 84 T* m_ptr; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 { | 187 { |
186 return p.get(); | 188 return p.get(); |
187 } | 189 } |
188 | 190 |
189 } // namespace WTF | 191 } // namespace WTF |
190 | 192 |
191 using WTF::RefPtr; | 193 using WTF::RefPtr; |
192 using WTF::static_pointer_cast; | 194 using WTF::static_pointer_cast; |
193 | 195 |
194 #endif // WTF_RefPtr_h | 196 #endif // WTF_RefPtr_h |
OLD | NEW |