1dda28197Spatrick //===-- CFCMutableDictionary.cpp ------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick
9061da546Spatrick #include "CFCMutableDictionary.h"
10061da546Spatrick #include "CFCString.h"
11061da546Spatrick // CFCString constructor
CFCMutableDictionary(CFMutableDictionaryRef s)12061da546Spatrick CFCMutableDictionary::CFCMutableDictionary(CFMutableDictionaryRef s)
13061da546Spatrick : CFCReleaser<CFMutableDictionaryRef>(s) {}
14061da546Spatrick
15061da546Spatrick // CFCMutableDictionary copy constructor
16*f6aab3d8Srobert CFCMutableDictionary::CFCMutableDictionary(const CFCMutableDictionary &rhs) =
17*f6aab3d8Srobert default;
18061da546Spatrick
19061da546Spatrick // CFCMutableDictionary copy constructor
20061da546Spatrick const CFCMutableDictionary &CFCMutableDictionary::
operator =(const CFCMutableDictionary & rhs)21061da546Spatrick operator=(const CFCMutableDictionary &rhs) {
22061da546Spatrick if (this != &rhs)
23061da546Spatrick *this = rhs;
24061da546Spatrick return *this;
25061da546Spatrick }
26061da546Spatrick
27061da546Spatrick // Destructor
28be691f3bSpatrick CFCMutableDictionary::~CFCMutableDictionary() = default;
29061da546Spatrick
GetCount() const30061da546Spatrick CFIndex CFCMutableDictionary::GetCount() const {
31061da546Spatrick CFMutableDictionaryRef dict = get();
32061da546Spatrick if (dict)
33061da546Spatrick return ::CFDictionaryGetCount(dict);
34061da546Spatrick return 0;
35061da546Spatrick }
36061da546Spatrick
GetCountOfKey(const void * key) const37061da546Spatrick CFIndex CFCMutableDictionary::GetCountOfKey(const void *key) const
38061da546Spatrick
39061da546Spatrick {
40061da546Spatrick CFMutableDictionaryRef dict = get();
41061da546Spatrick if (dict)
42061da546Spatrick return ::CFDictionaryGetCountOfKey(dict, key);
43061da546Spatrick return 0;
44061da546Spatrick }
45061da546Spatrick
GetCountOfValue(const void * value) const46061da546Spatrick CFIndex CFCMutableDictionary::GetCountOfValue(const void *value) const
47061da546Spatrick
48061da546Spatrick {
49061da546Spatrick CFMutableDictionaryRef dict = get();
50061da546Spatrick if (dict)
51061da546Spatrick return ::CFDictionaryGetCountOfValue(dict, value);
52061da546Spatrick return 0;
53061da546Spatrick }
54061da546Spatrick
GetKeysAndValues(const void ** keys,const void ** values) const55061da546Spatrick void CFCMutableDictionary::GetKeysAndValues(const void **keys,
56061da546Spatrick const void **values) const {
57061da546Spatrick CFMutableDictionaryRef dict = get();
58061da546Spatrick if (dict)
59061da546Spatrick ::CFDictionaryGetKeysAndValues(dict, keys, values);
60061da546Spatrick }
61061da546Spatrick
GetValue(const void * key) const62061da546Spatrick const void *CFCMutableDictionary::GetValue(const void *key) const
63061da546Spatrick
64061da546Spatrick {
65061da546Spatrick CFMutableDictionaryRef dict = get();
66061da546Spatrick if (dict)
67061da546Spatrick return ::CFDictionaryGetValue(dict, key);
68061da546Spatrick return NULL;
69061da546Spatrick }
70061da546Spatrick
71061da546Spatrick Boolean
GetValueIfPresent(const void * key,const void ** value_handle) const72061da546Spatrick CFCMutableDictionary::GetValueIfPresent(const void *key,
73061da546Spatrick const void **value_handle) const {
74061da546Spatrick CFMutableDictionaryRef dict = get();
75061da546Spatrick if (dict)
76061da546Spatrick return ::CFDictionaryGetValueIfPresent(dict, key, value_handle);
77061da546Spatrick return false;
78061da546Spatrick }
79061da546Spatrick
Dictionary(bool can_create)80061da546Spatrick CFMutableDictionaryRef CFCMutableDictionary::Dictionary(bool can_create) {
81061da546Spatrick CFMutableDictionaryRef dict = get();
82061da546Spatrick if (can_create && dict == NULL) {
83061da546Spatrick dict = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
84061da546Spatrick &kCFTypeDictionaryKeyCallBacks,
85061da546Spatrick &kCFTypeDictionaryValueCallBacks);
86061da546Spatrick reset(dict);
87061da546Spatrick }
88061da546Spatrick return dict;
89061da546Spatrick }
90061da546Spatrick
AddValue(CFStringRef key,const void * value,bool can_create)91061da546Spatrick bool CFCMutableDictionary::AddValue(CFStringRef key, const void *value,
92061da546Spatrick bool can_create) {
93061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
94061da546Spatrick if (dict != NULL) {
95061da546Spatrick // Let the dictionary own the CFNumber
96061da546Spatrick ::CFDictionaryAddValue(dict, key, value);
97061da546Spatrick return true;
98061da546Spatrick }
99061da546Spatrick return false;
100061da546Spatrick }
101061da546Spatrick
SetValue(CFStringRef key,const void * value,bool can_create)102061da546Spatrick bool CFCMutableDictionary::SetValue(CFStringRef key, const void *value,
103061da546Spatrick bool can_create) {
104061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
105061da546Spatrick if (dict != NULL) {
106061da546Spatrick // Let the dictionary own the CFNumber
107061da546Spatrick ::CFDictionarySetValue(dict, key, value);
108061da546Spatrick return true;
109061da546Spatrick }
110061da546Spatrick return false;
111061da546Spatrick }
112061da546Spatrick
AddValueSInt8(CFStringRef key,int8_t value,bool can_create)113061da546Spatrick bool CFCMutableDictionary::AddValueSInt8(CFStringRef key, int8_t value,
114061da546Spatrick bool can_create) {
115061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
116061da546Spatrick if (dict != NULL) {
117061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
118061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &value));
119061da546Spatrick if (cf_number.get()) {
120061da546Spatrick // Let the dictionary own the CFNumber
121061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
122061da546Spatrick return true;
123061da546Spatrick }
124061da546Spatrick }
125061da546Spatrick return false;
126061da546Spatrick }
127061da546Spatrick
SetValueSInt8(CFStringRef key,int8_t value,bool can_create)128061da546Spatrick bool CFCMutableDictionary::SetValueSInt8(CFStringRef key, int8_t value,
129061da546Spatrick bool can_create) {
130061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
131061da546Spatrick if (dict != NULL) {
132061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
133061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &value));
134061da546Spatrick if (cf_number.get()) {
135061da546Spatrick // Let the dictionary own the CFNumber
136061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
137061da546Spatrick return true;
138061da546Spatrick }
139061da546Spatrick }
140061da546Spatrick return false;
141061da546Spatrick }
142061da546Spatrick
AddValueSInt16(CFStringRef key,int16_t value,bool can_create)143061da546Spatrick bool CFCMutableDictionary::AddValueSInt16(CFStringRef key, int16_t value,
144061da546Spatrick bool can_create) {
145061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
146061da546Spatrick if (dict != NULL) {
147061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
148061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &value));
149061da546Spatrick if (cf_number.get()) {
150061da546Spatrick // Let the dictionary own the CFNumber
151061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
152061da546Spatrick return true;
153061da546Spatrick }
154061da546Spatrick }
155061da546Spatrick return false;
156061da546Spatrick }
157061da546Spatrick
SetValueSInt16(CFStringRef key,int16_t value,bool can_create)158061da546Spatrick bool CFCMutableDictionary::SetValueSInt16(CFStringRef key, int16_t value,
159061da546Spatrick bool can_create) {
160061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
161061da546Spatrick if (dict != NULL) {
162061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
163061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &value));
164061da546Spatrick if (cf_number.get()) {
165061da546Spatrick // Let the dictionary own the CFNumber
166061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
167061da546Spatrick return true;
168061da546Spatrick }
169061da546Spatrick }
170061da546Spatrick return false;
171061da546Spatrick }
172061da546Spatrick
AddValueSInt32(CFStringRef key,int32_t value,bool can_create)173061da546Spatrick bool CFCMutableDictionary::AddValueSInt32(CFStringRef key, int32_t value,
174061da546Spatrick bool can_create) {
175061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
176061da546Spatrick if (dict != NULL) {
177061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
178061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
179061da546Spatrick if (cf_number.get()) {
180061da546Spatrick // Let the dictionary own the CFNumber
181061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
182061da546Spatrick return true;
183061da546Spatrick }
184061da546Spatrick }
185061da546Spatrick return false;
186061da546Spatrick }
187061da546Spatrick
SetValueSInt32(CFStringRef key,int32_t value,bool can_create)188061da546Spatrick bool CFCMutableDictionary::SetValueSInt32(CFStringRef key, int32_t value,
189061da546Spatrick bool can_create) {
190061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
191061da546Spatrick if (dict != NULL) {
192061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
193061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
194061da546Spatrick if (cf_number.get()) {
195061da546Spatrick // Let the dictionary own the CFNumber
196061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
197061da546Spatrick return true;
198061da546Spatrick }
199061da546Spatrick }
200061da546Spatrick return false;
201061da546Spatrick }
202061da546Spatrick
AddValueSInt64(CFStringRef key,int64_t value,bool can_create)203061da546Spatrick bool CFCMutableDictionary::AddValueSInt64(CFStringRef key, int64_t value,
204061da546Spatrick bool can_create) {
205061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
206061da546Spatrick if (dict != NULL) {
207061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
208061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
209061da546Spatrick if (cf_number.get()) {
210061da546Spatrick // Let the dictionary own the CFNumber
211061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
212061da546Spatrick return true;
213061da546Spatrick }
214061da546Spatrick }
215061da546Spatrick return false;
216061da546Spatrick }
217061da546Spatrick
SetValueSInt64(CFStringRef key,int64_t value,bool can_create)218061da546Spatrick bool CFCMutableDictionary::SetValueSInt64(CFStringRef key, int64_t value,
219061da546Spatrick bool can_create) {
220061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
221061da546Spatrick if (dict != NULL) {
222061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
223061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
224061da546Spatrick if (cf_number.get()) {
225061da546Spatrick // Let the dictionary own the CFNumber
226061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
227061da546Spatrick return true;
228061da546Spatrick }
229061da546Spatrick }
230061da546Spatrick return false;
231061da546Spatrick }
232061da546Spatrick
AddValueUInt8(CFStringRef key,uint8_t value,bool can_create)233061da546Spatrick bool CFCMutableDictionary::AddValueUInt8(CFStringRef key, uint8_t value,
234061da546Spatrick bool can_create) {
235061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
236061da546Spatrick if (dict != NULL) {
237061da546Spatrick // Have to promote to the next size type so things don't appear negative of
238061da546Spatrick // the MSBit is set...
239061da546Spatrick int16_t sval = value;
240061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
241061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &sval));
242061da546Spatrick if (cf_number.get()) {
243061da546Spatrick // Let the dictionary own the CFNumber
244061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
245061da546Spatrick return true;
246061da546Spatrick }
247061da546Spatrick }
248061da546Spatrick return false;
249061da546Spatrick }
250061da546Spatrick
SetValueUInt8(CFStringRef key,uint8_t value,bool can_create)251061da546Spatrick bool CFCMutableDictionary::SetValueUInt8(CFStringRef key, uint8_t value,
252061da546Spatrick bool can_create) {
253061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
254061da546Spatrick if (dict != NULL) {
255061da546Spatrick // Have to promote to the next size type so things don't appear negative of
256061da546Spatrick // the MSBit is set...
257061da546Spatrick int16_t sval = value;
258061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
259061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &sval));
260061da546Spatrick if (cf_number.get()) {
261061da546Spatrick // Let the dictionary own the CFNumber
262061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
263061da546Spatrick return true;
264061da546Spatrick }
265061da546Spatrick }
266061da546Spatrick return false;
267061da546Spatrick }
268061da546Spatrick
AddValueUInt16(CFStringRef key,uint16_t value,bool can_create)269061da546Spatrick bool CFCMutableDictionary::AddValueUInt16(CFStringRef key, uint16_t value,
270061da546Spatrick bool can_create) {
271061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
272061da546Spatrick if (dict != NULL) {
273061da546Spatrick // Have to promote to the next size type so things don't appear negative of
274061da546Spatrick // the MSBit is set...
275061da546Spatrick int32_t sval = value;
276061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
277061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &sval));
278061da546Spatrick if (cf_number.get()) {
279061da546Spatrick // Let the dictionary own the CFNumber
280061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
281061da546Spatrick return true;
282061da546Spatrick }
283061da546Spatrick }
284061da546Spatrick return false;
285061da546Spatrick }
286061da546Spatrick
SetValueUInt16(CFStringRef key,uint16_t value,bool can_create)287061da546Spatrick bool CFCMutableDictionary::SetValueUInt16(CFStringRef key, uint16_t value,
288061da546Spatrick bool can_create) {
289061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
290061da546Spatrick if (dict != NULL) {
291061da546Spatrick // Have to promote to the next size type so things don't appear negative of
292061da546Spatrick // the MSBit is set...
293061da546Spatrick int32_t sval = value;
294061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
295061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &sval));
296061da546Spatrick if (cf_number.get()) {
297061da546Spatrick // Let the dictionary own the CFNumber
298061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
299061da546Spatrick return true;
300061da546Spatrick }
301061da546Spatrick }
302061da546Spatrick return false;
303061da546Spatrick }
304061da546Spatrick
AddValueUInt32(CFStringRef key,uint32_t value,bool can_create)305061da546Spatrick bool CFCMutableDictionary::AddValueUInt32(CFStringRef key, uint32_t value,
306061da546Spatrick bool can_create) {
307061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
308061da546Spatrick if (dict != NULL) {
309061da546Spatrick // Have to promote to the next size type so things don't appear negative of
310061da546Spatrick // the MSBit is set...
311061da546Spatrick int64_t sval = value;
312061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
313061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &sval));
314061da546Spatrick if (cf_number.get()) {
315061da546Spatrick // Let the dictionary own the CFNumber
316061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
317061da546Spatrick return true;
318061da546Spatrick }
319061da546Spatrick }
320061da546Spatrick return false;
321061da546Spatrick }
322061da546Spatrick
SetValueUInt32(CFStringRef key,uint32_t value,bool can_create)323061da546Spatrick bool CFCMutableDictionary::SetValueUInt32(CFStringRef key, uint32_t value,
324061da546Spatrick bool can_create) {
325061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
326061da546Spatrick if (dict != NULL) {
327061da546Spatrick // Have to promote to the next size type so things don't appear negative of
328061da546Spatrick // the MSBit is set...
329061da546Spatrick int64_t sval = value;
330061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
331061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &sval));
332061da546Spatrick if (cf_number.get()) {
333061da546Spatrick // Let the dictionary own the CFNumber
334061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
335061da546Spatrick return true;
336061da546Spatrick }
337061da546Spatrick }
338061da546Spatrick return false;
339061da546Spatrick }
340061da546Spatrick
AddValueUInt64(CFStringRef key,uint64_t value,bool can_create)341061da546Spatrick bool CFCMutableDictionary::AddValueUInt64(CFStringRef key, uint64_t value,
342061da546Spatrick bool can_create) {
343061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
344061da546Spatrick if (dict != NULL) {
345061da546Spatrick // The number may appear negative if the MSBit is set in "value". Due to a
346061da546Spatrick // limitation of CFNumber, there isn't a way to have it show up otherwise
347061da546Spatrick // as of this writing.
348061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
349061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
350061da546Spatrick if (cf_number.get()) {
351061da546Spatrick // Let the dictionary own the CFNumber
352061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
353061da546Spatrick return true;
354061da546Spatrick }
355061da546Spatrick }
356061da546Spatrick return false;
357061da546Spatrick }
358061da546Spatrick
SetValueUInt64(CFStringRef key,uint64_t value,bool can_create)359061da546Spatrick bool CFCMutableDictionary::SetValueUInt64(CFStringRef key, uint64_t value,
360061da546Spatrick bool can_create) {
361061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
362061da546Spatrick if (dict != NULL) {
363061da546Spatrick // The number may appear negative if the MSBit is set in "value". Due to a
364061da546Spatrick // limitation of CFNumber, there isn't a way to have it show up otherwise
365061da546Spatrick // as of this writing.
366061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
367061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
368061da546Spatrick if (cf_number.get()) {
369061da546Spatrick // Let the dictionary own the CFNumber
370061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
371061da546Spatrick return true;
372061da546Spatrick }
373061da546Spatrick }
374061da546Spatrick return false;
375061da546Spatrick }
376061da546Spatrick
AddValueDouble(CFStringRef key,double value,bool can_create)377061da546Spatrick bool CFCMutableDictionary::AddValueDouble(CFStringRef key, double value,
378061da546Spatrick bool can_create) {
379061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
380061da546Spatrick if (dict != NULL) {
381061da546Spatrick // The number may appear negative if the MSBit is set in "value". Due to a
382061da546Spatrick // limitation of CFNumber, there isn't a way to have it show up otherwise
383061da546Spatrick // as of this writing.
384061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
385061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &value));
386061da546Spatrick if (cf_number.get()) {
387061da546Spatrick // Let the dictionary own the CFNumber
388061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_number.get());
389061da546Spatrick return true;
390061da546Spatrick }
391061da546Spatrick }
392061da546Spatrick return false;
393061da546Spatrick }
394061da546Spatrick
SetValueDouble(CFStringRef key,double value,bool can_create)395061da546Spatrick bool CFCMutableDictionary::SetValueDouble(CFStringRef key, double value,
396061da546Spatrick bool can_create) {
397061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
398061da546Spatrick if (dict != NULL) {
399061da546Spatrick // The number may appear negative if the MSBit is set in "value". Due to a
400061da546Spatrick // limitation of CFNumber, there isn't a way to have it show up otherwise
401061da546Spatrick // as of this writing.
402061da546Spatrick CFCReleaser<CFNumberRef> cf_number(
403061da546Spatrick ::CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &value));
404061da546Spatrick if (cf_number.get()) {
405061da546Spatrick // Let the dictionary own the CFNumber
406061da546Spatrick ::CFDictionarySetValue(dict, key, cf_number.get());
407061da546Spatrick return true;
408061da546Spatrick }
409061da546Spatrick }
410061da546Spatrick return false;
411061da546Spatrick }
412061da546Spatrick
AddValueCString(CFStringRef key,const char * cstr,bool can_create)413061da546Spatrick bool CFCMutableDictionary::AddValueCString(CFStringRef key, const char *cstr,
414061da546Spatrick bool can_create) {
415061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
416061da546Spatrick if (dict != NULL) {
417061da546Spatrick CFCString cf_str(cstr, kCFStringEncodingUTF8);
418061da546Spatrick if (cf_str.get()) {
419061da546Spatrick // Let the dictionary own the CFNumber
420061da546Spatrick ::CFDictionaryAddValue(dict, key, cf_str.get());
421061da546Spatrick return true;
422061da546Spatrick }
423061da546Spatrick }
424061da546Spatrick return false;
425061da546Spatrick }
426061da546Spatrick
SetValueCString(CFStringRef key,const char * cstr,bool can_create)427061da546Spatrick bool CFCMutableDictionary::SetValueCString(CFStringRef key, const char *cstr,
428061da546Spatrick bool can_create) {
429061da546Spatrick CFMutableDictionaryRef dict = Dictionary(can_create);
430061da546Spatrick if (dict != NULL) {
431061da546Spatrick CFCString cf_str(cstr, kCFStringEncodingUTF8);
432061da546Spatrick if (cf_str.get()) {
433061da546Spatrick // Let the dictionary own the CFNumber
434061da546Spatrick ::CFDictionarySetValue(dict, key, cf_str.get());
435061da546Spatrick return true;
436061da546Spatrick }
437061da546Spatrick }
438061da546Spatrick return false;
439061da546Spatrick }
440061da546Spatrick
RemoveAllValues()441061da546Spatrick void CFCMutableDictionary::RemoveAllValues() {
442061da546Spatrick CFMutableDictionaryRef dict = get();
443061da546Spatrick if (dict)
444061da546Spatrick ::CFDictionaryRemoveAllValues(dict);
445061da546Spatrick }
446061da546Spatrick
RemoveValue(const void * value)447061da546Spatrick void CFCMutableDictionary::RemoveValue(const void *value) {
448061da546Spatrick CFMutableDictionaryRef dict = get();
449061da546Spatrick if (dict)
450061da546Spatrick ::CFDictionaryRemoveValue(dict, value);
451061da546Spatrick }
ReplaceValue(const void * key,const void * value)452061da546Spatrick void CFCMutableDictionary::ReplaceValue(const void *key, const void *value) {
453061da546Spatrick CFMutableDictionaryRef dict = get();
454061da546Spatrick if (dict)
455061da546Spatrick ::CFDictionaryReplaceValue(dict, key, value);
456061da546Spatrick }
457