diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 23:14:23 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 23:14:23 +0000 |
commit | f8f8250237f535750e0d8269d2762f52db090e45 (patch) | |
tree | 1cdf3da8041969b9b0ac8c045ca2bf458256ca66 /base/ref_counted.h | |
parent | c1dc9f130ed8792c3e821f486d3c5e1ed4e567f3 (diff) | |
download | chromium_src-f8f8250237f535750e0d8269d2762f52db090e45.zip chromium_src-f8f8250237f535750e0d8269d2762f52db090e45.tar.gz chromium_src-f8f8250237f535750e0d8269d2762f52db090e45.tar.bz2 |
Forces T*s to scoped_refptr<T> when PostTask()ing to a function expecting scoped_refptr<T>
Review URL: http://codereview.chromium.org/418007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32706 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/ref_counted.h')
-rw-r--r-- | base/ref_counted.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/ref_counted.h b/base/ref_counted.h index f2e4327..e8413d9 100644 --- a/base/ref_counted.h +++ b/base/ref_counted.h @@ -227,6 +227,12 @@ class scoped_refptr { ptr_->AddRef(); } + template <typename U> + scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { + if (ptr_) + ptr_->AddRef(); + } + ~scoped_refptr() { if (ptr_) ptr_->Release(); @@ -261,6 +267,11 @@ class scoped_refptr { return *this = r.ptr_; } + template <typename U> + scoped_refptr<T>& operator=(const scoped_refptr<U>& r) { + return *this = r.get(); + } + void swap(T** pp) { T* p = ptr_; ptr_ = *pp; @@ -275,4 +286,11 @@ class scoped_refptr { T* ptr_; }; +// Handy utility for creating a scoped_refptr<T> out of a T* explicitly without +// having to retype all the template arguments +template <typename T> +scoped_refptr<T> make_scoped_refptr(T* t) { + return scoped_refptr<T>(t); +} + #endif // BASE_REF_COUNTED_H_ |