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_IOPLUGININTERFACE_H_
6 #define BASE_MAC_SCOPED_IOPLUGININTERFACE_H_
8 #include <IOKit/IOKitLib.h>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
16 // Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends
17 // (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular).
19 class ScopedIOPluginInterface {
21 typedef T** InterfaceT;
22 typedef InterfaceT element_type;
24 explicit ScopedIOPluginInterface(InterfaceT object = NULL)
28 ~ScopedIOPluginInterface() {
30 (*object_)->Release(object_);
33 void reset(InterfaceT object = NULL) {
35 (*object_)->Release(object_);
39 bool operator==(InterfaceT that) const {
40 return object_ == that;
43 bool operator!=(InterfaceT that) const {
44 return object_ != that;
47 operator InterfaceT() const {
51 InterfaceT get() const {
55 void swap(ScopedIOPluginInterface& that) {
56 InterfaceT temp = that.object_;
57 that.object_ = object_;
61 InterfaceT release() WARN_UNUSED_RESULT {
62 InterfaceT temp = object_;
70 DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface);
76 #endif // BASE_MAC_SCOPED_IOPLUGININTERFACE_H_