Chromium Code Reviews| Index: base/mac/mac_util.mm |
| diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm |
| index 7f3be186daa8c0da82e4b5d58f21b1d70f27d756..98604b4f4bee72a41770014f70d4af225deeda09 100644 |
| --- a/base/mac/mac_util.mm |
| +++ b/base/mac/mac_util.mm |
| @@ -480,5 +480,77 @@ bool WasLaunchedAsHiddenLoginItem() { |
| return IsHiddenLoginItem(item); |
| } |
| +// Definitionsfor the corresponding CF_TO_NS_CAST_DECL macros in mac_util.h. |
|
Avi (use Gerrit)
2011/03/02 22:26:33
drive by: "Definitionsfor" needs a space.
dmac
2011/03/02 22:29:02
Done.
|
| +#define CF_TO_NS_CAST_DEFN(TypeCF, TypeNS) \ |
| +\ |
| +TypeNS* CFToNSCast(TypeCF##Ref cf_val) { \ |
| + DCHECK(!cf_val || TypeCF##GetTypeID() == CFGetTypeID(cf_val)); \ |
| + TypeNS* ns_val = \ |
| + const_cast<TypeNS*>(reinterpret_cast<const TypeNS*>(cf_val)); \ |
| + return ns_val; \ |
| +} \ |
| +\ |
| +TypeCF##Ref NSToCFCast(TypeNS* ns_val) { \ |
| + TypeCF##Ref cf_val = reinterpret_cast<TypeCF##Ref>(ns_val); \ |
| + DCHECK(!cf_val || TypeCF##GetTypeID() == CFGetTypeID(cf_val)); \ |
| + return cf_val; \ |
| +} \ |
| + |
| +#define CF_TO_NS_MUTABLE_CAST_DEFN(name) \ |
| +CF_TO_NS_CAST_DEFN(CF##name, NS##name) \ |
| +\ |
| +NSMutable##name* CFToNSCast(CFMutable##name##Ref cf_val) { \ |
| + DCHECK(!cf_val || CF##name##GetTypeID() == CFGetTypeID(cf_val)); \ |
| + NSMutable##name* ns_val = reinterpret_cast<NSMutable##name*>(cf_val); \ |
| + return ns_val; \ |
| +} \ |
| +\ |
| +CFMutable##name##Ref NSToCFCast(NSMutable##name* ns_val) { \ |
| + CFMutable##name##Ref cf_val = \ |
| + reinterpret_cast<CFMutable##name##Ref>(ns_val); \ |
| + DCHECK(!cf_val || CF##name##GetTypeID() == CFGetTypeID(cf_val)); \ |
| + return cf_val; \ |
| +} \ |
| + |
| +CF_TO_NS_MUTABLE_CAST_DEFN(Array); |
| +CF_TO_NS_MUTABLE_CAST_DEFN(AttributedString); |
| +CF_TO_NS_CAST_DEFN(CFCalendar, NSCalendar); |
| +CF_TO_NS_MUTABLE_CAST_DEFN(CharacterSet); |
| +CF_TO_NS_MUTABLE_CAST_DEFN(Data); |
| +CF_TO_NS_CAST_DEFN(CFDate, NSDate); |
| +CF_TO_NS_MUTABLE_CAST_DEFN(Dictionary); |
| +CF_TO_NS_CAST_DEFN(CFError, NSError); |
| +CF_TO_NS_CAST_DEFN(CFLocale, NSLocale); |
| +CF_TO_NS_CAST_DEFN(CFNumber, NSNumber); |
| +CF_TO_NS_CAST_DEFN(CFRunLoopTimer, NSTimer); |
| +CF_TO_NS_CAST_DEFN(CFTimeZone, NSTimeZone); |
| +CF_TO_NS_MUTABLE_CAST_DEFN(Set); |
| +CF_TO_NS_CAST_DEFN(CFReadStream, NSInputStream); |
| +CF_TO_NS_CAST_DEFN(CFWriteStream, NSOutputStream); |
| +CF_TO_NS_MUTABLE_CAST_DEFN(String); |
| +CF_TO_NS_CAST_DEFN(CFURL, NSURL); |
| + |
| } // namespace mac |
| } // namespace base |
| + |
| +std::ostream& operator<<(std::ostream& o, const CFStringRef string) { |
| + return o << base::SysCFStringRefToUTF8(string); |
| +} |
| + |
| +std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { |
| + base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); |
| + base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info( |
| + CFErrorCopyUserInfo(err)); |
| + CFStringRef errorDesc = NULL; |
| + if (user_info.get()) { |
| + errorDesc = reinterpret_cast<CFStringRef>( |
| + CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
| + } |
| + o << "Code: " << CFErrorGetCode(err) |
| + << " Domain: " << CFErrorGetDomain(err) |
| + << " Desc: " << desc.get(); |
| + if(errorDesc) { |
| + o << "(" << errorDesc << ")"; |
| + } |
| + return o; |
| +} |