clang: Suppress a new warning in sqlite.
[chromium-blink-merge.git] / base / mac / scoped_cftyperef.h
blob8567f85ffcdaed1adfe89e6056a6c333089610d2
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_CFTYPEREF_H_
6 #define BASE_MAC_SCOPED_CFTYPEREF_H_
8 #include <CoreFoundation/CoreFoundation.h>
10 #include "base/mac/scoped_typeref.h"
12 namespace base {
14 // ScopedCFTypeRef<> is patterned after scoped_ptr<>, but maintains ownership
15 // of a CoreFoundation object: any object that can be represented as a
16 // CFTypeRef. Style deviations here are solely for compatibility with
17 // scoped_ptr<>'s interface, with which everyone is already familiar.
19 // By default, ScopedCFTypeRef<> takes ownership of an object (in the
20 // constructor or in reset()) by taking over the caller's existing ownership
21 // claim. The caller must own the object it gives to ScopedCFTypeRef<>, and
22 // relinquishes an ownership claim to that object. ScopedCFTypeRef<> does not
23 // call CFRetain(). This behavior is parameterized by the |OwnershipPolicy|
24 // enum. If the value |RETAIN| is passed (in the constructor or in reset()),
25 // then ScopedCFTypeRef<> will call CFRetain() on the object, and the initial
26 // ownership is not changed.
28 namespace internal {
30 struct ScopedCFTypeRefTraits {
31 static void Retain(CFTypeRef object) {
32 CFRetain(object);
34 static void Release(CFTypeRef object) {
35 CFRelease(object);
39 } // namespace internal
41 template<typename CFT>
42 class ScopedCFTypeRef
43 : public ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits> {
44 public:
45 typedef CFT element_type;
47 explicit ScopedCFTypeRef(
48 CFT object = NULL,
49 base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
50 : ScopedTypeRef<CFT,
51 internal::ScopedCFTypeRefTraits>(object, policy) {}
53 ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that)
54 : ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits>(that) {}
57 } // namespace base
59 #endif // BASE_MAC_SCOPED_CFTYPEREF_H_