| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <cassert> | 10 #include <cassert> |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 scoped_refptr<T>(std::move(r)).swap(*this); | 347 scoped_refptr<T>(std::move(r)).swap(*this); |
| 348 return *this; | 348 return *this; |
| 349 } | 349 } |
| 350 | 350 |
| 351 template <typename U> | 351 template <typename U> |
| 352 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) { | 352 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) { |
| 353 scoped_refptr<T>(std::move(r)).swap(*this); | 353 scoped_refptr<T>(std::move(r)).swap(*this); |
| 354 return *this; | 354 return *this; |
| 355 } | 355 } |
| 356 | 356 |
| 357 void swap(T** pp) { | |
| 358 T* p = ptr_; | |
| 359 ptr_ = *pp; | |
| 360 *pp = p; | |
| 361 } | |
| 362 | |
| 363 void swap(scoped_refptr<T>& r) { | 357 void swap(scoped_refptr<T>& r) { |
| 364 swap(&r.ptr_); | 358 T* tmp = ptr_; |
| 359 ptr_ = r.ptr_; |
| 360 r.ptr_ = tmp; |
| 365 } | 361 } |
| 366 | 362 |
| 367 explicit operator bool() const { return ptr_ != nullptr; } | 363 explicit operator bool() const { return ptr_ != nullptr; } |
| 368 | 364 |
| 369 template <typename U> | 365 template <typename U> |
| 370 bool operator==(const scoped_refptr<U>& rhs) const { | 366 bool operator==(const scoped_refptr<U>& rhs) const { |
| 371 return ptr_ == rhs.get(); | 367 return ptr_ == rhs.get(); |
| 372 } | 368 } |
| 373 | 369 |
| 374 template <typename U> | 370 template <typename U> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { | 451 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { |
| 456 return !operator==(null, rhs); | 452 return !operator==(null, rhs); |
| 457 } | 453 } |
| 458 | 454 |
| 459 template <typename T> | 455 template <typename T> |
| 460 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { | 456 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { |
| 461 return out << p.get(); | 457 return out << p.get(); |
| 462 } | 458 } |
| 463 | 459 |
| 464 #endif // BASE_MEMORY_REF_COUNTED_H_ | 460 #endif // BASE_MEMORY_REF_COUNTED_H_ |
| OLD | NEW |