OLD | NEW |
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 Loading... |
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 Loading... |
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_ |
OLD | NEW |