From 7a801dab5e105a7debcbc982e1b00a2e01e4e0e2 Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Fri, 23 Mar 2012 18:17:33 +0000 Subject: 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 --- base/base.gypi | 1 + base/mac/scoped_ioobject.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 base/mac/scoped_ioobject.h (limited to 'base') 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 + +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +namespace base { +namespace mac { + +// Just like ScopedCFTypeRef but for io_object_t and subclasses. +template +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_ -- cgit v1.1