Add ICU message format support
[chromium-blink-merge.git] / base / mac / scoped_ioobject.h
blob854039b5537dd215fa94c66f057512f32fb8d540
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_IOOBJECT_H_
6 #define BASE_MAC_SCOPED_IOOBJECT_H_
8 #include <IOKit/IOKitLib.h>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
13 namespace base {
14 namespace mac {
16 // Just like ScopedCFTypeRef but for io_object_t and subclasses.
17 template<typename IOT>
18 class ScopedIOObject {
19 public:
20 typedef IOT element_type;
22 explicit ScopedIOObject(IOT object = IO_OBJECT_NULL)
23 : object_(object) {
26 ~ScopedIOObject() {
27 if (object_)
28 IOObjectRelease(object_);
31 void reset(IOT object = IO_OBJECT_NULL) {
32 if (object_)
33 IOObjectRelease(object_);
34 object_ = object;
37 bool operator==(IOT that) const {
38 return object_ == that;
41 bool operator!=(IOT that) const {
42 return object_ != that;
45 operator IOT() const {
46 return object_;
49 IOT get() const {
50 return object_;
53 void swap(ScopedIOObject& that) {
54 IOT temp = that.object_;
55 that.object_ = object_;
56 object_ = temp;
59 IOT release() WARN_UNUSED_RESULT {
60 IOT temp = object_;
61 object_ = IO_OBJECT_NULL;
62 return temp;
65 private:
66 IOT object_;
68 DISALLOW_COPY_AND_ASSIGN(ScopedIOObject);
71 } // namespace mac
72 } // namespace base
74 #endif // BASE_MAC_SCOPED_IOOBJECT_H_