46 #include "CACFArray.h"
49 #include "CACFDictionary.h"
50 #include "CACFNumber.h"
51 #include "CACFString.h"
57 bool CACFArray::HasItem(
const void* inItem)
const
59 bool theAnswer =
false;
62 CFRange theRange = { 0, CFArrayGetCount(mCFArray)};
63 theAnswer = CFArrayContainsValue(mCFArray, theRange, inItem);
68 bool CACFArray::GetIndexOfItem(
const void* inItem, UInt32& outIndex)
const
70 bool theAnswer =
false;
74 CFRange theRange = { 0, CFArrayGetCount(mCFArray)};
75 CFIndex theIndex = CFArrayGetFirstIndexOfValue(mCFArray, theRange, inItem);
79 outIndex = ToUInt32(theIndex);
85 bool CACFArray::GetBool(UInt32 inIndex,
bool& outValue)
const
87 bool theAnswer =
false;
89 CFTypeRef theValue = NULL;
90 if(GetCFType(inIndex, theValue))
92 if((theValue != NULL) && (CFGetTypeID(theValue) == CFBooleanGetTypeID()))
94 outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue));
97 else if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
99 SInt32 theNumericValue = 0;
100 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue);
101 outValue = theNumericValue != 0;
109 bool CACFArray::GetSInt32(UInt32 inIndex, SInt32& outItem)
const
111 bool theAnswer =
false;
113 CFTypeRef theItem = NULL;
114 if(GetCFType(inIndex, theItem))
116 if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
118 CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt32Type, &outItem);
126 bool CACFArray::GetUInt32(UInt32 inIndex, UInt32& outItem)
const
128 bool theAnswer =
false;
130 CFTypeRef theItem = NULL;
131 if(GetCFType(inIndex, theItem))
133 if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
135 CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt32Type, &outItem);
143 bool CACFArray::GetSInt64(UInt32 inIndex, SInt64& outItem)
const
145 bool theAnswer =
false;
147 CFTypeRef theItem = NULL;
148 if(GetCFType(inIndex, theItem))
150 if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
152 CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt64Type, &outItem);
160 bool CACFArray::GetUInt64(UInt32 inIndex, UInt64& outItem)
const
162 bool theAnswer =
false;
164 CFTypeRef theItem = NULL;
165 if(GetCFType(inIndex, theItem))
167 if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
169 CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt64Type, &outItem);
177 bool CACFArray::GetFloat32(UInt32 inIndex, Float32& outItem)
const
179 bool theAnswer =
false;
181 CFTypeRef theItem = NULL;
182 if(GetCFType(inIndex, theItem))
184 if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
186 CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberFloat32Type, &outItem);
194 bool CACFArray::GetFloat64(UInt32 inIndex, Float64& outItem)
const
196 bool theAnswer =
false;
198 CFTypeRef theItem = NULL;
199 if(GetCFType(inIndex, theItem))
201 if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
203 CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberFloat64Type, &outItem);
211 bool CACFArray::GetString(UInt32 inIndex, CFStringRef& outItem)
const
213 bool theAnswer =
false;
215 CFTypeRef theItem = NULL;
216 if(GetCFType(inIndex, theItem))
218 if((theItem != NULL) && (CFGetTypeID(theItem) == CFStringGetTypeID()))
220 outItem =
static_cast<CFStringRef
>(theItem);
228 bool CACFArray::GetArray(UInt32 inIndex, CFArrayRef& outItem)
const
230 bool theAnswer =
false;
232 CFTypeRef theItem = NULL;
233 if(GetCFType(inIndex, theItem))
235 if((theItem != NULL) && (CFGetTypeID(theItem) == CFArrayGetTypeID()))
237 outItem =
static_cast<CFArrayRef
>(theItem);
245 bool CACFArray::GetDictionary(UInt32 inIndex, CFDictionaryRef& outItem)
const
247 bool theAnswer =
false;
249 CFTypeRef theItem = NULL;
250 if(GetCFType(inIndex, theItem))
252 if((theItem != NULL) && (CFGetTypeID(theItem) == CFDictionaryGetTypeID()))
254 outItem =
static_cast<CFDictionaryRef
>(theItem);
262 bool CACFArray::GetData(UInt32 inIndex, CFDataRef& outItem)
const
264 bool theAnswer =
false;
266 CFTypeRef theItem = NULL;
267 if(GetCFType(inIndex, theItem))
269 if((theItem != NULL) && (CFGetTypeID(theItem) == CFDataGetTypeID()))
271 outItem =
static_cast<CFDataRef
>(theItem);
279 bool CACFArray::GetUUID(UInt32 inIndex, CFUUIDRef& outItem)
const
281 bool theAnswer =
false;
283 CFTypeRef theItem = NULL;
284 if(GetCFType(inIndex, theItem))
286 if((theItem != NULL) && (CFGetTypeID(theItem) == CFUUIDGetTypeID()))
288 outItem =
static_cast<CFUUIDRef
>(theItem);
296 bool CACFArray::GetCFType(UInt32 inIndex, CFTypeRef& outItem)
const
298 bool theAnswer =
false;
300 if((mCFArray != NULL) && (inIndex < GetNumberItems()))
302 outItem = CFArrayGetValueAtIndex(mCFArray, inIndex);
303 theAnswer = outItem != NULL;
309 void CACFArray::GetCACFString(UInt32 inIndex, CACFString& outItem)
const
311 outItem =
static_cast<CFStringRef
>(NULL);
312 CFTypeRef theItem = NULL;
313 if(GetCFType(inIndex, theItem))
315 if((theItem != NULL) && (CFGetTypeID(theItem) == CFStringGetTypeID()))
317 outItem =
static_cast<CFStringRef
>(theItem);
322 void CACFArray::GetCACFArray(UInt32 inIndex, CACFArray& outItem)
const
324 outItem =
static_cast<CFArrayRef
>(NULL);
325 CFTypeRef theItem = NULL;
326 if(GetCFType(inIndex, theItem))
328 if((theItem != NULL) && (CFGetTypeID(theItem) == CFArrayGetTypeID()))
330 outItem =
static_cast<CFArrayRef
>(theItem);
335 void CACFArray::GetCACFDictionary(UInt32 inIndex, CACFDictionary& outItem)
const
337 outItem =
static_cast<CFDictionaryRef
>(NULL);
338 CFTypeRef theItem = NULL;
339 if(GetCFType(inIndex, theItem))
341 if((theItem != NULL) && (CFGetTypeID(theItem) == CFDictionaryGetTypeID()))
343 outItem =
static_cast<CFDictionaryRef
>(theItem);
348 bool CACFArray::AppendBool(
bool inItem)
350 bool theAnswer =
false;
352 if((mCFArray != NULL) && mMutable)
354 CACFBoolean theItem(inItem);
355 if(theItem.IsValid())
357 theAnswer = AppendCFType(theItem.GetCFBoolean());
364 bool CACFArray::AppendSInt32(SInt32 inItem)
366 bool theAnswer =
false;
368 if((mCFArray != NULL) && mMutable)
370 CACFNumber theItem(inItem);
371 if(theItem.IsValid())
373 theAnswer = AppendCFType(theItem.GetCFNumber());
380 bool CACFArray::AppendUInt32(UInt32 inItem)
382 bool theAnswer =
false;
384 if((mCFArray != NULL) && mMutable)
386 CACFNumber theItem(inItem);
387 if(theItem.IsValid())
389 theAnswer = AppendCFType(theItem.GetCFNumber());
396 bool CACFArray::AppendSInt64(SInt64 inItem)
398 bool theAnswer =
false;
400 if((mCFArray != NULL) && mMutable)
402 CACFNumber theItem(inItem);
403 if(theItem.IsValid())
405 theAnswer = AppendCFType(theItem.GetCFNumber());
412 bool CACFArray::AppendUInt64(UInt64 inItem)
414 bool theAnswer =
false;
416 if((mCFArray != NULL) && mMutable)
418 CACFNumber theItem(inItem);
419 if(theItem.IsValid())
421 theAnswer = AppendCFType(theItem.GetCFNumber());
428 bool CACFArray::AppendFloat32(Float32 inItem)
430 bool theAnswer =
false;
432 if((mCFArray != NULL) && mMutable)
434 CACFNumber theItem(inItem);
435 if(theItem.IsValid())
437 theAnswer = AppendCFType(theItem.GetCFNumber());
444 bool CACFArray::AppendFloat64(Float64 inItem)
446 bool theAnswer =
false;
448 if((mCFArray != NULL) && mMutable)
450 CACFNumber theItem(inItem);
451 if(theItem.IsValid())
453 theAnswer = AppendCFType(theItem.GetCFNumber());
460 bool CACFArray::AppendString(
const CFStringRef inItem)
462 return AppendCFType(inItem);
465 bool CACFArray::AppendArray(
const CFArrayRef inItem)
467 return AppendCFType(inItem);
470 bool CACFArray::AppendDictionary(
const CFDictionaryRef inItem)
472 return AppendCFType(inItem);
475 bool CACFArray::AppendData(
const CFDataRef inItem)
477 return AppendCFType(inItem);
480 bool CACFArray::AppendCFType(
const CFTypeRef inItem)
482 bool theAnswer =
false;
484 if((mCFArray != NULL) && mMutable)
486 CFArrayAppendValue(mCFArray, inItem);
493 bool CACFArray::InsertBool(UInt32 inIndex,
bool inItem)
495 bool theAnswer =
false;
497 if((mCFArray != NULL) && mMutable)
499 CACFBoolean theItem(inItem);
500 if(theItem.IsValid())
502 theAnswer = InsertCFType(inIndex, theItem.GetCFBoolean());
509 bool CACFArray::InsertSInt32(UInt32 inIndex, SInt32 inItem)
511 bool theAnswer =
false;
513 if((mCFArray != NULL) && mMutable)
515 CACFNumber theItem(inItem);
516 if(theItem.IsValid())
518 theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
525 bool CACFArray::InsertUInt32(UInt32 inIndex, UInt32 inItem)
527 bool theAnswer =
false;
529 if((mCFArray != NULL) && mMutable)
531 CACFNumber theItem(inItem);
532 if(theItem.IsValid())
534 theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
541 bool CACFArray::InsertSInt64(UInt32 inIndex, SInt64 inItem)
543 bool theAnswer =
false;
545 if((mCFArray != NULL) && mMutable)
547 CACFNumber theItem(inItem);
548 if(theItem.IsValid())
550 theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
557 bool CACFArray::InsertUInt64(UInt32 inIndex, UInt64 inItem)
559 bool theAnswer =
false;
561 if((mCFArray != NULL) && mMutable)
563 CACFNumber theItem(inItem);
564 if(theItem.IsValid())
566 theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
573 bool CACFArray::InsertFloat32(UInt32 inIndex, Float32 inItem)
575 bool theAnswer =
false;
577 if((mCFArray != NULL) && mMutable)
579 CACFNumber theItem(inItem);
580 if(theItem.IsValid())
582 theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
589 bool CACFArray::InsertFloat64(UInt32 inIndex, Float64 inItem)
591 bool theAnswer =
false;
593 if((mCFArray != NULL) && mMutable)
595 CACFNumber theItem(inItem);
596 if(theItem.IsValid())
598 theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
605 bool CACFArray::InsertString(UInt32 inIndex,
const CFStringRef inItem)
607 return InsertCFType(inIndex, inItem);
610 bool CACFArray::InsertArray(UInt32 inIndex,
const CFArrayRef inItem)
612 return InsertCFType(inIndex, inItem);
615 bool CACFArray::InsertDictionary(UInt32 inIndex,
const CFDictionaryRef inItem)
617 return InsertCFType(inIndex, inItem);
620 bool CACFArray::InsertData(UInt32 inIndex,
const CFDataRef inItem)
622 return InsertCFType(inIndex, inItem);
625 bool CACFArray::InsertCFType(UInt32 inIndex,
const CFTypeRef inItem)
627 bool theAnswer =
false;
629 if((mCFArray != NULL) && mMutable)
631 if(inIndex < GetNumberItems())
633 CFArrayInsertValueAtIndex(mCFArray, inIndex, inItem);
637 CFArrayAppendValue(mCFArray, inItem);
645 bool CACFArray::SetBool(UInt32 inIndex,
bool inItem)
647 bool theAnswer =
false;
649 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
651 CACFBoolean theItem(inItem);
652 if(theItem.IsValid())
654 theAnswer = SetCFType(inIndex, theItem.GetCFBoolean());
661 bool CACFArray::SetSInt32(UInt32 inIndex, SInt32 inItem)
663 bool theAnswer =
false;
665 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
667 CACFNumber theItem(inItem);
668 if(theItem.IsValid())
670 theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
677 bool CACFArray::SetUInt32(UInt32 inIndex, UInt32 inItem)
679 bool theAnswer =
false;
681 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
683 CACFNumber theItem(inItem);
684 if(theItem.IsValid())
686 theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
693 bool CACFArray::SetSInt64(UInt32 inIndex, SInt64 inItem)
695 bool theAnswer =
false;
697 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
699 CACFNumber theItem(inItem);
700 if(theItem.IsValid())
702 theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
709 bool CACFArray::SetUInt64(UInt32 inIndex, UInt64 inItem)
711 bool theAnswer =
false;
713 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
715 CACFNumber theItem(inItem);
716 if(theItem.IsValid())
718 theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
725 bool CACFArray::SetFloat32(UInt32 inIndex, Float32 inItem)
727 bool theAnswer =
false;
729 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
731 CACFNumber theItem(inItem);
732 if(theItem.IsValid())
734 theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
741 bool CACFArray::SetFloat64(UInt32 inIndex, Float64 inItem)
743 bool theAnswer =
false;
745 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
747 CACFNumber theItem(inItem);
748 if(theItem.IsValid())
750 theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
757 bool CACFArray::SetString(UInt32 inIndex,
const CFStringRef inItem)
759 return SetCFType(inIndex, inItem);
762 bool CACFArray::SetArray(UInt32 inIndex,
const CFArrayRef inItem)
764 return SetCFType(inIndex, inItem);
767 bool CACFArray::SetDictionary(UInt32 inIndex,
const CFDictionaryRef inItem)
769 return SetCFType(inIndex, inItem);
772 bool CACFArray::SetData(UInt32 inIndex,
const CFDataRef inItem)
774 return SetCFType(inIndex, inItem);
777 bool CACFArray::SetCFType(UInt32 inIndex,
const CFTypeRef inItem)
779 bool theAnswer =
false;
781 if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
783 CFArraySetValueAtIndex(mCFArray, inIndex, inItem);