Index: base/mac/scoped_cftyperef.h |
diff --git a/base/mac/scoped_cftyperef.h b/base/mac/scoped_cftyperef.h |
index c41de80d8052fa1dcb0dad978a6e696981c8e0aa..d45259c0f4d6cb4d47b33589eb6ee5cd52ea6154 100644 |
--- a/base/mac/scoped_cftyperef.h |
+++ b/base/mac/scoped_cftyperef.h |
@@ -7,9 +7,7 @@ |
#include <CoreFoundation/CoreFoundation.h> |
-#include "base/basictypes.h" |
-#include "base/compiler_specific.h" |
-#include "base/memory/scoped_policy.h" |
+#include "base/mac/scoped_typeref.h" |
namespace base { |
@@ -28,77 +26,20 @@ namespace base { |
// ownership is not changed. |
template<typename CFT> |
-class ScopedCFTypeRef { |
+class ScopedCFTypeRef |
+ : public ScopedTypeRef<CFT, CFTypeRef, CFRetain, CFRelease> { |
Mark Mentovai
2014/02/07 17:22:08
4 spaces, not 2.
ccameron
2014/02/07 19:23:57
Done.
|
public: |
typedef CFT element_type; |
explicit ScopedCFTypeRef( |
CFT object = NULL, |
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) |
- : object_(object) { |
- if (object_ && policy == base::scoped_policy::RETAIN) |
- CFRetain(object_); |
- } |
+ : ScopedTypeRef<CFT, CFTypeRef, CFRetain, CFRelease>(object, policy) {} |
ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that) |
- : object_(that.object_) { |
- if (object_) |
- CFRetain(object_); |
- } |
+ : ScopedTypeRef<CFT, CFTypeRef, CFRetain, CFRelease>(that) {} |
- ~ScopedCFTypeRef() { |
- if (object_) |
- CFRelease(object_); |
- } |
- |
- ScopedCFTypeRef& operator=(const ScopedCFTypeRef<CFT>& that) { |
- reset(that.get(), base::scoped_policy::RETAIN); |
- return *this; |
- } |
- |
- void reset(CFT object = NULL, |
- base::scoped_policy::OwnershipPolicy policy = |
- base::scoped_policy::ASSUME) { |
- if (object && policy == base::scoped_policy::RETAIN) |
- CFRetain(object); |
- if (object_) |
- CFRelease(object_); |
- object_ = object; |
- } |
- |
- bool operator==(CFT that) const { |
- return object_ == that; |
- } |
- |
- bool operator!=(CFT that) const { |
- return object_ != that; |
- } |
- |
- operator CFT() const { |
- return object_; |
- } |
- |
- CFT get() const { |
- return object_; |
- } |
- |
- void swap(ScopedCFTypeRef& that) { |
- CFT temp = that.object_; |
- that.object_ = object_; |
- object_ = temp; |
- } |
- |
- // ScopedCFTypeRef<>::release() is like scoped_ptr<>::release. It is NOT |
- // a wrapper for CFRelease(). To force a ScopedCFTypeRef<> object to call |
- // CFRelease(), use ScopedCFTypeRef<>::reset(). |
- CFT release() WARN_UNUSED_RESULT { |
- CFT temp = object_; |
- object_ = NULL; |
- return temp; |
- } |
- |
- private: |
- CFT object_; |
+ virtual ~ScopedCFTypeRef() {} |
}; |
} // namespace base |