OLD | NEW |
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 it gives to scoped_cftyperef<>, and relinquishes | 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 | 19 // an ownership claim to that object. scoped_cftyperef<> does not call |
20 // CFRetain(). | 20 // CFRetain(). |
21 template<typename CFT> | 21 template<typename CFT> |
22 class scoped_cftyperef { | 22 class scoped_cftyperef { |
23 public: | 23 public: |
24 typedef CFT element_type; | 24 typedef CFT element_type; |
25 | 25 |
26 explicit scoped_cftyperef(CFT object = NULL) | 26 explicit scoped_cftyperef(CFT object = NULL) |
27 : object_(object) { | 27 : object_(object) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_ |
OLD | NEW |