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

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: & cleanup 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..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
« 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