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

Unified Diff: base/mac/scoped_ioobject.h

Issue 1551943002: Rewrite most of the scopers in //base/mac to use ScopedTypeRef or ScopedGeneric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS Created 5 years 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_ioobject.h
diff --git a/base/mac/scoped_ioobject.h b/base/mac/scoped_ioobject.h
index 7bf8895d2ef05faa60fb983b3f0220d8a21fbf93..c948cb5542340e1a426039100ca77777446b12e8 100644
--- a/base/mac/scoped_ioobject.h
+++ b/base/mac/scoped_ioobject.h
@@ -7,66 +7,28 @@
#include <IOKit/IOKitLib.h>
-#include "base/compiler_specific.h"
-#include "base/macros.h"
+#include "base/mac/scoped_typeref.h"
namespace base {
namespace mac {
-// Just like ScopedCFTypeRef but for io_object_t and subclasses.
-template<typename IOT>
-class ScopedIOObject {
- public:
- typedef IOT element_type;
-
- explicit ScopedIOObject(IOT object = IO_OBJECT_NULL)
- : object_(object) {
- }
-
- ~ScopedIOObject() {
- if (object_)
- IOObjectRelease(object_);
- }
-
- void reset(IOT object = IO_OBJECT_NULL) {
- if (object_)
- IOObjectRelease(object_);
- object_ = object;
- }
-
- bool operator==(IOT that) const {
- return object_ == that;
- }
-
- bool operator!=(IOT that) const {
- return object_ != that;
- }
-
- operator IOT() const {
- return object_;
- }
-
- IOT get() const {
- return object_;
- }
+namespace internal {
- void swap(ScopedIOObject& that) {
- IOT temp = that.object_;
- that.object_ = object_;
- object_ = temp;
- }
-
- IOT release() WARN_UNUSED_RESULT {
- IOT temp = object_;
- object_ = IO_OBJECT_NULL;
- return temp;
+template <typename IOT>
+struct ScopedIOObjectTraits {
+ static IOT InvalidValue() { return IO_OBJECT_NULL; }
+ static IOT Retain(IOT iot) {
+ IOObjectRetain(iot);
+ return iot;
}
+ static void Release(IOT iot) { IOObjectRelease(iot); }
+};
- private:
- IOT object_;
+} // namespce internal
- DISALLOW_COPY_AND_ASSIGN(ScopedIOObject);
-};
+// Just like ScopedCFTypeRef but for io_object_t and subclasses.
+template <typename IOT>
+using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
} // namespace mac
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698