when tabbing between track/bus name fields, skip rec-enabled tracks to avoid an annoy...
[ardour2.git] / libs / appleutility / CACFDictionary.cpp
blobc209b5fc36c5fe873452cdefcfc9253c704cb85e
1 /* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
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.
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.
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.
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.
38 /*=============================================================================
39 CACFDictionary.cpp
40 CAAudioEngine
42 =============================================================================*/
44 //=============================================================================
45 // Includes
46 //=============================================================================
48 // Self Include
49 #include "CACFDictionary.h"
51 // PublicUtility Includes
52 #include "CACFString.h"
53 #include "CACFNumber.h"
55 //=============================================================================
56 // CACFDictionary
57 //=============================================================================
59 bool CACFDictionary::HasKey(const CFStringRef inKey) const
61 return CFDictionaryContainsKey(mCFDictionary, inKey) != 0;
64 UInt32 CACFDictionary::Size () const
66 return CFDictionaryGetCount(mCFDictionary);
69 void CACFDictionary::GetKeys (const void **keys) const
71 CFDictionaryGetKeysAndValues(mCFDictionary, keys, NULL);
74 bool CACFDictionary::GetBool(const CFStringRef inKey, bool& outValue) const
76 bool theAnswer = false;
78 CFTypeRef theValue = NULL;
79 if(GetCFType(inKey, theValue))
81 if((theValue != NULL) && (CFGetTypeID(theValue) == CFBooleanGetTypeID()))
83 outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue));
84 theAnswer = true;
86 else if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
88 SInt32 theNumericValue = 0;
89 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue);
90 outValue = theNumericValue != 0;
91 theAnswer = true;
95 return theAnswer;
98 bool CACFDictionary::GetSInt32(const CFStringRef inKey, SInt32& outValue) const
100 bool theAnswer = false;
102 CFTypeRef theValue = NULL;
103 if(GetCFType(inKey, theValue))
105 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
107 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
108 theAnswer = true;
112 return theAnswer;
115 bool CACFDictionary::GetUInt32(const CFStringRef inKey, UInt32& outValue) const
117 bool theAnswer = false;
119 CFTypeRef theValue = NULL;
120 if(GetCFType(inKey, theValue))
122 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
124 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
125 theAnswer = true;
129 return theAnswer;
132 bool CACFDictionary::GetSInt64(const CFStringRef inKey, SInt64& outValue) const
134 bool theAnswer = false;
136 CFTypeRef theValue = NULL;
137 if(GetCFType(inKey, theValue))
139 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
141 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
142 theAnswer = true;
146 return theAnswer;
149 bool CACFDictionary::GetUInt64(const CFStringRef inKey, UInt64& outValue) const
151 bool theAnswer = false;
153 CFTypeRef theValue = NULL;
154 if(GetCFType(inKey, theValue))
156 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
158 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
159 theAnswer = true;
163 return theAnswer;
166 bool CACFDictionary::GetFloat32(const CFStringRef inKey, Float32& outValue) const
168 bool theAnswer = false;
170 CFTypeRef theValue = NULL;
171 if(GetCFType(inKey, theValue))
173 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
175 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat32Type, &outValue);
176 theAnswer = true;
180 return theAnswer;
183 bool CACFDictionary::GetFloat64(const CFStringRef inKey, Float64& outValue) const
185 bool theAnswer = false;
187 CFTypeRef theValue = NULL;
188 if(GetCFType(inKey, theValue))
190 if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
192 CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat64Type, &outValue);
193 theAnswer = true;
197 return theAnswer;
200 bool CACFDictionary::GetString(const CFStringRef inKey, CFStringRef& outValue) const
202 bool theAnswer = false;
204 CFTypeRef theValue = NULL;
205 if(GetCFType(inKey, theValue))
207 if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
209 outValue = static_cast<CFStringRef>(theValue);
210 theAnswer = true;
214 return theAnswer;
217 bool CACFDictionary::GetArray(const CFStringRef inKey, CFArrayRef& outValue) const
219 bool theAnswer = false;
221 CFTypeRef theValue = NULL;
222 if(GetCFType(inKey, theValue))
224 if((theValue != NULL) && (CFGetTypeID(theValue) == CFArrayGetTypeID()))
226 outValue = static_cast<CFArrayRef>(theValue);
227 theAnswer = true;
231 return theAnswer;
234 bool CACFDictionary::GetDictionary(const CFStringRef inKey, CFDictionaryRef& outValue) const
236 bool theAnswer = false;
238 CFTypeRef theValue = NULL;
239 if(GetCFType(inKey, theValue))
241 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDictionaryGetTypeID()))
243 outValue = static_cast<CFDictionaryRef>(theValue);
244 theAnswer = true;
248 return theAnswer;
251 bool CACFDictionary::GetData(const CFStringRef inKey, CFDataRef& outValue) const
253 bool theAnswer = false;
255 CFTypeRef theValue = NULL;
256 if(GetCFType(inKey, theValue))
258 if((theValue != NULL) && (CFGetTypeID(theValue) == CFDataGetTypeID()))
260 outValue = static_cast<CFDataRef>(theValue);
261 theAnswer = true;
265 return theAnswer;
268 bool CACFDictionary::GetCFType(const CFStringRef inKey, CFTypeRef& outValue) const
270 bool theAnswer = false;
272 if(mCFDictionary != NULL)
274 outValue = CFDictionaryGetValue(mCFDictionary, inKey);
275 theAnswer = (outValue != NULL);
278 return theAnswer;
281 bool CACFDictionary::GetCFTypeWithCStringKey(const char* inKey, CFTypeRef& outValue) const
283 bool theAnswer = false;
285 if(mCFDictionary != NULL)
287 CACFString theKey(inKey);
288 if(theKey.IsValid())
290 theAnswer = GetCFType(theKey.GetCFString(), outValue);
294 return theAnswer;
297 bool CACFDictionary::AddSInt32(const CFStringRef inKey, SInt32 inValue)
299 bool theAnswer = false;
301 if(mMutable && (mCFDictionary != NULL))
303 CACFNumber theValue(inValue);
304 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
307 return theAnswer;
310 bool CACFDictionary::AddUInt32(const CFStringRef inKey, UInt32 inValue)
312 bool theAnswer = false;
314 if(mMutable && (mCFDictionary != NULL))
316 CACFNumber theValue(inValue);
317 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
320 return theAnswer;
323 bool CACFDictionary::AddSInt64(const CFStringRef inKey, SInt64 inValue)
325 bool theAnswer = false;
327 if(mMutable && (mCFDictionary != NULL))
329 CACFNumber theValue(inValue);
330 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
333 return theAnswer;
336 bool CACFDictionary::AddUInt64(const CFStringRef inKey, UInt64 inValue)
338 bool theAnswer = false;
340 if(mMutable && (mCFDictionary != NULL))
342 CACFNumber theValue(inValue);
343 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
346 return theAnswer;
349 bool CACFDictionary::AddFloat32(const CFStringRef inKey, Float32 inValue)
351 bool theAnswer = false;
353 if(mMutable && (mCFDictionary != NULL))
355 CACFNumber theValue(inValue);
356 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
359 return theAnswer;
362 bool CACFDictionary::AddFloat64(const CFStringRef inKey, Float64 inValue)
364 bool theAnswer = false;
366 if(mMutable && (mCFDictionary != NULL))
368 CACFNumber theValue(inValue);
369 theAnswer = AddCFType(inKey, theValue.GetCFNumber());
372 return theAnswer;
375 bool CACFDictionary::AddNumber(const CFStringRef inKey, const CFNumberRef inValue)
377 bool theAnswer = false;
379 if(mMutable && (mCFDictionary != NULL))
381 theAnswer = AddCFType(inKey, inValue);
384 return theAnswer;
387 bool CACFDictionary::AddString(const CFStringRef inKey, const CFStringRef inValue)
389 bool theAnswer = false;
391 if(mMutable && (mCFDictionary != NULL))
393 theAnswer = AddCFType(inKey, inValue);
396 return theAnswer;
399 bool CACFDictionary::AddArray(const CFStringRef inKey, const CFArrayRef inValue)
401 bool theAnswer = false;
403 if(mMutable && (mCFDictionary != NULL))
405 theAnswer = AddCFType(inKey, inValue);
408 return theAnswer;
411 bool CACFDictionary::AddDictionary(const CFStringRef inKey, const CFDictionaryRef inValue)
413 bool theAnswer = false;
415 if(mMutable && (mCFDictionary != NULL))
417 theAnswer = AddCFType(inKey, inValue);
420 return theAnswer;
423 bool CACFDictionary::AddData(const CFStringRef inKey, const CFDataRef inValue)
425 bool theAnswer = false;
427 if(mMutable && (mCFDictionary != NULL))
429 theAnswer = AddCFType(inKey, inValue);
432 return theAnswer;
435 bool CACFDictionary::AddCFType(const CFStringRef inKey, const CFTypeRef inValue)
437 bool theAnswer = false;
439 if(mMutable && (mCFDictionary != NULL))
441 CFDictionarySetValue(mCFDictionary, inKey, inValue);
442 theAnswer = true;
445 return theAnswer;
448 bool CACFDictionary::AddCFTypeWithCStringKey(const char* inKey, const CFTypeRef inValue)
450 bool theAnswer = false;
452 if(mMutable && (mCFDictionary != NULL))
454 CACFString theKey(inKey);
455 if(theKey.IsValid())
457 theAnswer = AddCFType(theKey.GetCFString(), inValue);
461 return theAnswer;
464 bool CACFDictionary::AddCString(const CFStringRef inKey, const char* inValue)
466 bool theAnswer = false;
468 if(mMutable && (mCFDictionary != NULL))
470 CACFString theValue(inValue);
471 if(theValue.IsValid())
473 theAnswer = AddCFType(inKey, theValue.GetCFString());
477 return theAnswer;