diff options
Diffstat (limited to 'chromium/base/mac/scoped_cftyperef.h')
-rw-r--r-- | chromium/base/mac/scoped_cftyperef.h | 85 |
1 files changed, 19 insertions, 66 deletions
diff --git a/chromium/base/mac/scoped_cftyperef.h b/chromium/base/mac/scoped_cftyperef.h index c41de80d805..8567f85ffcd 100644 --- a/chromium/base/mac/scoped_cftyperef.h +++ b/chromium/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 { @@ -27,78 +25,33 @@ namespace base { // then ScopedCFTypeRef<> will call CFRetain() on the object, and the initial // ownership is not changed. +namespace internal { + +struct ScopedCFTypeRefTraits { + static void Retain(CFTypeRef object) { + CFRetain(object); + } + static void Release(CFTypeRef object) { + CFRelease(object); + } +}; + +} // namespace internal + template<typename CFT> -class ScopedCFTypeRef { +class ScopedCFTypeRef + : public ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits> { 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, + internal::ScopedCFTypeRefTraits>(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; - } - - private: - CFT object_; + : ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits>(that) {} }; } // namespace base |