41 #if !defined(__CACFDictionary_h__)
42 #define __CACFDictionary_h__
49 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
50 #include <CoreFoundation/CoreFoundation.h>
52 #include <CoreFoundation.h>
71 CACFDictionary(
bool inRelease =
true) : mCFDictionary(CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)), mRelease(inRelease), mMutable(true) {}
72 CACFDictionary(CFDictionaryRef inCFDictionary,
bool inRelease) : mCFDictionary(const_cast<CFMutableDictionaryRef>(inCFDictionary)), mRelease(inRelease), mMutable(false) {}
73 CACFDictionary(CFMutableDictionaryRef inCFDictionary,
bool inRelease) : mCFDictionary(inCFDictionary), mRelease(inRelease), mMutable(true) {}
74 CACFDictionary(
const CACFDictionary& inDictionary) : mCFDictionary(inDictionary.mCFDictionary), mRelease(inDictionary.mRelease), mMutable(inDictionary.mMutable) { Retain(); }
75 CACFDictionary& operator=(
const CACFDictionary& inDictionary) { Release(); mCFDictionary = inDictionary.mCFDictionary; mRelease = inDictionary.mRelease; mMutable = inDictionary.mMutable; Retain();
return *
this; }
76 CACFDictionary& operator=(CFDictionaryRef inDictionary) { Release(); mCFDictionary =
const_cast<CFMutableDictionaryRef
>(inDictionary); mMutable =
false; Retain();
return *
this; }
77 CACFDictionary& operator=(CFMutableDictionaryRef inDictionary) { Release(); mCFDictionary = inDictionary; mMutable =
true; Retain();
return *
this; }
78 ~CACFDictionary() { Release(); }
81 void Retain() {
if(mRelease && (mCFDictionary != NULL)) { CFRetain(mCFDictionary); } }
82 void Release() {
if(mRelease && (mCFDictionary != NULL)) { CFRelease(mCFDictionary); } }
86 bool IsValid()
const {
return mCFDictionary != NULL; }
87 bool IsMutable()
const {
return mMutable;}
88 bool CanModify()
const {
return mMutable && (mCFDictionary != NULL); }
90 bool WillRelease()
const {
return mRelease; }
91 void ShouldRelease(
bool inRelease) { mRelease = inRelease; }
93 CFDictionaryRef GetDict()
const {
return mCFDictionary; }
94 CFDictionaryRef GetCFDictionary()
const {
return mCFDictionary; }
95 CFDictionaryRef CopyCFDictionary()
const {
if(mCFDictionary != NULL) { CFRetain(mCFDictionary); }
return mCFDictionary; }
97 CFMutableDictionaryRef GetMutableDict() {
return mCFDictionary; }
98 CFMutableDictionaryRef GetCFMutableDictionary()
const {
return mCFDictionary; }
99 CFMutableDictionaryRef CopyCFMutableDictionary()
const {
if(mCFDictionary != NULL) { CFRetain(mCFDictionary); }
return mCFDictionary; }
100 void SetCFMutableDictionaryFromCopy(CFDictionaryRef inDictionary,
bool inRelease =
true) { Release(); mCFDictionary = CFDictionaryCreateMutableCopy(NULL, 0, inDictionary); mMutable =
true; mRelease = inRelease; }
101 void SetCFMutableDictionaryToEmpty(
bool inRelease =
true) { Release(); mCFDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); mMutable =
true; mRelease = inRelease; }
103 CFPropertyListRef AsPropertyList()
const {
return mCFDictionary; }
104 OSStatus GetDictIfMutable(CFMutableDictionaryRef& outDict)
const { OSStatus theAnswer = -1;
if(mMutable) { outDict = mCFDictionary; theAnswer = 0; }
return theAnswer; }
108 bool HasKey(
const CFStringRef inKey)
const;
110 void GetKeys(
const void** keys)
const;
112 bool GetBool(
const CFStringRef inKey,
bool& outValue)
const;
113 bool GetSInt32(
const CFStringRef inKey, SInt32& outValue)
const;
114 bool GetUInt32(
const CFStringRef inKey, UInt32& outValue)
const;
115 bool GetSInt64(
const CFStringRef inKey, SInt64& outValue)
const;
116 bool GetUInt64(
const CFStringRef inKey, UInt64& outValue)
const;
117 bool GetFloat32(
const CFStringRef inKey, Float32& outValue)
const;
118 bool GetFloat64(
const CFStringRef inKey, Float64& outValue)
const;
119 bool GetFixed64(
const CFStringRef inKey, Float64& outValue)
const;
120 bool GetString(
const CFStringRef inKey, CFStringRef& outValue)
const;
121 bool GetArray(
const CFStringRef inKey, CFArrayRef& outValue)
const;
122 bool GetDictionary(
const CFStringRef inKey, CFDictionaryRef& outValue)
const;
123 bool GetData(
const CFStringRef inKey, CFDataRef& outValue)
const;
124 bool GetCFType(
const CFStringRef inKey, CFTypeRef& outValue)
const;
126 bool GetCFTypeWithCStringKey(
const char* inKey, CFTypeRef& outValue)
const;
128 void GetCACFString(
const CFStringRef inKey, CACFString& outItem)
const;
129 void GetCACFArray(
const CFStringRef inKey, CACFArray& outItem)
const;
130 void GetCACFDictionary(
const CFStringRef inKey, CACFDictionary& outItem)
const;
132 bool AddBool(
const CFStringRef inKey,
bool inValue);
133 bool AddSInt32(
const CFStringRef inKey, SInt32 inValue);
134 bool AddUInt32(
const CFStringRef inKey, UInt32 inValue);
135 bool AddSInt64(
const CFStringRef inKey, SInt64 inValue);
136 bool AddUInt64(
const CFStringRef inKey, UInt64 inValue);
137 bool AddFloat32(
const CFStringRef inKey, Float32 inValue);
138 bool AddFloat64(
const CFStringRef inKey, Float64 inValue);
139 bool AddNumber(
const CFStringRef inKey,
const CFNumberRef inValue);
140 bool AddString(
const CFStringRef inKey,
const CFStringRef inValue);
141 bool AddArray(
const CFStringRef inKey,
const CFArrayRef inValue);
142 bool AddDictionary(
const CFStringRef inKey,
const CFDictionaryRef inValue);
143 bool AddData(
const CFStringRef inKey,
const CFDataRef inValue);
144 bool AddCFType(
const CFStringRef inKey,
const CFTypeRef inValue);
145 bool AddURL(
const CFStringRef inKey,
const CFURLRef inValue);
147 bool AddCFTypeWithCStringKey(
const char* inKey,
const CFTypeRef inValue);
148 bool AddCString(
const CFStringRef inKey,
const char* inValue);
150 void RemoveKey(
const CFStringRef inKey) {
if(CanModify()) { CFDictionaryRemoveValue(mCFDictionary, inKey); } }
151 void Clear() {
if(CanModify()) { CFDictionaryRemoveAllValues(mCFDictionary); } }
153 void Show() { CFShow(mCFDictionary); }
157 CFMutableDictionaryRef mCFDictionary;
162 #endif //__CACFDictionary_h__