Index: skia/ext/refptr.h |
diff --git a/skia/ext/refptr.h b/skia/ext/refptr.h |
index a3900f61ba4502c0d59c3b8664cf6bb4dd3c4aa1..1e66a5215791a599dc869d3dd7bb779d484333a1 100644 |
--- a/skia/ext/refptr.h |
+++ b/skia/ext/refptr.h |
@@ -5,6 +5,8 @@ |
#ifndef SKIA_EXT_REFPTR_H_ |
#define SKIA_EXT_REFPTR_H_ |
+#include "base/basictypes.h" |
+#include "base/logging.h" |
#include "third_party/skia/include/core/SkRefCnt.h" |
namespace skia { |
@@ -87,6 +89,30 @@ class RefPtr { |
return ptr_ ? &RefPtr::ptr_ : NULL; |
} |
+ class Receiver { |
+ public: |
+ ~Receiver() { |
+ DCHECK(!*refptr_) << "RefPtr must be empty."; |
+ refptr_->ptr_ = ptr_; |
+ } |
+ |
+ operator T**() { return &ptr_; } |
+ |
+ private: |
+ friend class RefPtr; |
+ |
+ Receiver(RefPtr* refptr) : refptr_(refptr), ptr_(NULL) { |
awong
2013/07/17 23:12:59
explicit?
danakj
2013/07/17 23:18:46
Done.
|
+ DCHECK(!*refptr_) << "RefPtr must be empty."; |
+ } |
+ |
+ RefPtr* refptr_; |
+ T* ptr_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Receiver); |
+ }; |
+ |
+ Receiver ReceiveAndAdoptRef() { return Receiver(this); } |
awong
2013/07/17 23:12:59
Add comment saying to not use this as part of a su
danakj
2013/07/17 23:18:46
Good point! Done, with examples.
|
+ |
private: |
T* ptr_; |