diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 18:17:33 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 18:17:33 +0000 |
commit | 7a801dab5e105a7debcbc982e1b00a2e01e4e0e2 (patch) | |
tree | 521a31a82b106b66c6403d762b94a1fa8d833efc /base | |
parent | d3d6b274c90b4e0c6ddb2ddb2b7f011eeb917fb8 (diff) | |
download | chromium_src-7a801dab5e105a7debcbc982e1b00a2e01e4e0e2.zip chromium_src-7a801dab5e105a7debcbc982e1b00a2e01e4e0e2.tar.gz chromium_src-7a801dab5e105a7debcbc982e1b00a2e01e4e0e2.tar.bz2 |
Move ScopedIOObject to base/mac.
That way, it can be used in rlz.
BUG=none
TEST=none
TBR=mark (who said "LG" instead of "LGTM")
Review URL: https://chromiumcodereview.appspot.com/9839058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128533 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/mac/scoped_ioobject.h | 75 |
2 files changed, 76 insertions, 0 deletions
diff --git a/base/base.gypi b/base/base.gypi index e2423e5..bca1c09 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -168,6 +168,7 @@ 'mac/scoped_aedesc.h', 'mac/scoped_authorizationref.h', 'mac/scoped_cftyperef.h', + 'mac/scoped_ioobject.h', 'mac/scoped_nsautorelease_pool.h', 'mac/scoped_nsautorelease_pool.mm', 'mac/scoped_nsexception_enabler.h', diff --git a/base/mac/scoped_ioobject.h b/base/mac/scoped_ioobject.h new file mode 100644 index 0000000..d5cb90c --- /dev/null +++ b/base/mac/scoped_ioobject.h @@ -0,0 +1,75 @@ +// Copyright (c) 2011 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_IOOBJECT_H_ +#define BASE_MAC_SCOPED_IOOBJECT_H_ +#pragma once + +#include <IOKit/IOKitLib.h> + +#include "base/basictypes.h" +#include "base/compiler_specific.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 = NULL) + : object_(object) { + } + + ~ScopedIOObject() { + if (object_) + IOObjectRelease(object_); + } + + void reset(IOT 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_; + } + + void swap(ScopedIOObject& that) { + IOT temp = that.object_; + that.object_ = object_; + object_ = temp; + } + + IOT release() WARN_UNUSED_RESULT { + IOT temp = object_; + object_ = NULL; + return temp; + } + + private: + IOT object_; + + DISALLOW_COPY_AND_ASSIGN(ScopedIOObject); +}; + +} // namespace mac +} // namespace base + +#endif // BASE_MAC_SCOPED_IOOBJECT_H_ |