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

Unified Diff: base/mac/foundation_util.mm

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 side-by-side diff with in-line comments
Download patch
Index: base/mac/foundation_util.mm
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index 8a4ce471765e1157886e293ae4c7b9007ccc24f7..777836ae9c5eaec094a29dd0c8234923983a4762 100644
--- a/base/mac/foundation_util.mm
+++ b/base/mac/foundation_util.mm
@@ -348,6 +348,41 @@ CF_CAST_DEFN(CFNumber);
CF_CAST_DEFN(CFSet);
CF_CAST_DEFN(CFString);
+#define GET_VAL_FROM_DICT_DEFN(TypeCF) \
+template<> TypeCF##Ref \
+GetValueFromDictionary<TypeCF##Ref>(CFDictionaryRef dict, CFStringRef key) { \
+ CFTypeRef val = CFDictionaryGetValue(dict, key); \
+ TypeCF##Ref value = base::mac::CFCast<TypeCF##Ref>(val); \
+ if (!val) \
+ return value; \
+ if (!value) { \
+ ScopedCFTypeRef<CFStringRef> expected_type_ref( \
+ CFCopyTypeIDDescription(TypeCF##GetTypeID())); \
+ ScopedCFTypeRef<CFStringRef> actual_type_ref( \
+ CFCopyTypeIDDescription(CFGetTypeID(val))); \
+ DLOG(WARNING) << "Expected value for key " \
+ << base::SysCFStringRefToUTF8(key) \
+ << " to be " \
+ << base::SysCFStringRefToUTF8(expected_type_ref) \
+ << " but it was " \
+ << base::SysCFStringRefToUTF8(actual_type_ref) \
+ << " instead"; \
+ return NULL; \
+ } \
+ return value; \
+}
+
+GET_VAL_FROM_DICT_DEFN(CFArray);
+GET_VAL_FROM_DICT_DEFN(CFBag);
+GET_VAL_FROM_DICT_DEFN(CFBoolean);
+GET_VAL_FROM_DICT_DEFN(CFData);
+GET_VAL_FROM_DICT_DEFN(CFDate);
+GET_VAL_FROM_DICT_DEFN(CFDictionary);
+GET_VAL_FROM_DICT_DEFN(CFNull);
+GET_VAL_FROM_DICT_DEFN(CFNumber);
+GET_VAL_FROM_DICT_DEFN(CFSet);
+GET_VAL_FROM_DICT_DEFN(CFString);
+
} // namespace mac
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698