41 #if !defined(__CACFArray_h__)
42 #define __CACFArray_h__
49 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
50 #include <CoreAudio/CoreAudioTypes.h>
51 #include <CoreFoundation/CoreFoundation.h>
53 #include <CoreAudioTypes.h>
54 #include <CoreFoundation.h>
57 #include "CADebugMacros.h"
75 CACFArray(
bool inRelease =
true) : mCFArray(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)), mRelease(inRelease), mMutable(true) {}
76 CACFArray(UInt32 inMaxNumberItems,
bool inRelease) : mCFArray(CFArrayCreateMutable(NULL, inMaxNumberItems, &kCFTypeArrayCallBacks)), mRelease(inRelease), mMutable(true) {}
77 CACFArray(CFArrayRef inCFArray,
bool inRelease) : mCFArray(const_cast<CFMutableArrayRef>(inCFArray)), mRelease(inRelease), mMutable(false) {}
78 CACFArray(CFMutableArrayRef inCFArray,
bool inRelease) : mCFArray(inCFArray), mRelease(inRelease), mMutable(true) {}
79 CACFArray(
const CACFArray& inArray) : mCFArray(inArray.mCFArray), mRelease(inArray.mRelease), mMutable(inArray.mMutable) { Retain(); }
80 CACFArray& operator=(
const CACFArray& inArray) { Release(); mCFArray = inArray.mCFArray; mRelease = inArray.mRelease; mMutable = inArray.mMutable; Retain();
return *
this; }
81 CACFArray& operator=(CFArrayRef inCFArray) { Release(); mCFArray =
const_cast<CFMutableArrayRef
>(inCFArray); mMutable =
false; Retain();
return *
this; }
82 CACFArray& operator=(CFMutableArrayRef inCFArray) { Release(); mCFArray = inCFArray; mMutable =
true; Retain();
return *
this; }
83 ~CACFArray() { Release(); }
86 void Retain() {
if(mRelease && (mCFArray != NULL)) { CFRetain(mCFArray); } }
87 void Release() {
if(mRelease && (mCFArray != NULL)) { CFRelease(mCFArray); } }
91 bool IsValid()
const {
return mCFArray != NULL; }
92 bool IsMutable()
const {
return mMutable; }
93 bool CanModify()
const {
return mMutable && (mCFArray != NULL); }
95 bool WillRelease()
const {
return mRelease; }
96 void ShouldRelease(
bool inRelease) { mRelease = inRelease; }
98 CFTypeID GetTypeID()
const {
return CFGetTypeID(mCFArray); }
100 CFArrayRef GetCFArray()
const {
return mCFArray; }
101 CFArrayRef CopyCFArray()
const {
if(mCFArray != NULL) { CFRetain(mCFArray); }
return mCFArray; }
103 CFMutableArrayRef GetCFMutableArray()
const {
return mCFArray; }
104 CFMutableArrayRef CopyCFMutableArray()
const {
if(mCFArray != NULL) { CFRetain(mCFArray); }
return mCFArray; }
105 CFPropertyListRef AsPropertyList()
const {
return mCFArray; }
107 void SetCFMutableArrayFromCopy(CFArrayRef inArray,
bool inRelease =
true) { Release(); mCFArray = CFArrayCreateMutableCopy(NULL, 0, inArray); mMutable =
true; mRelease = inRelease; }
111 UInt32 GetNumberItems()
const { UInt32 theAnswer = 0;
if(mCFArray != NULL) { theAnswer = ToUInt32(CFArrayGetCount(mCFArray)); }
return theAnswer; }
112 bool HasItem(
const void* inItem)
const;
113 void RemoveItem(
const void* inItem) { UInt32 theIndex;
if(CanModify() && GetIndexOfItem(inItem, theIndex)) { RemoveItemAtIndex(theIndex); } }
114 bool GetIndexOfItem(
const void* inItem, UInt32& outIndex)
const;
115 void RemoveItemAtIndex(UInt32 inIndex) {
if(CanModify()) { CFArrayRemoveValueAtIndex(mCFArray, inIndex); } }
116 void Clear() {
if(CanModify()) { CFArrayRemoveAllValues(mCFArray); } }
117 void Sort(CFComparatorFunction inCompareFunction) {
if(CanModify()) { CFRange theRange = { 0, CFArrayGetCount(mCFArray) }; CFArraySortValues(mCFArray, theRange, inCompareFunction, NULL); } }
118 void SortNumbers() { Sort((CFComparatorFunction)CFNumberCompare); }
119 void SortStrings() { Sort((CFComparatorFunction)CFStringCompare); }
121 bool GetBool(UInt32 inIndex,
bool& outValue)
const;
122 bool GetSInt32(UInt32 inIndex, SInt32& outItem)
const;
123 bool GetUInt32(UInt32 inIndex, UInt32& outItem)
const;
124 bool GetSInt64(UInt32 inIndex, SInt64& outItem)
const;
125 bool GetUInt64(UInt32 inIndex, UInt64& outItem)
const;
126 bool GetFloat32(UInt32 inIndex, Float32& outItem)
const;
127 bool GetFloat64(UInt32 inIndex, Float64& outItem)
const;
128 bool GetString(UInt32 inIndex, CFStringRef& outItem)
const;
129 bool GetArray(UInt32 inIndex, CFArrayRef& outItem)
const;
130 bool GetDictionary(UInt32 inIndex, CFDictionaryRef& outItem)
const;
131 bool GetData(UInt32 inIndex, CFDataRef& outItem)
const;
132 bool GetUUID(UInt32 inIndex, CFUUIDRef& outItem)
const;
133 bool GetCFType(UInt32 inIndex, CFTypeRef& outItem)
const;
135 void GetCACFString(UInt32 inIndex, CACFString& outItem)
const;
136 void GetCACFArray(UInt32 inIndex, CACFArray& outItem)
const;
137 void GetCACFDictionary(UInt32 inIndex, CACFDictionary& outItem)
const;
139 bool AppendBool(
bool inItem);
140 bool AppendSInt32(SInt32 inItem);
141 bool AppendUInt32(UInt32 inItem);
142 bool AppendSInt64(SInt64 inItem);
143 bool AppendUInt64(UInt64 inItem);
144 bool AppendFloat32(Float32 inItem);
145 bool AppendFloat64(Float64 inItem);
146 bool AppendString(
const CFStringRef inItem);
147 bool AppendArray(
const CFArrayRef inItem);
148 bool AppendDictionary(
const CFDictionaryRef inItem);
149 bool AppendData(
const CFDataRef inItem);
150 bool AppendCFType(
const CFTypeRef inItem);
152 bool InsertBool(UInt32 inIndex,
bool inItem);
153 bool InsertSInt32(UInt32 inIndex, SInt32 inItem);
154 bool InsertUInt32(UInt32 inIndex, UInt32 inItem);
155 bool InsertSInt64(UInt32 inIndex, SInt64 inItem);
156 bool InsertUInt64(UInt32 inIndex, UInt64 inItem);
157 bool InsertFloat32(UInt32 inIndex, Float32 inItem);
158 bool InsertFloat64(UInt32 inIndex, Float64 inItem);
159 bool InsertString(UInt32 inIndex,
const CFStringRef inItem);
160 bool InsertArray(UInt32 inIndex,
const CFArrayRef inItem);
161 bool InsertDictionary(UInt32 inIndex,
const CFDictionaryRef inItem);
162 bool InsertData(UInt32 inIndex,
const CFDataRef inItem);
163 bool InsertCFType(UInt32 inIndex,
const CFTypeRef inItem);
165 bool SetBool(UInt32 inIndex,
bool inItem);
166 bool SetSInt32(UInt32 inIndex, SInt32 inItem);
167 bool SetUInt32(UInt32 inIndex, UInt32 inItem);
168 bool SetSInt64(UInt32 inIndex, SInt64 inItem);
169 bool SetUInt64(UInt32 inIndex, UInt64 inItem);
170 bool SetFloat32(UInt32 inIndex, Float32 inItem);
171 bool SetFloat64(UInt32 inIndex, Float64 inItem);
172 bool SetString(UInt32 inIndex,
const CFStringRef inItem);
173 bool SetArray(UInt32 inIndex,
const CFArrayRef inItem);
174 bool SetDictionary(UInt32 inIndex,
const CFDictionaryRef inItem);
175 bool SetData(UInt32 inIndex,
const CFDataRef inItem);
176 bool SetCFType(UInt32 inIndex,
const CFTypeRef inItem);
180 CFMutableArrayRef mCFArray;