Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: base/mac/scoped_cftyperef.h

Issue 3855001: Move scoped_cftyperef from base to base/mac, use the new namespace, and name ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_path.cc ('k') | base/mac_util.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_SCOPED_CFTYPEREF_H_ 5 #ifndef BASE_MAC_SCOPED_CFTYPEREF_H_
6 #define BASE_SCOPED_CFTYPEREF_H_ 6 #define BASE_MAC_SCOPED_CFTYPEREF_H_
7 #pragma once 7 #pragma once
8 8
9 #include <CoreFoundation/CoreFoundation.h> 9 #include <CoreFoundation/CoreFoundation.h>
10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 13
13 // scoped_cftyperef<> is patterned after scoped_ptr<>, but maintains ownership 14 namespace base {
15 namespace mac {
16
17 // ScopedCFTypeRef<> is patterned after scoped_ptr<>, but maintains ownership
14 // of a CoreFoundation object: any object that can be represented as a 18 // of a CoreFoundation object: any object that can be represented as a
15 // CFTypeRef. Style deviations here are solely for compatibility with 19 // CFTypeRef. Style deviations here are solely for compatibility with
16 // scoped_ptr<>'s interface, with which everyone is already familiar. 20 // scoped_ptr<>'s interface, with which everyone is already familiar.
17 // 21 //
18 // When scoped_cftyperef<> takes ownership of an object (in the constructor or 22 // When ScopedCFTypeRef<> takes ownership of an object (in the constructor or
19 // in reset()), it takes over the caller's existing ownership claim. The 23 // in reset()), it takes over the caller's existing ownership claim. The
20 // caller must own the object it gives to scoped_cftyperef<>, and relinquishes 24 // caller must own the object it gives to ScopedCFTypeRef<>, and relinquishes
21 // an ownership claim to that object. scoped_cftyperef<> does not call 25 // an ownership claim to that object. ScopedCFTypeRef<> does not call
22 // CFRetain(). 26 // CFRetain().
23 template<typename CFT> 27 template<typename CFT>
24 class scoped_cftyperef { 28 class ScopedCFTypeRef {
25 public: 29 public:
26 typedef CFT element_type; 30 typedef CFT element_type;
27 31
28 explicit scoped_cftyperef(CFT object = NULL) 32 explicit ScopedCFTypeRef(CFT object = NULL)
29 : object_(object) { 33 : object_(object) {
30 } 34 }
31 35
32 ~scoped_cftyperef() { 36 ~ScopedCFTypeRef() {
33 if (object_) 37 if (object_)
34 CFRelease(object_); 38 CFRelease(object_);
35 } 39 }
36 40
37 void reset(CFT object = NULL) { 41 void reset(CFT object = NULL) {
38 if (object_) 42 if (object_)
39 CFRelease(object_); 43 CFRelease(object_);
40 object_ = object; 44 object_ = object;
41 } 45 }
42 46
(...skipping 24 matching lines...) Expand all
67 // CFRelease(), use scoped_cftyperef<>::reset(). 71 // CFRelease(), use scoped_cftyperef<>::reset().
68 CFT release() WARN_UNUSED_RESULT { 72 CFT release() WARN_UNUSED_RESULT {
69 CFT temp = object_; 73 CFT temp = object_;
70 object_ = NULL; 74 object_ = NULL;
71 return temp; 75 return temp;
72 } 76 }
73 77
74 private: 78 private:
75 CFT object_; 79 CFT object_;
76 80
77 DISALLOW_COPY_AND_ASSIGN(scoped_cftyperef); 81 DISALLOW_COPY_AND_ASSIGN(ScopedCFTypeRef);
78 }; 82 };
79 83
80 #endif // BASE_SCOPED_CFTYPEREF_H_ 84 } // namespace mac
85 } // namespace base
86
87 #endif // BASE_MAC_SCOPED_CFTYPEREF_H_
OLDNEW
« no previous file with comments | « base/file_path.cc ('k') | base/mac_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698