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

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

Issue 505943002: Implement the deference operator for scoped_refptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | no next file » | 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (ptr_) 288 if (ptr_)
289 ptr_->Release(); 289 ptr_->Release();
290 } 290 }
291 291
292 T* get() const { return ptr_; } 292 T* get() const { return ptr_; }
293 293
294 // Allow scoped_refptr<C> to be used in boolean expression 294 // Allow scoped_refptr<C> to be used in boolean expression
295 // and comparison operations. 295 // and comparison operations.
296 operator T*() const { return ptr_; } 296 operator T*() const { return ptr_; }
297 297
298 T& operator*() const {
299 assert(ptr_ != NULL);
300 return *ptr_;
301 }
302
298 T* operator->() const { 303 T* operator->() const {
299 assert(ptr_ != NULL); 304 assert(ptr_ != NULL);
300 return ptr_; 305 return ptr_;
301 } 306 }
302 307
303 scoped_refptr<T>& operator=(T* p) { 308 scoped_refptr<T>& operator=(T* p) {
304 // AddRef first so that self assignment should work 309 // AddRef first so that self assignment should work
305 if (p) 310 if (p)
306 p->AddRef(); 311 p->AddRef();
307 T* old_ptr = ptr_; 312 T* old_ptr = ptr_;
(...skipping 27 matching lines...) Expand all
335 }; 340 };
336 341
337 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without 342 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
338 // having to retype all the template arguments 343 // having to retype all the template arguments
339 template <typename T> 344 template <typename T>
340 scoped_refptr<T> make_scoped_refptr(T* t) { 345 scoped_refptr<T> make_scoped_refptr(T* t) {
341 return scoped_refptr<T>(t); 346 return scoped_refptr<T>(t);
342 } 347 }
343 348
344 #endif // BASE_MEMORY_REF_COUNTED_H_ 349 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698