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

Side by Side Diff: third_party/WebKit/Source/wtf/PassRefPtr.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
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/Source/wtf/RefPtr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 template <typename U> PassRefPtr(const RefPtr<U>&, EnsurePtrConvertibleArgDe cl(U, T)); 74 template <typename U> PassRefPtr(const RefPtr<U>&, EnsurePtrConvertibleArgDe cl(U, T));
75 75
76 T* get() const { return m_ptr; } 76 T* get() const { return m_ptr; }
77 77
78 T* leakRef() const WARN_UNUSED_RETURN; 78 T* leakRef() const WARN_UNUSED_RETURN;
79 79
80 T& operator*() const { return *m_ptr; } 80 T& operator*() const { return *m_ptr; }
81 T* operator->() const { return m_ptr; } 81 T* operator->() const { return m_ptr; }
82 82
83 bool operator!() const { return !m_ptr; } 83 bool operator!() const { return !m_ptr; }
84 explicit operator bool() const { return m_ptr; } 84
85 // This conversion operator allows implicit conversion to bool but not to
86 // other integer types.
87 typedef T* (PassRefPtr::*UnspecifiedBoolType);
88 operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::m_ptr : 0 ; }
85 89
86 friend PassRefPtr adoptRef<T>(T*); 90 friend PassRefPtr adoptRef<T>(T*);
87 91
88 private: 92 private:
89 enum AdoptRefTag { AdoptRef }; 93 enum AdoptRefTag { AdoptRef };
90 PassRefPtr(T* ptr, AdoptRefTag) : m_ptr(ptr) {} 94 PassRefPtr(T* ptr, AdoptRefTag) : m_ptr(ptr) {}
91 95
92 PassRefPtr& operator=(const PassRefPtr&) 96 PassRefPtr& operator=(const PassRefPtr&)
93 { 97 {
94 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); 98 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b) 135 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b)
132 { 136 {
133 return a.get() == b; 137 return a.get() == b;
134 } 138 }
135 139
136 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr< U>& b) 140 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr< U>& b)
137 { 141 {
138 return a == b.get(); 142 return a == b.get();
139 } 143 }
140 144
141 template <typename T> inline bool operator==(const PassRefPtr<T>& a, std::nullpt r_t)
142 {
143 return !a.get();
144 }
145
146 template <typename T> inline bool operator==(std::nullptr_t, const PassRefPtr<T> & b)
147 {
148 return !b.get();
149 }
150
151 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b) 145 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
152 { 146 {
153 return a.get() != b.get(); 147 return a.get() != b.get();
154 } 148 }
155 149
156 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b) 150 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b)
157 { 151 {
158 return a.get() != b.get(); 152 return a.get() != b.get();
159 } 153 }
160 154
161 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con st PassRefPtr<U>& b) 155 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con st PassRefPtr<U>& b)
162 { 156 {
163 return a.get() != b.get(); 157 return a.get() != b.get();
164 } 158 }
165 159
166 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b) 160 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b)
167 { 161 {
168 return a.get() != b; 162 return a.get() != b;
169 } 163 }
170 164
171 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr< U>& b) 165 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr< U>& b)
172 { 166 {
173 return a != b.get(); 167 return a != b.get();
174 } 168 }
175 169
176 template <typename T> inline bool operator!=(const PassRefPtr<T>& a, std::nullpt r_t)
177 {
178 return a.get();
179 }
180
181 template <typename T> inline bool operator!=(std::nullptr_t, const PassRefPtr<T> & b)
182 {
183 return b.get();
184 }
185
186 template <typename T> PassRefPtr<T> adoptRef(T* p) 170 template <typename T> PassRefPtr<T> adoptRef(T* p)
187 { 171 {
188 adopted(p); 172 adopted(p);
189 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); 173 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef);
190 } 174 }
191 175
192 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p) 176 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
193 { 177 {
194 return adoptRef(static_cast<T*>(p.leakRef())); 178 return adoptRef(static_cast<T*>(p.leakRef()));
195 } 179 }
196 180
197 template <typename T> inline T* getPtr(const PassRefPtr<T>& p) 181 template <typename T> inline T* getPtr(const PassRefPtr<T>& p)
198 { 182 {
199 return p.get(); 183 return p.get();
200 } 184 }
201 185
202 } // namespace WTF 186 } // namespace WTF
203 187
204 using WTF::PassRefPtr; 188 using WTF::PassRefPtr;
205 using WTF::adoptRef; 189 using WTF::adoptRef;
206 using WTF::static_pointer_cast; 190 using WTF::static_pointer_cast;
207 191
208 #endif // WTF_PassRefPtr_h 192 #endif // WTF_PassRefPtr_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/Source/wtf/RefPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698