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

Side by Side Diff: base/memory/ref_counted.h

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 | « base/files/important_file_writer_unittest.cc ('k') | base/memory/weak_ptr.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MEMORY_REF_COUNTED_H_ 5 #ifndef BASE_MEMORY_REF_COUNTED_H_
6 #define BASE_MEMORY_REF_COUNTED_H_ 6 #define BASE_MEMORY_REF_COUNTED_H_
7 7
8 #include <cassert> 8 #include <cassert>
9 9
10 #include "base/atomic_ref_count.h" 10 #include "base/atomic_ref_count.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { 242 scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) {
243 if (ptr_) 243 if (ptr_)
244 ptr_->AddRef(); 244 ptr_->AddRef();
245 } 245 }
246 246
247 ~scoped_refptr() { 247 ~scoped_refptr() {
248 if (ptr_) 248 if (ptr_)
249 ptr_->Release(); 249 ptr_->Release();
250 } 250 }
251 251
252 // Allow scoped_refptr<T> to be used in boolean expressions, but not
253 // implicitly convertible to a real bool (which is dangerous).
254 typedef T* scoped_refptr::*Testable;
255 operator Testable() const { return ptr_ ? &scoped_refptr::ptr_ : NULL; }
256
252 T* get() const { return ptr_; } 257 T* get() const { return ptr_; }
253 operator T*() const { return ptr_; }
254 T* operator->() const { 258 T* operator->() const {
255 assert(ptr_ != NULL); 259 assert(ptr_ != NULL);
256 return ptr_; 260 return ptr_;
257 } 261 }
258 262
259 // Release a pointer. 263 // Release a pointer.
260 // The return value is the current pointer held by this object. 264 // The return value is the current pointer held by this object.
261 // If this object holds a NULL pointer, the return value is NULL. 265 // If this object holds a NULL pointer, the return value is NULL.
262 // After this operation, this object will hold a NULL pointer, 266 // After this operation, this object will hold a NULL pointer,
263 // and will not own the object any more. 267 // and will not own the object any more.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 }; 306 };
303 307
304 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without 308 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
305 // having to retype all the template arguments 309 // having to retype all the template arguments
306 template <typename T> 310 template <typename T>
307 scoped_refptr<T> make_scoped_refptr(T* t) { 311 scoped_refptr<T> make_scoped_refptr(T* t) {
308 return scoped_refptr<T>(t); 312 return scoped_refptr<T>(t);
309 } 313 }
310 314
311 #endif // BASE_MEMORY_REF_COUNTED_H_ 315 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« no previous file with comments | « base/files/important_file_writer_unittest.cc ('k') | base/memory/weak_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698