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

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

Issue 8540021: Create a nicer interface for base::mac::GetValueFromDictionary (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: move header definition to be in similar place as body def Created 9 years, 1 month 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/mac/foundation_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_MAC_FOUNDATION_UTIL_H_ 5 #ifndef BASE_MAC_FOUNDATION_UTIL_H_
6 #define BASE_MAC_FOUNDATION_UTIL_H_ 6 #define BASE_MAC_FOUNDATION_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <CoreFoundation/CoreFoundation.h> 9 #include <CoreFoundation/CoreFoundation.h>
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // |exec_name| - path to the binary 95 // |exec_name| - path to the binary
96 // returns - path to the application bundle, or empty on error 96 // returns - path to the application bundle, or empty on error
97 BASE_EXPORT FilePath GetAppBundlePath(const FilePath& exec_name); 97 BASE_EXPORT FilePath GetAppBundlePath(const FilePath& exec_name);
98 98
99 // Utility function to pull out a value from a dictionary, check its type, and 99 // Utility function to pull out a value from a dictionary, check its type, and
100 // return it. Returns NULL if the key is not present or of the wrong type. 100 // return it. Returns NULL if the key is not present or of the wrong type.
101 BASE_EXPORT CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, 101 BASE_EXPORT CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
102 CFStringRef key, 102 CFStringRef key,
103 CFTypeID expected_type); 103 CFTypeID expected_type);
104 104
105 // Utility function to pull out a value from a dictionary, check its type, and
106 // return it. Returns NULL if the key is not present or of the wrong type.
107 BASE_EXPORT template<class T>
108 T GetValueFromDictionary(CFDictionaryRef dict, CFStringRef key);
Nico 2011/11/11 23:08:36 I don't understand why this is a template function
KushalP 2011/11/11 23:13:35 I would've thought the template function is a clea
109
105 // Retain/release calls for memory management in C++. 110 // Retain/release calls for memory management in C++.
106 BASE_EXPORT void NSObjectRetain(void* obj); 111 BASE_EXPORT void NSObjectRetain(void* obj);
107 BASE_EXPORT void NSObjectRelease(void* obj); 112 BASE_EXPORT void NSObjectRelease(void* obj);
108 113
109 // CFTypeRefToNSObjectAutorelease transfers ownership of a Core Foundation 114 // CFTypeRefToNSObjectAutorelease transfers ownership of a Core Foundation
110 // object (one derived from CFTypeRef) to the Foundation memory management 115 // object (one derived from CFTypeRef) to the Foundation memory management
111 // system. In a traditional managed-memory environment, cf_object is 116 // system. In a traditional managed-memory environment, cf_object is
112 // autoreleased and returned as an NSObject. In a garbage-collected 117 // autoreleased and returned as an NSObject. In a garbage-collected
113 // environment, cf_object is marked as eligible for garbage collection. 118 // environment, cf_object is marked as eligible for garbage collection.
114 // 119 //
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 263
259 BASE_EXPORT template<class T> 264 BASE_EXPORT template<class T>
260 T* ObjCCastStrict(id objc_val) { 265 T* ObjCCastStrict(id objc_val) {
261 T* rv = ObjCCast<T>(objc_val); 266 T* rv = ObjCCast<T>(objc_val);
262 DCHECK(objc_val == nil || rv); 267 DCHECK(objc_val == nil || rv);
263 return rv; 268 return rv;
264 } 269 }
265 270
266 #endif // defined(__OBJC__) 271 #endif // defined(__OBJC__)
267 272
273 // Utility function to pull out a value from a dictionary, check its type, and
274 // return it. Returns NULL if the key is not present or of the wrong type.
275 // Is a cleaner implementation of base::mac::GetValueFromDictionary() above.
276 BASE_EXPORT template<class T>
277 T GetValueFromDictionary(CFDictionaryRef dict, CFStringRef key);
278
268 } // namespace mac 279 } // namespace mac
269 } // namespace base 280 } // namespace base
270 281
271 // Stream operations for CFTypes. They can be used with NSTypes as well 282 // Stream operations for CFTypes. They can be used with NSTypes as well
272 // by using the NSToCFCast methods above. 283 // by using the NSToCFCast methods above.
273 // e.g. LOG(INFO) << base::mac::NSToCFCast(@"foo"); 284 // e.g. LOG(INFO) << base::mac::NSToCFCast(@"foo");
274 // Operator << can not be overloaded for ObjectiveC types as the compiler 285 // Operator << can not be overloaded for ObjectiveC types as the compiler
275 // can not distinguish between overloads for id with overloads for void*. 286 // can not distinguish between overloads for id with overloads for void*.
276 BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, 287 BASE_EXPORT extern std::ostream& operator<<(std::ostream& o,
277 const CFErrorRef err); 288 const CFErrorRef err);
278 BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, 289 BASE_EXPORT extern std::ostream& operator<<(std::ostream& o,
279 const CFStringRef str); 290 const CFStringRef str);
280 291
281 #endif // BASE_MAC_FOUNDATION_UTIL_H_ 292 #endif // BASE_MAC_FOUNDATION_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/mac/foundation_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698