Index: base/mac/scoped_cftyperef.h |
diff --git a/base/mac/scoped_cftyperef.h b/base/mac/scoped_cftyperef.h |
index c41de80d8052fa1dcb0dad978a6e696981c8e0aa..28b25004b93c9e26cbba8da506ab6ebb0d5e1b9f 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,30 @@ namespace base { |
// ownership is not changed. |
template<typename CFT> |
Mark Mentovai
2014/02/07 19:53:40
No need to templatize this at all, since you’re sp
ccameron
2014/02/07 20:58:04
Done.
|
-class ScopedCFTypeRef { |
+struct ScopedCFTypeRefTraits { |
+ static void Retain(CFT object) { |
+ CFRetain(object); |
+ } |
+ static void Release(CFT object) { |
+ CFRelease(object); |
+ } |
+}; |
+ |
+template<typename CFT> |
+class ScopedCFTypeRef |
+ : public ScopedTypeRef<CFT, ScopedCFTypeRefTraits<CFT> > { |
Mark Mentovai
2014/02/07 19:53:40
I think we only ever build with C++11 language sup
Avi (use Gerrit)
2014/02/07 19:59:23
Does the compiler we use for iOS support C++11? Th
ccameron
2014/02/07 20:58:04
Changed (a different instance) to >> -- if the iOS
|
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, ScopedCFTypeRefTraits<CFT> >(object, policy) {} |
ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that) |
- : object_(that.object_) { |
- if (object_) |
- CFRetain(object_); |
- } |
- |
- ~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; |
- } |
+ : ScopedTypeRef<CFT, ScopedCFTypeRefTraits<CFT> >(that) {} |
- private: |
- CFT object_; |
+ virtual ~ScopedCFTypeRef() {} |
Mark Mentovai
2014/02/07 19:53:40
Why is this virtual?
ccameron
2014/02/07 20:58:04
Removed (was here for style, not correctness).
|
}; |
} // namespace base |