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

Side by Side Diff: base/scoped_cftyperef.h

Issue 52018: Improve scoped_cftyperef<> and scoped_nsobject<> reset() semantics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 9 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 | « no previous file | base/scoped_nsobject.h » ('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) 2006-2008 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_SCOPED_CFTYPEREF_H_
6 #define BASE_SCOPED_CFTYPEREF_H_ 6 #define BASE_SCOPED_CFTYPEREF_H_
7 7
8 #include <CoreFoundation/CoreFoundation.h> 8 #include <CoreFoundation/CoreFoundation.h>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 10
11 // scoped_cftyperef<> is patterned after scoped_ptr<>, but maintains ownership 11 // scoped_cftyperef<> is patterned after scoped_ptr<>, but maintains ownership
12 // of a CoreFoundation object: any object that can be represented as a 12 // of a CoreFoundation object: any object that can be represented as a
13 // CFTypeRef. Style deviations here are solely for compatibility with 13 // CFTypeRef. Style deviations here are solely for compatibility with
14 // scoped_ptr<>'s interface, with which everyone is already familiar. 14 // scoped_ptr<>'s interface, with which everyone is already familiar.
15 // 15 //
16 // When scoped_cftyperef<> takes ownership of an object (in the constructor or 16 // When scoped_cftyperef<> takes ownership of an object (in the constructor or
17 // in reset()), it takes over the caller's existing ownership claim. The 17 // in reset()), it takes over the caller's existing ownership claim. The
18 // caller must own the object. scoped_cftyperef<> does not call CFRetain(). 18 // caller must own the object it gives to scoped_cftyperef<>, and relinquishes
19 // an ownership claim to that object. scoped_cftyperef<> does not call
20 // CFRetain().
19 template<typename CFT> 21 template<typename CFT>
20 class scoped_cftyperef { 22 class scoped_cftyperef {
21 public: 23 public:
22 typedef CFT element_type; 24 typedef CFT element_type;
23 25
24 explicit scoped_cftyperef(CFT object = NULL) 26 explicit scoped_cftyperef(CFT object = NULL)
25 : object_(object) { 27 : object_(object) {
26 } 28 }
27 29
28 ~scoped_cftyperef() { 30 ~scoped_cftyperef() {
29 if (object_) 31 if (object_)
30 CFRelease(object_); 32 CFRelease(object_);
31 } 33 }
32 34
33 void reset(CFT object = NULL) { 35 void reset(CFT object = NULL) {
34 if (object_ != object) { 36 if (object_)
TVL 2009/03/23 17:30:22 part of me thinks it's better to match the other s
35 if (object_) 37 CFRelease(object_);
36 CFRelease(object_); 38 object_ = object;
37 object_ = object;
38 }
39 } 39 }
40 40
41 bool operator==(CFT that) const { 41 bool operator==(CFT that) const {
42 return object_ == that; 42 return object_ == that;
43 } 43 }
44 44
45 bool operator!=(CFT that) const { 45 bool operator!=(CFT that) const {
46 return object_ != that; 46 return object_ != that;
47 } 47 }
48 48
(...skipping 20 matching lines...) Expand all
69 return temp; 69 return temp;
70 } 70 }
71 71
72 private: 72 private:
73 CFT object_; 73 CFT object_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(scoped_cftyperef); 75 DISALLOW_COPY_AND_ASSIGN(scoped_cftyperef);
76 }; 76 };
77 77
78 #endif // BASE_SCOPED_CFTYPEREF_H_ 78 #endif // BASE_SCOPED_CFTYPEREF_H_
OLDNEW
« no previous file with comments | « no previous file | base/scoped_nsobject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698