1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_MAC_SCOPED_IOOBJECT_H_
6 #define BASE_MAC_SCOPED_IOOBJECT_H_
8 #include <IOKit/IOKitLib.h>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
16 // Just like ScopedCFTypeRef but for io_object_t and subclasses.
17 template<typename IOT>
18 class ScopedIOObject {
20 typedef IOT element_type;
22 explicit ScopedIOObject(IOT object = IO_OBJECT_NULL)
28 IOObjectRelease(object_);
31 void reset(IOT object = IO_OBJECT_NULL) {
33 IOObjectRelease(object_);
37 bool operator==(IOT that) const {
38 return object_ == that;
41 bool operator!=(IOT that) const {
42 return object_ != that;
45 operator IOT() const {
53 void swap(ScopedIOObject& that) {
54 IOT temp = that.object_;
55 that.object_ = object_;
59 IOT release() WARN_UNUSED_RESULT {
61 object_ = IO_OBJECT_NULL;
68 DISALLOW_COPY_AND_ASSIGN(ScopedIOObject);
74 #endif // BASE_MAC_SCOPED_IOOBJECT_H_