46 #include "CACFDictionary.h"
49 #include "CACFArray.h"
50 #include "CACFNumber.h"
51 #include "CACFString.h"
57 bool CACFDictionary::HasKey(
const CFStringRef inKey)
const
59 return CFDictionaryContainsKey(mCFDictionary, inKey) != 0;
62 UInt32 CACFDictionary::Size ()
const
64 return ToUInt32(CFDictionaryGetCount(mCFDictionary));
67 void CACFDictionary::GetKeys (
const void **keys)
const
69 CFDictionaryGetKeysAndValues(mCFDictionary, keys, NULL);
72 bool CACFDictionary::GetBool(
const CFStringRef inKey,
bool& outValue)
const
74 bool theAnswer =
false;
76 CFTypeRef theValue = NULL;
77 if(GetCFType(inKey, theValue))
79 if((theValue != NULL) && (CFGetTypeID(theValue) == CFBooleanGetTypeID()))
81 outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue));
84 else if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
86 SInt32 theNumericValue = 0;
87 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue);
88 outValue = theNumericValue != 0;
96 bool CACFDictionary::GetSInt32(
const CFStringRef inKey, SInt32& outValue)
const
98 bool theAnswer =
false;
100 CFTypeRef theValue = NULL;
101 if(GetCFType(inKey, theValue))
103 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
105 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
113 bool CACFDictionary::GetUInt32(
const CFStringRef inKey, UInt32& outValue)
const
115 bool theAnswer =
false;
117 CFTypeRef theValue = NULL;
118 if(GetCFType(inKey, theValue))
120 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
122 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
130 bool CACFDictionary::GetSInt64(
const CFStringRef inKey, SInt64& outValue)
const
132 bool theAnswer =
false;
134 CFTypeRef theValue = NULL;
135 if(GetCFType(inKey, theValue))
137 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
139 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
147 bool CACFDictionary::GetUInt64(
const CFStringRef inKey, UInt64& outValue)
const
149 bool theAnswer =
false;
151 CFTypeRef theValue = NULL;
152 if(GetCFType(inKey, theValue))
154 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
156 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
164 bool CACFDictionary::GetFloat32(
const CFStringRef inKey, Float32& outValue)
const
166 bool theAnswer =
false;
168 CFTypeRef theValue = NULL;
169 if(GetCFType(inKey, theValue))
171 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
173 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat32Type, &outValue);
181 bool CACFDictionary::GetFloat64(
const CFStringRef inKey, Float64& outValue)
const
183 bool theAnswer =
false;
185 CFTypeRef theValue = NULL;
186 if(GetCFType(inKey, theValue))
188 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
190 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat64Type, &outValue);
198 bool CACFDictionary::GetFixed64(
const CFStringRef inKey, Float64& outValue)
const
200 bool theAnswer =
false;
202 CFTypeRef theValue = NULL;
203 if(GetCFType(inKey, theValue))
205 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
207 SInt64 theFixed64 = 0;
208 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &theFixed64);
209 outValue =
static_cast<Float64
>(theFixed64 >> 32);
210 outValue +=
static_cast<Float64
>(theFixed64 & 0x00000000FFFFFFFFLL) / static_cast<Float64>(0x0000000100000000LL);
218 bool CACFDictionary::GetString(
const CFStringRef inKey, CFStringRef& outValue)
const
220 bool theAnswer =
false;
222 CFTypeRef theValue = NULL;
223 if(GetCFType(inKey, theValue))
225 if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
227 outValue =
static_cast<CFStringRef
>(theValue);
235 bool CACFDictionary::GetArray(
const CFStringRef inKey, CFArrayRef& outValue)
const
237 bool theAnswer =
false;
239 CFTypeRef theValue = NULL;
240 if(GetCFType(inKey, theValue))
242 if((theValue != NULL) && (CFGetTypeID(theValue) == CFArrayGetTypeID()))
244 outValue =
static_cast<CFArrayRef
>(theValue);
252 bool CACFDictionary::GetDictionary(
const CFStringRef inKey, CFDictionaryRef& outValue)
const
254 bool theAnswer =
false;
256 CFTypeRef theValue = NULL;
257 if(GetCFType(inKey, theValue))
259 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDictionaryGetTypeID()))
261 outValue =
static_cast<CFDictionaryRef
>(theValue);
269 bool CACFDictionary::GetData(
const CFStringRef inKey, CFDataRef& outValue)
const
271 bool theAnswer =
false;
273 CFTypeRef theValue = NULL;
274 if(GetCFType(inKey, theValue))
276 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDataGetTypeID()))
278 outValue =
static_cast<CFDataRef
>(theValue);
286 bool CACFDictionary::GetCFType(
const CFStringRef inKey, CFTypeRef& outValue)
const
288 bool theAnswer =
false;
290 if(mCFDictionary != NULL)
292 outValue = CFDictionaryGetValue(mCFDictionary, inKey);
293 theAnswer = (outValue != NULL);
299 bool CACFDictionary::GetCFTypeWithCStringKey(
const char* inKey, CFTypeRef& outValue)
const
301 bool theAnswer =
false;
303 if(mCFDictionary != NULL)
305 CACFString theKey(inKey);
308 theAnswer = GetCFType(theKey.GetCFString(), outValue);
315 void CACFDictionary::GetCACFString(
const CFStringRef inKey, CACFString& outValue)
const
317 outValue =
static_cast<CFStringRef
>(NULL);
318 CFTypeRef theValue = NULL;
319 if(GetCFType(inKey, theValue))
321 if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
323 outValue =
static_cast<CFStringRef
>(theValue);
328 void CACFDictionary::GetCACFArray(
const CFStringRef inKey, CACFArray& outValue)
const
330 outValue =
static_cast<CFArrayRef
>(NULL);
331 CFTypeRef theValue = NULL;
332 if(GetCFType(inKey, theValue))
334 if((theValue != NULL) && (CFGetTypeID(theValue) == CFArrayGetTypeID()))
336 outValue =
static_cast<CFArrayRef
>(theValue);
341 void CACFDictionary::GetCACFDictionary(
const CFStringRef inKey, CACFDictionary& outValue)
const
343 outValue =
static_cast<CFDictionaryRef
>(NULL);
344 CFTypeRef theValue = NULL;
345 if(GetCFType(inKey, theValue))
347 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDictionaryGetTypeID()))
349 outValue =
static_cast<CFDictionaryRef
>(theValue);
354 bool CACFDictionary::AddBool(
const CFStringRef inKey,
bool inValue)
356 bool theAnswer =
false;
358 if(mMutable && (mCFDictionary != NULL))
360 CACFBoolean theValue(inValue);
361 theAnswer = AddCFType(inKey, theValue.GetCFBoolean());
367 bool CACFDictionary::AddSInt32(
const CFStringRef inKey, SInt32 inValue)
369 bool theAnswer =
false;
371 if(mMutable && (mCFDictionary != NULL))
373 CACFNumber theValue(inValue);
374 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
380 bool CACFDictionary::AddUInt32(
const CFStringRef inKey, UInt32 inValue)
382 bool theAnswer =
false;
384 if(mMutable && (mCFDictionary != NULL))
386 CACFNumber theValue(inValue);
387 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
393 bool CACFDictionary::AddSInt64(
const CFStringRef inKey, SInt64 inValue)
395 bool theAnswer =
false;
397 if(mMutable && (mCFDictionary != NULL))
399 CACFNumber theValue(inValue);
400 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
406 bool CACFDictionary::AddUInt64(
const CFStringRef inKey, UInt64 inValue)
408 bool theAnswer =
false;
410 if(mMutable && (mCFDictionary != NULL))
412 CACFNumber theValue(inValue);
413 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
419 bool CACFDictionary::AddFloat32(
const CFStringRef inKey, Float32 inValue)
421 bool theAnswer =
false;
423 if(mMutable && (mCFDictionary != NULL))
425 CACFNumber theValue(inValue);
426 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
432 bool CACFDictionary::AddFloat64(
const CFStringRef inKey, Float64 inValue)
434 bool theAnswer =
false;
436 if(mMutable && (mCFDictionary != NULL))
438 CACFNumber theValue(inValue);
439 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
445 bool CACFDictionary::AddNumber(
const CFStringRef inKey,
const CFNumberRef inValue)
447 bool theAnswer =
false;
449 if(mMutable && (mCFDictionary != NULL))
451 theAnswer = AddCFType(inKey, inValue);
457 bool CACFDictionary::AddString(
const CFStringRef inKey,
const CFStringRef inValue)
459 bool theAnswer =
false;
461 if(mMutable && (mCFDictionary != NULL))
463 theAnswer = AddCFType(inKey, inValue);
469 bool CACFDictionary::AddArray(
const CFStringRef inKey,
const CFArrayRef inValue)
471 bool theAnswer =
false;
473 if(mMutable && (mCFDictionary != NULL))
475 theAnswer = AddCFType(inKey, inValue);
481 bool CACFDictionary::AddDictionary(
const CFStringRef inKey,
const CFDictionaryRef inValue)
483 bool theAnswer =
false;
485 if(mMutable && (mCFDictionary != NULL))
487 theAnswer = AddCFType(inKey, inValue);
493 bool CACFDictionary::AddData(
const CFStringRef inKey,
const CFDataRef inValue)
495 bool theAnswer =
false;
497 if(mMutable && (mCFDictionary != NULL))
499 theAnswer = AddCFType(inKey, inValue);
505 bool CACFDictionary::AddCFType(
const CFStringRef inKey,
const CFTypeRef inValue)
507 bool theAnswer =
false;
509 if(mMutable && (mCFDictionary != NULL))
511 CFDictionarySetValue(mCFDictionary, inKey, inValue);
518 bool CACFDictionary::AddURL(
const CFStringRef inKey,
const CFURLRef inValue)
520 bool theAnswer =
false;
522 if(mMutable && (mCFDictionary != NULL))
524 CFDictionarySetValue(mCFDictionary, inKey, inValue);
531 bool CACFDictionary::AddCFTypeWithCStringKey(
const char* inKey,
const CFTypeRef inValue)
533 bool theAnswer =
false;
535 if(mMutable && (mCFDictionary != NULL))
537 CACFString theKey(inKey);
540 theAnswer = AddCFType(theKey.GetCFString(), inValue);
547 bool CACFDictionary::AddCString(
const CFStringRef inKey,
const char* inValue)
549 bool theAnswer =
false;
551 if(mMutable && (mCFDictionary != NULL))
553 CACFString theValue(inValue);
554 if(theValue.IsValid())
556 theAnswer = AddCFType(inKey, theValue.GetCFString());