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 |