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

Unified Diff: base/mac/scoped_cftyperef.h

Issue 157063002: Add helpers for CGL types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 10 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
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
« no previous file with comments | « base/base.gypi ('k') | base/mac/scoped_typeref.h » ('j') | base/mac/scoped_typeref.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698