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 /*=============================================================================
41 =============================================================================*/
42 #if !defined(__CACFDictionary_h__)
43 #define __CACFDictionary_h__
45 //=============================================================================
47 //=============================================================================
50 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
51 #include <CoreFoundation/CoreFoundation.h>
53 #include <CoreFoundation.h>
56 //=============================================================================
58 //=============================================================================
63 // Construction/Destruction
65 CACFDictionary(bool inRelease
) : mCFDictionary(CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
)), mRelease(inRelease
), mMutable(true) {}
66 CACFDictionary(const CFDictionaryRef inCFDictionary
, bool inRelease
) : mCFDictionary(const_cast<CFMutableDictionaryRef
>(inCFDictionary
)), mRelease(inRelease
), mMutable(true) {}
67 CACFDictionary(const CFMutableDictionaryRef inCFDictionary
, bool inRelease
) : mCFDictionary(inCFDictionary
), mRelease(inRelease
), mMutable(true) {}
68 CACFDictionary(const CACFDictionary
& inDictionary
) : mCFDictionary(inDictionary
.mCFDictionary
), mRelease(inDictionary
.mRelease
), mMutable(inDictionary
.mMutable
) { if(mRelease
&& (mCFDictionary
!= NULL
)) { CFRetain(mCFDictionary
); } }
69 CACFDictionary
& operator=(const CACFDictionary
& inDictionary
) { mCFDictionary
= inDictionary
.mCFDictionary
; mRelease
= inDictionary
.mRelease
; mMutable
= inDictionary
.mMutable
; if(mRelease
&& (mCFDictionary
!= NULL
)) { CFRetain(mCFDictionary
); } return *this; }
70 ~CACFDictionary() { if(mRelease
&& (mCFDictionary
!= NULL
)) { CFRelease(mCFDictionary
); } }
74 bool IsValid() const { return mCFDictionary
!= NULL
; }
75 bool IsMutable() const { return mMutable
;}
76 bool CanModify() const { return mMutable
&& (mCFDictionary
!= NULL
); }
78 bool WillRelease() const { return mRelease
; }
79 void ShouldRelease(bool inRelease
) { mRelease
= inRelease
; }
81 CFDictionaryRef
GetDict() const { return mCFDictionary
; }
82 CFDictionaryRef
GetCFDictionary() const { return mCFDictionary
; }
83 CFDictionaryRef
CopyCFDictionary() const { if(mCFDictionary
!= NULL
) { CFRetain(mCFDictionary
); } return mCFDictionary
; }
85 CFMutableDictionaryRef
GetMutableDict() { return mCFDictionary
; }
86 CFMutableDictionaryRef
GetCFMutableDictionary() const { return mCFDictionary
; }
87 CFMutableDictionaryRef
CopyCFMutableDictionary() const { if(mCFDictionary
!= NULL
) { CFRetain(mCFDictionary
); } return mCFDictionary
; }
88 void SetCFMutableDictionaryFromCopy(CFDictionaryRef inDictionary
, bool inRelease
= true) { if(mRelease
&& (mCFDictionary
!= NULL
)) { CFRelease(mCFDictionary
); } mCFDictionary
= CFDictionaryCreateMutableCopy(NULL
, 0, inDictionary
); mMutable
= true; mRelease
= inRelease
; }
90 CFPropertyListRef
AsPropertyList() const { return mCFDictionary
; }
91 OSStatus
GetDictIfMutable(CFMutableDictionaryRef
& outDict
) const { OSStatus theAnswer
= -1; if(mMutable
) { outDict
= mCFDictionary
; theAnswer
= 0; } return theAnswer
; }
95 bool HasKey(const CFStringRef inKey
) const;
97 void GetKeys(const void** keys
) const;
99 bool GetBool(const CFStringRef inKey
, bool& outValue
) const;
100 bool GetSInt32(const CFStringRef inKey
, SInt32
& outValue
) const;
101 bool GetUInt32(const CFStringRef inKey
, UInt32
& outValue
) const;
102 bool GetSInt64(const CFStringRef inKey
, SInt64
& outValue
) const;
103 bool GetUInt64(const CFStringRef inKey
, UInt64
& outValue
) const;
104 bool GetFloat32(const CFStringRef inKey
, Float32
& outValue
) const;
105 bool GetFloat64(const CFStringRef inKey
, Float64
& outValue
) const;
106 bool GetString(const CFStringRef inKey
, CFStringRef
& outValue
) const;
107 bool GetArray(const CFStringRef inKey
, CFArrayRef
& outValue
) const;
108 bool GetDictionary(const CFStringRef inKey
, CFDictionaryRef
& outValue
) const;
109 bool GetData(const CFStringRef inKey
, CFDataRef
& outValue
) const;
110 bool GetCFType(const CFStringRef inKey
, CFTypeRef
& outValue
) const;
112 bool GetCFTypeWithCStringKey(const char* inKey
, CFTypeRef
& outValue
) const;
114 bool AddSInt32(const CFStringRef inKey
, SInt32 inValue
);
115 bool AddUInt32(const CFStringRef inKey
, UInt32 inValue
);
116 bool AddSInt64(const CFStringRef inKey
, SInt64 inValue
);
117 bool AddUInt64(const CFStringRef inKey
, UInt64 inValue
);
118 bool AddFloat32(const CFStringRef inKey
, Float32 inValue
);
119 bool AddFloat64(const CFStringRef inKey
, Float64 inValue
);
120 bool AddNumber(const CFStringRef inKey
, const CFNumberRef inValue
);
121 bool AddString(const CFStringRef inKey
, const CFStringRef inValue
);
122 bool AddArray(const CFStringRef inKey
, const CFArrayRef inValue
);
123 bool AddDictionary(const CFStringRef inKey
, const CFDictionaryRef inValue
);
124 bool AddData(const CFStringRef inKey
, const CFDataRef inValue
);
125 bool AddCFType(const CFStringRef inKey
, const CFTypeRef inValue
);
127 bool AddCFTypeWithCStringKey(const char* inKey
, const CFTypeRef inValue
);
128 bool AddCString(const CFStringRef inKey
, const char* inValue
);
130 void Clear() { if(CanModify()) { CFDictionaryRemoveAllValues(mCFDictionary
); } }
132 void Show() { CFShow(mCFDictionary
); }
136 CFMutableDictionaryRef mCFDictionary
;
141 #endif //__CACFDictionary_h__