Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: third_party/WebKit/Source/wtf/RefPtr.h

Issue 1912203002: Revert of WTF: Implement explicit RefPtr::operator bool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 explicit operator bool() const { return m_ptr; } 73
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; }
74 78
75 RefPtr& operator=(RefPtr o) { swap(o); return *this; } 79 RefPtr& operator=(RefPtr o) { swap(o); return *this; }
76 RefPtr& operator=(std::nullptr_t) { clear(); return *this; } 80 RefPtr& operator=(std::nullptr_t) { clear(); return *this; }
77 // This is required by HashMap<RefPtr>>. 81 // This is required by HashMap<RefPtr>>.
78 template <typename U> RefPtr& operator=(RefPtrValuePeeker<U>); 82 template <typename U> RefPtr& operator=(RefPtrValuePeeker<U>);
79 83
80 void swap(RefPtr&); 84 void swap(RefPtr&);
81 85
82 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } 86 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
83 87
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b) 128 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
125 { 129 {
126 return a.get() == b; 130 return a.get() == b;
127 } 131 }
128 132
129 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b) 133 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
130 { 134 {
131 return a == b.get(); 135 return a == b.get();
132 } 136 }
133 137
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
144 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con st RefPtr<U>& b) 138 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con st RefPtr<U>& b)
145 { 139 {
146 return a.get() != b.get(); 140 return a.get() != b.get();
147 } 141 }
148 142
149 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b) 143 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
150 { 144 {
151 return a.get() != b; 145 return a.get() != b;
152 } 146 }
153 147
154 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b) 148 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
155 { 149 {
156 return a != b.get(); 150 return a != b.get();
157 } 151 }
158 152
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
169 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const Ref Ptr<U>& p) 153 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const Ref Ptr<U>& p)
170 { 154 {
171 return RefPtr<T>(static_cast<T*>(p.get())); 155 return RefPtr<T>(static_cast<T*>(p.get()));
172 } 156 }
173 157
174 template <typename T> inline T* getPtr(const RefPtr<T>& p) 158 template <typename T> inline T* getPtr(const RefPtr<T>& p)
175 { 159 {
176 return p.get(); 160 return p.get();
177 } 161 }
178 162
179 template <typename T> class RefPtrValuePeeker { 163 template <typename T> class RefPtrValuePeeker {
180 DISALLOW_NEW(); 164 DISALLOW_NEW();
181 public: 165 public:
182 ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) {} 166 ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) {}
183 ALWAYS_INLINE RefPtrValuePeeker(std::nullptr_t): m_ptr(nullptr) {} 167 ALWAYS_INLINE RefPtrValuePeeker(std::nullptr_t): m_ptr(nullptr) {}
184 template <typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get()) {} 168 template <typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get()) {}
185 template <typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get ()) {} 169 template <typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get ()) {}
186 170
187 ALWAYS_INLINE operator T*() const { return m_ptr; } 171 ALWAYS_INLINE operator T*() const { return m_ptr; }
188 private: 172 private:
189 T* m_ptr; 173 T* m_ptr;
190 }; 174 };
191 175
192 } // namespace WTF 176 } // namespace WTF
193 177
194 using WTF::RefPtr; 178 using WTF::RefPtr;
195 using WTF::static_pointer_cast; 179 using WTF::static_pointer_cast;
196 180
197 #endif // WTF_RefPtr_h 181 #endif // WTF_RefPtr_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/PassRefPtr.h ('k') | third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698