Clarify stop-at-session-end behaviour; should fix #4033.
[ardour.git] / libs / appleutility / CACFDictionary.cpp
1 /*      Copyright:      � Copyright 2005 Apple Computer, Inc. All rights reserved.
2
3         Disclaimer:     IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
4                         ("Apple") in consideration of your agreement to the following terms, and your
5                         use, installation, modification or redistribution of this Apple software
6                         constitutes acceptance of these terms.  If you do not agree with these terms,
7                         please do not use, install, modify or redistribute this Apple software.
8
9                         In consideration of your agreement to abide by the following terms, and subject
10                         to these terms, Apple grants you a personal, non-exclusive license, under Apple�s
11                         copyrights in this original Apple software (the "Apple Software"), to use,
12                         reproduce, modify and redistribute the Apple Software, with or without
13                         modifications, in source and/or binary forms; provided that if you redistribute
14                         the Apple Software in its entirety and without modifications, you must retain
15                         this notice and the following text and disclaimers in all such redistributions of
16                         the Apple Software.  Neither the name, trademarks, service marks or logos of
17                         Apple Computer, Inc. may be used to endorse or promote products derived from the
18                         Apple Software without specific prior written permission from Apple.  Except as
19                         expressly stated in this notice, no other rights or licenses, express or implied,
20                         are granted by Apple herein, including but not limited to any patent rights that
21                         may be infringed by your derivative works or by other works in which the Apple
22                         Software may be incorporated.
23
24                         The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
25                         WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
26                         WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27                         PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
28                         COMBINATION WITH YOUR PRODUCTS.
29
30                         IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
31                         CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32                         GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33                         ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
34                         OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
35                         (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
36                         ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /*=============================================================================
39         CACFDictionary.cpp
40         CAAudioEngine
41
42 =============================================================================*/
43
44 //=============================================================================
45 //      Includes
46 //=============================================================================
47
48 //      Self Include
49 #include "CACFDictionary.h"
50
51 //      PublicUtility Includes
52 #include "CACFString.h"
53 #include "CACFNumber.h"
54
55 //=============================================================================
56 //      CACFDictionary
57 //=============================================================================
58
59 bool    CACFDictionary::HasKey(const CFStringRef inKey) const
60 {
61         return CFDictionaryContainsKey(mCFDictionary, inKey) != 0;
62 }
63
64 UInt32  CACFDictionary::Size () const
65 {
66         return CFDictionaryGetCount(mCFDictionary);
67 }
68
69 void    CACFDictionary::GetKeys (const void **keys) const
70 {
71         CFDictionaryGetKeysAndValues(mCFDictionary, keys, NULL);
72 }
73
74 bool    CACFDictionary::GetBool(const CFStringRef inKey, bool& outValue) const
75 {
76         bool theAnswer = false;
77         
78         CFTypeRef theValue = NULL;
79         if(GetCFType(inKey, theValue))
80         {
81                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFBooleanGetTypeID()))
82                 {
83                         outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue));
84                         theAnswer = true;
85                 }
86                 else if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
87                 {
88                         SInt32 theNumericValue = 0;
89                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue);
90                         outValue = theNumericValue != 0;
91                         theAnswer = true;
92                 }
93         }
94         
95         return theAnswer;
96 }
97
98 bool    CACFDictionary::GetSInt32(const CFStringRef inKey, SInt32& outValue) const
99 {
100         bool theAnswer = false;
101         
102         CFTypeRef theValue = NULL;
103         if(GetCFType(inKey, theValue))
104         {
105                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
106                 {
107                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
108                         theAnswer = true;
109                 }
110         }
111         
112         return theAnswer;
113 }
114
115 bool    CACFDictionary::GetUInt32(const CFStringRef inKey, UInt32& outValue) const
116 {
117         bool theAnswer = false;
118         
119         CFTypeRef theValue = NULL;
120         if(GetCFType(inKey, theValue))
121         {
122                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
123                 {
124                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
125                         theAnswer = true;
126                 }
127         }
128         
129         return theAnswer;
130 }
131
132 bool    CACFDictionary::GetSInt64(const CFStringRef inKey, SInt64& outValue) const
133 {
134         bool theAnswer = false;
135         
136         CFTypeRef theValue = NULL;
137         if(GetCFType(inKey, theValue))
138         {
139                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
140                 {
141                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
142                         theAnswer = true;
143                 }
144         }
145         
146         return theAnswer;
147 }
148
149 bool    CACFDictionary::GetUInt64(const CFStringRef inKey, UInt64& outValue) const
150 {
151         bool theAnswer = false;
152         
153         CFTypeRef theValue = NULL;
154         if(GetCFType(inKey, theValue))
155         {
156                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
157                 {
158                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
159                         theAnswer = true;
160                 }
161         }
162         
163         return theAnswer;
164 }
165
166 bool    CACFDictionary::GetFloat32(const CFStringRef inKey, Float32& outValue) const
167 {
168         bool theAnswer = false;
169         
170         CFTypeRef theValue = NULL;
171         if(GetCFType(inKey, theValue))
172         {
173                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
174                 {
175                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat32Type, &outValue);
176                         theAnswer = true;
177                 }
178         }
179         
180         return theAnswer;
181 }
182
183 bool    CACFDictionary::GetFloat64(const CFStringRef inKey, Float64& outValue) const
184 {
185         bool theAnswer = false;
186         
187         CFTypeRef theValue = NULL;
188         if(GetCFType(inKey, theValue))
189         {
190                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
191                 {
192                         CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat64Type, &outValue);
193                         theAnswer = true;
194                 }
195         }
196         
197         return theAnswer;
198 }
199
200 bool    CACFDictionary::GetString(const CFStringRef inKey, CFStringRef& outValue) const
201 {
202         bool theAnswer = false;
203         
204         CFTypeRef theValue = NULL;
205         if(GetCFType(inKey, theValue))
206         {
207                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
208                 {
209                         outValue = static_cast<CFStringRef>(theValue);
210                         theAnswer = true;
211                 }
212         }
213         
214         return theAnswer;
215 }
216         
217 bool    CACFDictionary::GetArray(const CFStringRef inKey, CFArrayRef& outValue) const
218 {
219         bool theAnswer = false;
220         
221         CFTypeRef theValue = NULL;
222         if(GetCFType(inKey, theValue))
223         {
224                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFArrayGetTypeID()))
225                 {
226                         outValue = static_cast<CFArrayRef>(theValue);
227                         theAnswer = true;
228                 }
229         }
230         
231         return theAnswer;
232 }
233         
234 bool    CACFDictionary::GetDictionary(const CFStringRef inKey, CFDictionaryRef& outValue) const
235 {
236         bool theAnswer = false;
237         
238         CFTypeRef theValue = NULL;
239         if(GetCFType(inKey, theValue))
240         {
241                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDictionaryGetTypeID()))
242                 {
243                         outValue = static_cast<CFDictionaryRef>(theValue);
244                         theAnswer = true;
245                 }
246         }
247         
248         return theAnswer;
249 }
250
251 bool    CACFDictionary::GetData(const CFStringRef inKey, CFDataRef& outValue) const
252 {
253         bool theAnswer = false;
254         
255         CFTypeRef theValue = NULL;
256         if(GetCFType(inKey, theValue))
257         {
258                 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDataGetTypeID()))
259                 {
260                         outValue = static_cast<CFDataRef>(theValue);
261                         theAnswer = true;
262                 }
263         }
264         
265         return theAnswer;
266 }
267
268 bool    CACFDictionary::GetCFType(const CFStringRef inKey, CFTypeRef& outValue) const
269 {
270         bool theAnswer = false;
271         
272         if(mCFDictionary != NULL)
273         {
274                 outValue = CFDictionaryGetValue(mCFDictionary, inKey);
275                 theAnswer = (outValue != NULL);
276         }
277         
278         return theAnswer;
279 }
280
281 bool    CACFDictionary::GetCFTypeWithCStringKey(const char* inKey, CFTypeRef& outValue) const
282 {
283         bool theAnswer = false;
284         
285         if(mCFDictionary != NULL)
286         {
287                 CACFString theKey(inKey);
288                 if(theKey.IsValid())
289                 {
290                         theAnswer = GetCFType(theKey.GetCFString(), outValue);
291                 }
292         }
293         
294         return theAnswer;
295 }
296
297 bool    CACFDictionary::AddSInt32(const CFStringRef inKey, SInt32 inValue)
298 {
299         bool theAnswer = false;
300         
301         if(mMutable && (mCFDictionary != NULL))
302         {
303                 CACFNumber theValue(inValue);
304                 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
305         }
306         
307         return theAnswer;
308 }
309
310 bool    CACFDictionary::AddUInt32(const CFStringRef inKey, UInt32 inValue)
311 {
312         bool theAnswer = false;
313         
314         if(mMutable && (mCFDictionary != NULL))
315         {
316                 CACFNumber theValue(inValue);
317                 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
318         }
319         
320         return theAnswer;
321 }
322
323 bool    CACFDictionary::AddSInt64(const CFStringRef inKey, SInt64 inValue)
324 {
325         bool theAnswer = false;
326         
327         if(mMutable && (mCFDictionary != NULL))
328         {
329                 CACFNumber theValue(inValue);
330                 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
331         }
332         
333         return theAnswer;
334 }
335
336 bool    CACFDictionary::AddUInt64(const CFStringRef inKey, UInt64 inValue)
337 {
338         bool theAnswer = false;
339         
340         if(mMutable && (mCFDictionary != NULL))
341         {
342                 CACFNumber theValue(inValue);
343                 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
344         }
345         
346         return theAnswer;
347 }
348
349 bool    CACFDictionary::AddFloat32(const CFStringRef inKey, Float32 inValue)
350 {
351         bool theAnswer = false;
352         
353         if(mMutable && (mCFDictionary != NULL))
354         {
355                 CACFNumber theValue(inValue);
356                 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
357         }
358         
359         return theAnswer;
360 }
361
362 bool    CACFDictionary::AddFloat64(const CFStringRef inKey, Float64 inValue)
363 {
364         bool theAnswer = false;
365         
366         if(mMutable && (mCFDictionary != NULL))
367         {
368                 CACFNumber theValue(inValue);
369                 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
370         }
371         
372         return theAnswer;
373 }
374
375 bool    CACFDictionary::AddNumber(const CFStringRef inKey, const CFNumberRef inValue)
376 {
377         bool theAnswer = false;
378         
379         if(mMutable && (mCFDictionary != NULL))
380         {
381                 theAnswer = AddCFType(inKey, inValue);
382         }
383         
384         return theAnswer;
385 }
386
387 bool    CACFDictionary::AddString(const CFStringRef inKey, const CFStringRef inValue)
388 {
389         bool theAnswer = false;
390         
391         if(mMutable && (mCFDictionary != NULL))
392         {
393                 theAnswer = AddCFType(inKey, inValue);
394         }
395         
396         return theAnswer;
397 }
398
399 bool    CACFDictionary::AddArray(const CFStringRef inKey, const CFArrayRef inValue)
400 {
401         bool theAnswer = false;
402         
403         if(mMutable && (mCFDictionary != NULL))
404         {
405                 theAnswer = AddCFType(inKey, inValue);
406         }
407         
408         return theAnswer;
409 }
410
411 bool    CACFDictionary::AddDictionary(const CFStringRef inKey, const CFDictionaryRef inValue)
412 {
413         bool theAnswer = false;
414         
415         if(mMutable && (mCFDictionary != NULL))
416         {
417                 theAnswer = AddCFType(inKey, inValue);
418         }
419         
420         return theAnswer;
421 }
422
423 bool    CACFDictionary::AddData(const CFStringRef inKey, const CFDataRef inValue)
424 {
425         bool theAnswer = false;
426         
427         if(mMutable && (mCFDictionary != NULL))
428         {
429                 theAnswer = AddCFType(inKey, inValue);
430         }
431         
432         return theAnswer;
433 }
434
435 bool    CACFDictionary::AddCFType(const CFStringRef inKey, const CFTypeRef inValue)
436 {
437         bool theAnswer = false;
438         
439         if(mMutable && (mCFDictionary != NULL))
440         {
441                 CFDictionarySetValue(mCFDictionary, inKey, inValue);
442                 theAnswer = true;
443         }
444         
445         return theAnswer;
446 }
447
448 bool    CACFDictionary::AddCFTypeWithCStringKey(const char* inKey, const CFTypeRef inValue)
449 {
450         bool theAnswer = false;
451         
452         if(mMutable && (mCFDictionary != NULL))
453         {
454                 CACFString theKey(inKey);
455                 if(theKey.IsValid())
456                 {
457                         theAnswer = AddCFType(theKey.GetCFString(), inValue);
458                 }
459         }
460         
461         return theAnswer;
462 }
463
464 bool    CACFDictionary::AddCString(const CFStringRef inKey, const char* inValue)
465 {
466         bool theAnswer = false;
467         
468         if(mMutable && (mCFDictionary != NULL))
469         {
470                 CACFString theValue(inValue);
471                 if(theValue.IsValid())
472                 {
473                         theAnswer = AddCFType(inKey, theValue.GetCFString());
474                 }
475         }
476         
477         return theAnswer;
478 }