Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: base/memory/ref_counted.h

Issue 623633002: scoped_refptr: support opaque pointed-to classes via extern template (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix header guard Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | base/memory/ref_counted_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ref_counted.h
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h
index 556dbd6ecd0f1ab7f09703b051bf1b5643102cac..1000056bb37d21a932d80509adaedddd6d8cd6f9 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -276,23 +276,23 @@ class scoped_refptr {
scoped_refptr(T* p) : ptr_(p) {
if (ptr_)
- ptr_->AddRef();
+ AddRef(ptr_);
}
scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) {
if (ptr_)
- ptr_->AddRef();
+ AddRef(ptr_);
}
template <typename U>
scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) {
if (ptr_)
- ptr_->AddRef();
+ AddRef(ptr_);
}
~scoped_refptr() {
if (ptr_)
- ptr_->Release();
+ Release(ptr_);
}
T* get() const { return ptr_; }
@@ -316,11 +316,11 @@ class scoped_refptr {
scoped_refptr<T>& operator=(T* p) {
// AddRef first so that self assignment should work
if (p)
- p->AddRef();
+ AddRef(p);
T* old_ptr = ptr_;
ptr_ = p;
if (old_ptr)
- old_ptr->Release();
+ Release(old_ptr);
return *this;
}
@@ -362,8 +362,26 @@ class scoped_refptr {
protected:
T* ptr_;
+
+ private:
+ // Non-inline helpers to allow:
+ // class Opaque;
+ // extern template class scoped_refptr<Opaque>;
+ // Otherwise the compiler will complain that Opaque is an incomplete type.
+ static void AddRef(T* ptr);
+ static void Release(T* ptr);
};
+template <typename T>
+void scoped_refptr<T>::AddRef(T* ptr) {
+ ptr->AddRef();
+}
+
+template <typename T>
+void scoped_refptr<T>::Release(T* ptr) {
+ ptr->Release();
+}
+
// Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
// having to retype all the template arguments
template <typename T>
« no previous file with comments | « base/base.gyp ('k') | base/memory/ref_counted_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698