OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SCOPED_REFPTR_H_ |
| 6 #define SCOPED_REFPTR_H_ |
| 7 |
| 8 // Stub scoped_refptr<T> class that supports an implicit cast to T*. |
| 9 template <class T> |
| 10 class scoped_refptr { |
| 11 public: |
| 12 typedef T element_type; |
| 13 scoped_refptr() : ptr_(0) {} |
| 14 scoped_refptr(T* p) : ptr_(p) {} |
| 15 scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) {} |
| 16 |
| 17 template <typename U> |
| 18 scoped_refptr(const scoped_refptr<U>& r) |
| 19 : ptr_(r.get()) {} |
| 20 |
| 21 ~scoped_refptr() {} |
| 22 |
| 23 T* get() const { return ptr_; } |
| 24 operator T*() const { return ptr_; } |
| 25 T* operator->() const { return ptr_; } |
| 26 |
| 27 scoped_refptr<T>& operator=(T* p) { |
| 28 ptr_ = p; |
| 29 return *this; |
| 30 } |
| 31 scoped_refptr<T>& operator=(const scoped_refptr<T>& r) { |
| 32 return *this = r.ptr_; |
| 33 } |
| 34 template <typename U> |
| 35 scoped_refptr<T>& operator=(const scoped_refptr<U>& r) { |
| 36 return *this = r.get(); |
| 37 } |
| 38 |
| 39 protected: |
| 40 T* ptr_; |
| 41 }; |
| 42 |
| 43 #endif // SCOPED_REFPTR_H_ |
OLD | NEW |