| 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 #include <iosfwd> | 9 #include <iosfwd> |
| 10 | 10 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 296 } |
| 297 | 297 |
| 298 T* get() const { return ptr_; } | 298 T* get() const { return ptr_; } |
| 299 | 299 |
| 300 #if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) | 300 #if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) |
| 301 // Allow scoped_refptr<C> to be used in boolean expression | 301 // Allow scoped_refptr<C> to be used in boolean expression |
| 302 // and comparison operations. | 302 // and comparison operations. |
| 303 operator T*() const { return ptr_; } | 303 operator T*() const { return ptr_; } |
| 304 #endif | 304 #endif |
| 305 | 305 |
| 306 explicit operator bool() const { return ptr_ != nullptr; } |
| 307 |
| 306 T& operator*() const { | 308 T& operator*() const { |
| 307 assert(ptr_ != NULL); | 309 assert(ptr_ != nullptr); |
| 308 return *ptr_; | 310 return *ptr_; |
| 309 } | 311 } |
| 310 | 312 |
| 311 T* operator->() const { | 313 T* operator->() const { |
| 312 assert(ptr_ != NULL); | 314 assert(ptr_ != nullptr); |
| 313 return ptr_; | 315 return ptr_; |
| 314 } | 316 } |
| 315 | 317 |
| 316 scoped_refptr<T>& operator=(T* p) { | 318 scoped_refptr<T>& operator=(T* p) { |
| 317 // AddRef first so that self assignment should work | 319 // AddRef first so that self assignment should work |
| 318 if (p) | 320 if (p) |
| 319 p->AddRef(); | 321 p->AddRef(); |
| 320 T* old_ptr = ptr_; | 322 T* old_ptr = ptr_; |
| 321 ptr_ = p; | 323 ptr_ = p; |
| 322 if (old_ptr) | 324 if (old_ptr) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 return !operator==(lhs, rhs); | 395 return !operator==(lhs, rhs); |
| 394 } | 396 } |
| 395 | 397 |
| 396 template <typename T> | 398 template <typename T> |
| 397 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { | 399 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { |
| 398 return out << p.get(); | 400 return out << p.get(); |
| 399 } | 401 } |
| 400 #endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) | 402 #endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) |
| 401 | 403 |
| 402 #endif // BASE_MEMORY_REF_COUNTED_H_ | 404 #endif // BASE_MEMORY_REF_COUNTED_H_ |
| OLD | NEW |