OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ | |
6 #define BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ | |
7 | |
8 #include <IOKit/IOKitLib.h> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 | |
13 namespace base { | |
14 namespace mac { | |
15 | |
16 // Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends | |
17 // (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular). | |
18 template<typename T> | |
19 class ScopedIOPluginInterface { | |
20 public: | |
21 typedef T** IFT; | |
Mark Mentovai
2013/04/24 16:57:20
What is IFT supposed to stand for?
CFT, IOT, and
jeremya
2013/04/26 03:47:40
"Interface Type", but I guess I should pick a bett
| |
22 typedef IFT element_type; | |
23 | |
24 explicit ScopedIOPluginInterface(IFT object = NULL) | |
25 : object_(object) { | |
26 } | |
27 | |
28 ~ScopedIOPluginInterface() { | |
29 if (object_) | |
30 (*object_)->Release(object_); | |
31 } | |
32 | |
33 void reset(IFT object = NULL) { | |
34 if (object_) | |
35 (*object_)->Release(object_); | |
36 object_ = object; | |
37 } | |
38 | |
39 bool operator==(IFT that) const { | |
40 return object_ == that; | |
41 } | |
42 | |
43 bool operator!=(IFT that) const { | |
44 return object_ != that; | |
45 } | |
46 | |
47 operator IFT() const { | |
48 return object_; | |
49 } | |
50 | |
51 IFT get() const { | |
52 return object_; | |
53 } | |
54 | |
55 void swap(ScopedIOPluginInterface& that) { | |
56 IFT temp = that.object_; | |
57 that.object_ = object_; | |
58 object_ = temp; | |
59 } | |
60 | |
61 IFT release() WARN_UNUSED_RESULT { | |
62 IFT temp = object_; | |
63 object_ = NULL; | |
64 return temp; | |
65 } | |
66 | |
67 private: | |
68 IFT object_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface); | |
71 }; | |
72 | |
73 } // namespace mac | |
74 } // namespace base | |
75 | |
76 #endif // BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ | |
OLD | NEW |