1 // Copyright 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_CFFILEDESCRIPTORREF_H_
6 #define BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_
8 #include <CoreFoundation/CoreFoundation.h>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
16 // ScopedCFFileDescriptorRef is designed after ScopedCFTypeRef<>. On
17 // destruction, it will invalidate the file descriptor.
18 // ScopedCFFileDescriptorRef (unlike ScopedCFTypeRef<>) does not support RETAIN
19 // semantics, copying, or assignment, as doing so would increase the chances
20 // that a file descriptor is invalidated while still in use.
21 class ScopedCFFileDescriptorRef
{
23 explicit ScopedCFFileDescriptorRef(CFFileDescriptorRef fdref
= NULL
)
27 ~ScopedCFFileDescriptorRef() {
29 CFFileDescriptorInvalidate(fdref_
);
34 void reset(CFFileDescriptorRef fdref
= NULL
) {
38 CFFileDescriptorInvalidate(fdref_
);
44 bool operator==(CFFileDescriptorRef that
) const {
45 return fdref_
== that
;
48 bool operator!=(CFFileDescriptorRef that
) const {
49 return fdref_
!= that
;
52 operator CFFileDescriptorRef() const {
56 CFFileDescriptorRef
get() const {
60 CFFileDescriptorRef
release() WARN_UNUSED_RESULT
{
61 CFFileDescriptorRef temp
= fdref_
;
67 CFFileDescriptorRef fdref_
;
69 DISALLOW_COPY_AND_ASSIGN(ScopedCFFileDescriptorRef
);
75 #endif // BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_