Chromium Code Reviews| Index: base/mac/scoped_ioplugininterface.h |
| diff --git a/base/mac/scoped_ioplugininterface.h b/base/mac/scoped_ioplugininterface.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3233cfac53387efb56cdbdf7d50527a96ae81c0b |
| --- /dev/null |
| +++ b/base/mac/scoped_ioplugininterface.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ |
| +#define BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ |
| + |
| +#include <IOKit/IOKitLib.h> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| + |
| +namespace base { |
| +namespace mac { |
| + |
| +// Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends |
| +// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular). |
| +template<typename T> |
| +class ScopedIOPluginInterface { |
| + public: |
| + 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
|
| + typedef IFT element_type; |
| + |
| + explicit ScopedIOPluginInterface(IFT object = NULL) |
| + : object_(object) { |
| + } |
| + |
| + ~ScopedIOPluginInterface() { |
| + if (object_) |
| + (*object_)->Release(object_); |
| + } |
| + |
| + void reset(IFT object = NULL) { |
| + if (object_) |
| + (*object_)->Release(object_); |
| + object_ = object; |
| + } |
| + |
| + bool operator==(IFT that) const { |
| + return object_ == that; |
| + } |
| + |
| + bool operator!=(IFT that) const { |
| + return object_ != that; |
| + } |
| + |
| + operator IFT() const { |
| + return object_; |
| + } |
| + |
| + IFT get() const { |
| + return object_; |
| + } |
| + |
| + void swap(ScopedIOPluginInterface& that) { |
| + IFT temp = that.object_; |
| + that.object_ = object_; |
| + object_ = temp; |
| + } |
| + |
| + IFT release() WARN_UNUSED_RESULT { |
| + IFT temp = object_; |
| + object_ = NULL; |
| + return temp; |
| + } |
| + |
| + private: |
| + IFT object_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface); |
| +}; |
| + |
| +} // namespace mac |
| +} // namespace base |
| + |
| +#endif // BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ |