180814287SRaphael Isemann //===-- CFCMutableDictionary.cpp ------------------------------------------===//
230fdc8d8SChris Lattner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
630fdc8d8SChris Lattner //
730fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
830fdc8d8SChris Lattner
930fdc8d8SChris Lattner #include "CFCMutableDictionary.h"
1030fdc8d8SChris Lattner #include "CFCString.h"
1130fdc8d8SChris Lattner // CFCString constructor
CFCMutableDictionary(CFMutableDictionaryRef s)12b9c1b51eSKate Stone CFCMutableDictionary::CFCMutableDictionary(CFMutableDictionaryRef s)
13b9c1b51eSKate Stone : CFCReleaser<CFMutableDictionaryRef>(s) {}
1430fdc8d8SChris Lattner
1530fdc8d8SChris Lattner // CFCMutableDictionary copy constructor
16*24f9a2f5SShafik Yaghmour CFCMutableDictionary::CFCMutableDictionary(const CFCMutableDictionary &rhs) =
17*24f9a2f5SShafik Yaghmour default;
1830fdc8d8SChris Lattner
1930fdc8d8SChris Lattner // CFCMutableDictionary copy constructor
20b9c1b51eSKate Stone const CFCMutableDictionary &CFCMutableDictionary::
operator =(const CFCMutableDictionary & rhs)21b9c1b51eSKate Stone operator=(const CFCMutableDictionary &rhs) {
2230fdc8d8SChris Lattner if (this != &rhs)
2330fdc8d8SChris Lattner *this = rhs;
2430fdc8d8SChris Lattner return *this;
2530fdc8d8SChris Lattner }
2630fdc8d8SChris Lattner
2730fdc8d8SChris Lattner // Destructor
28fd2433e1SJonas Devlieghere CFCMutableDictionary::~CFCMutableDictionary() = default;
2930fdc8d8SChris Lattner
GetCount() const30b9c1b51eSKate Stone CFIndex CFCMutableDictionary::GetCount() const {
3130fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
3230fdc8d8SChris Lattner if (dict)
3330fdc8d8SChris Lattner return ::CFDictionaryGetCount(dict);
3430fdc8d8SChris Lattner return 0;
3530fdc8d8SChris Lattner }
3630fdc8d8SChris Lattner
GetCountOfKey(const void * key) const37b9c1b51eSKate Stone CFIndex CFCMutableDictionary::GetCountOfKey(const void *key) const
3830fdc8d8SChris Lattner
3930fdc8d8SChris Lattner {
4030fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
4130fdc8d8SChris Lattner if (dict)
4230fdc8d8SChris Lattner return ::CFDictionaryGetCountOfKey(dict, key);
4330fdc8d8SChris Lattner return 0;
4430fdc8d8SChris Lattner }
4530fdc8d8SChris Lattner
GetCountOfValue(const void * value) const46b9c1b51eSKate Stone CFIndex CFCMutableDictionary::GetCountOfValue(const void *value) const
4730fdc8d8SChris Lattner
4830fdc8d8SChris Lattner {
4930fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
5030fdc8d8SChris Lattner if (dict)
5130fdc8d8SChris Lattner return ::CFDictionaryGetCountOfValue(dict, value);
5230fdc8d8SChris Lattner return 0;
5330fdc8d8SChris Lattner }
5430fdc8d8SChris Lattner
GetKeysAndValues(const void ** keys,const void ** values) const55b9c1b51eSKate Stone void CFCMutableDictionary::GetKeysAndValues(const void **keys,
56b9c1b51eSKate Stone const void **values) const {
5730fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
5830fdc8d8SChris Lattner if (dict)
5930fdc8d8SChris Lattner ::CFDictionaryGetKeysAndValues(dict, keys, values);
6030fdc8d8SChris Lattner }
6130fdc8d8SChris Lattner
GetValue(const void * key) const62b9c1b51eSKate Stone const void *CFCMutableDictionary::GetValue(const void *key) const
6330fdc8d8SChris Lattner
6430fdc8d8SChris Lattner {
6530fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
6630fdc8d8SChris Lattner if (dict)
6730fdc8d8SChris Lattner return ::CFDictionaryGetValue(dict, key);
6830fdc8d8SChris Lattner return NULL;
6930fdc8d8SChris Lattner }
7030fdc8d8SChris Lattner
7130fdc8d8SChris Lattner Boolean
GetValueIfPresent(const void * key,const void ** value_handle) const72b9c1b51eSKate Stone CFCMutableDictionary::GetValueIfPresent(const void *key,
73b9c1b51eSKate Stone const void **value_handle) const {
7430fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
7530fdc8d8SChris Lattner if (dict)
7630fdc8d8SChris Lattner return ::CFDictionaryGetValueIfPresent(dict, key, value_handle);
7730fdc8d8SChris Lattner return false;
7830fdc8d8SChris Lattner }
7930fdc8d8SChris Lattner
Dictionary(bool can_create)80b9c1b51eSKate Stone CFMutableDictionaryRef CFCMutableDictionary::Dictionary(bool can_create) {
8130fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
82b9c1b51eSKate Stone if (can_create && dict == NULL) {
83b9c1b51eSKate Stone dict = ::CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
84b9c1b51eSKate Stone &kCFTypeDictionaryKeyCallBacks,
85b9c1b51eSKate Stone &kCFTypeDictionaryValueCallBacks);
8630fdc8d8SChris Lattner reset(dict);
8730fdc8d8SChris Lattner }
8830fdc8d8SChris Lattner return dict;
8930fdc8d8SChris Lattner }
9030fdc8d8SChris Lattner
AddValue(CFStringRef key,const void * value,bool can_create)91b9c1b51eSKate Stone bool CFCMutableDictionary::AddValue(CFStringRef key, const void *value,
92b9c1b51eSKate Stone bool can_create) {
9330fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
94b9c1b51eSKate Stone if (dict != NULL) {
9530fdc8d8SChris Lattner // Let the dictionary own the CFNumber
9630fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, value);
9730fdc8d8SChris Lattner return true;
9830fdc8d8SChris Lattner }
9930fdc8d8SChris Lattner return false;
10030fdc8d8SChris Lattner }
10130fdc8d8SChris Lattner
SetValue(CFStringRef key,const void * value,bool can_create)102b9c1b51eSKate Stone bool CFCMutableDictionary::SetValue(CFStringRef key, const void *value,
103b9c1b51eSKate Stone bool can_create) {
10430fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
105b9c1b51eSKate Stone if (dict != NULL) {
10630fdc8d8SChris Lattner // Let the dictionary own the CFNumber
10730fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, value);
10830fdc8d8SChris Lattner return true;
10930fdc8d8SChris Lattner }
11030fdc8d8SChris Lattner return false;
11130fdc8d8SChris Lattner }
11230fdc8d8SChris Lattner
AddValueSInt8(CFStringRef key,int8_t value,bool can_create)113b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueSInt8(CFStringRef key, int8_t value,
114b9c1b51eSKate Stone bool can_create) {
11530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
116b9c1b51eSKate Stone if (dict != NULL) {
117b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
118b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &value));
119b9c1b51eSKate Stone if (cf_number.get()) {
12030fdc8d8SChris Lattner // Let the dictionary own the CFNumber
12130fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
12230fdc8d8SChris Lattner return true;
12330fdc8d8SChris Lattner }
12430fdc8d8SChris Lattner }
12530fdc8d8SChris Lattner return false;
12630fdc8d8SChris Lattner }
12730fdc8d8SChris Lattner
SetValueSInt8(CFStringRef key,int8_t value,bool can_create)128b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueSInt8(CFStringRef key, int8_t value,
129b9c1b51eSKate Stone bool can_create) {
13030fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
131b9c1b51eSKate Stone if (dict != NULL) {
132b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
133b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &value));
134b9c1b51eSKate Stone if (cf_number.get()) {
13530fdc8d8SChris Lattner // Let the dictionary own the CFNumber
13630fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
13730fdc8d8SChris Lattner return true;
13830fdc8d8SChris Lattner }
13930fdc8d8SChris Lattner }
14030fdc8d8SChris Lattner return false;
14130fdc8d8SChris Lattner }
14230fdc8d8SChris Lattner
AddValueSInt16(CFStringRef key,int16_t value,bool can_create)143b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueSInt16(CFStringRef key, int16_t value,
144b9c1b51eSKate Stone bool can_create) {
14530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
146b9c1b51eSKate Stone if (dict != NULL) {
147b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
148b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &value));
149b9c1b51eSKate Stone if (cf_number.get()) {
15030fdc8d8SChris Lattner // Let the dictionary own the CFNumber
15130fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
15230fdc8d8SChris Lattner return true;
15330fdc8d8SChris Lattner }
15430fdc8d8SChris Lattner }
15530fdc8d8SChris Lattner return false;
15630fdc8d8SChris Lattner }
15730fdc8d8SChris Lattner
SetValueSInt16(CFStringRef key,int16_t value,bool can_create)158b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueSInt16(CFStringRef key, int16_t value,
159b9c1b51eSKate Stone bool can_create) {
16030fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
161b9c1b51eSKate Stone if (dict != NULL) {
162b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
163b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &value));
164b9c1b51eSKate Stone if (cf_number.get()) {
16530fdc8d8SChris Lattner // Let the dictionary own the CFNumber
16630fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
16730fdc8d8SChris Lattner return true;
16830fdc8d8SChris Lattner }
16930fdc8d8SChris Lattner }
17030fdc8d8SChris Lattner return false;
17130fdc8d8SChris Lattner }
17230fdc8d8SChris Lattner
AddValueSInt32(CFStringRef key,int32_t value,bool can_create)173b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueSInt32(CFStringRef key, int32_t value,
174b9c1b51eSKate Stone bool can_create) {
17530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
176b9c1b51eSKate Stone if (dict != NULL) {
177b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
178b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
179b9c1b51eSKate Stone if (cf_number.get()) {
18030fdc8d8SChris Lattner // Let the dictionary own the CFNumber
18130fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
18230fdc8d8SChris Lattner return true;
18330fdc8d8SChris Lattner }
18430fdc8d8SChris Lattner }
18530fdc8d8SChris Lattner return false;
18630fdc8d8SChris Lattner }
18730fdc8d8SChris Lattner
SetValueSInt32(CFStringRef key,int32_t value,bool can_create)188b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueSInt32(CFStringRef key, int32_t value,
189b9c1b51eSKate Stone bool can_create) {
19030fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
191b9c1b51eSKate Stone if (dict != NULL) {
192b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
193b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
194b9c1b51eSKate Stone if (cf_number.get()) {
19530fdc8d8SChris Lattner // Let the dictionary own the CFNumber
19630fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
19730fdc8d8SChris Lattner return true;
19830fdc8d8SChris Lattner }
19930fdc8d8SChris Lattner }
20030fdc8d8SChris Lattner return false;
20130fdc8d8SChris Lattner }
20230fdc8d8SChris Lattner
AddValueSInt64(CFStringRef key,int64_t value,bool can_create)203b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueSInt64(CFStringRef key, int64_t value,
204b9c1b51eSKate Stone bool can_create) {
20530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
206b9c1b51eSKate Stone if (dict != NULL) {
207b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
208b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
209b9c1b51eSKate Stone if (cf_number.get()) {
21030fdc8d8SChris Lattner // Let the dictionary own the CFNumber
21130fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
21230fdc8d8SChris Lattner return true;
21330fdc8d8SChris Lattner }
21430fdc8d8SChris Lattner }
21530fdc8d8SChris Lattner return false;
21630fdc8d8SChris Lattner }
21730fdc8d8SChris Lattner
SetValueSInt64(CFStringRef key,int64_t value,bool can_create)218b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueSInt64(CFStringRef key, int64_t value,
219b9c1b51eSKate Stone bool can_create) {
22030fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
221b9c1b51eSKate Stone if (dict != NULL) {
222b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
223b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
224b9c1b51eSKate Stone if (cf_number.get()) {
22530fdc8d8SChris Lattner // Let the dictionary own the CFNumber
22630fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
22730fdc8d8SChris Lattner return true;
22830fdc8d8SChris Lattner }
22930fdc8d8SChris Lattner }
23030fdc8d8SChris Lattner return false;
23130fdc8d8SChris Lattner }
23230fdc8d8SChris Lattner
AddValueUInt8(CFStringRef key,uint8_t value,bool can_create)233b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueUInt8(CFStringRef key, uint8_t value,
234b9c1b51eSKate Stone bool can_create) {
23530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
236b9c1b51eSKate Stone if (dict != NULL) {
237b9c1b51eSKate Stone // Have to promote to the next size type so things don't appear negative of
238b9c1b51eSKate Stone // the MSBit is set...
23930fdc8d8SChris Lattner int16_t sval = value;
240b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
241b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &sval));
242b9c1b51eSKate Stone if (cf_number.get()) {
24330fdc8d8SChris Lattner // Let the dictionary own the CFNumber
24430fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
24530fdc8d8SChris Lattner return true;
24630fdc8d8SChris Lattner }
24730fdc8d8SChris Lattner }
24830fdc8d8SChris Lattner return false;
24930fdc8d8SChris Lattner }
25030fdc8d8SChris Lattner
SetValueUInt8(CFStringRef key,uint8_t value,bool can_create)251b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueUInt8(CFStringRef key, uint8_t value,
252b9c1b51eSKate Stone bool can_create) {
25330fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
254b9c1b51eSKate Stone if (dict != NULL) {
255b9c1b51eSKate Stone // Have to promote to the next size type so things don't appear negative of
256b9c1b51eSKate Stone // the MSBit is set...
25730fdc8d8SChris Lattner int16_t sval = value;
258b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
259b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &sval));
260b9c1b51eSKate Stone if (cf_number.get()) {
26130fdc8d8SChris Lattner // Let the dictionary own the CFNumber
26230fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
26330fdc8d8SChris Lattner return true;
26430fdc8d8SChris Lattner }
26530fdc8d8SChris Lattner }
26630fdc8d8SChris Lattner return false;
26730fdc8d8SChris Lattner }
26830fdc8d8SChris Lattner
AddValueUInt16(CFStringRef key,uint16_t value,bool can_create)269b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueUInt16(CFStringRef key, uint16_t value,
270b9c1b51eSKate Stone bool can_create) {
27130fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
272b9c1b51eSKate Stone if (dict != NULL) {
273b9c1b51eSKate Stone // Have to promote to the next size type so things don't appear negative of
274b9c1b51eSKate Stone // the MSBit is set...
27530fdc8d8SChris Lattner int32_t sval = value;
276b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
277b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &sval));
278b9c1b51eSKate Stone if (cf_number.get()) {
27930fdc8d8SChris Lattner // Let the dictionary own the CFNumber
28030fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
28130fdc8d8SChris Lattner return true;
28230fdc8d8SChris Lattner }
28330fdc8d8SChris Lattner }
28430fdc8d8SChris Lattner return false;
28530fdc8d8SChris Lattner }
28630fdc8d8SChris Lattner
SetValueUInt16(CFStringRef key,uint16_t value,bool can_create)287b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueUInt16(CFStringRef key, uint16_t value,
288b9c1b51eSKate Stone bool can_create) {
28930fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
290b9c1b51eSKate Stone if (dict != NULL) {
291b9c1b51eSKate Stone // Have to promote to the next size type so things don't appear negative of
292b9c1b51eSKate Stone // the MSBit is set...
29330fdc8d8SChris Lattner int32_t sval = value;
294b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
295b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &sval));
296b9c1b51eSKate Stone if (cf_number.get()) {
29730fdc8d8SChris Lattner // Let the dictionary own the CFNumber
29830fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
29930fdc8d8SChris Lattner return true;
30030fdc8d8SChris Lattner }
30130fdc8d8SChris Lattner }
30230fdc8d8SChris Lattner return false;
30330fdc8d8SChris Lattner }
30430fdc8d8SChris Lattner
AddValueUInt32(CFStringRef key,uint32_t value,bool can_create)305b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueUInt32(CFStringRef key, uint32_t value,
306b9c1b51eSKate Stone bool can_create) {
30730fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
308b9c1b51eSKate Stone if (dict != NULL) {
309b9c1b51eSKate Stone // Have to promote to the next size type so things don't appear negative of
310b9c1b51eSKate Stone // the MSBit is set...
31130fdc8d8SChris Lattner int64_t sval = value;
312b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
313b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &sval));
314b9c1b51eSKate Stone if (cf_number.get()) {
31530fdc8d8SChris Lattner // Let the dictionary own the CFNumber
31630fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
31730fdc8d8SChris Lattner return true;
31830fdc8d8SChris Lattner }
31930fdc8d8SChris Lattner }
32030fdc8d8SChris Lattner return false;
32130fdc8d8SChris Lattner }
32230fdc8d8SChris Lattner
SetValueUInt32(CFStringRef key,uint32_t value,bool can_create)323b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueUInt32(CFStringRef key, uint32_t value,
324b9c1b51eSKate Stone bool can_create) {
32530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
326b9c1b51eSKate Stone if (dict != NULL) {
327b9c1b51eSKate Stone // Have to promote to the next size type so things don't appear negative of
328b9c1b51eSKate Stone // the MSBit is set...
32930fdc8d8SChris Lattner int64_t sval = value;
330b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
331b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &sval));
332b9c1b51eSKate Stone if (cf_number.get()) {
33330fdc8d8SChris Lattner // Let the dictionary own the CFNumber
33430fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
33530fdc8d8SChris Lattner return true;
33630fdc8d8SChris Lattner }
33730fdc8d8SChris Lattner }
33830fdc8d8SChris Lattner return false;
33930fdc8d8SChris Lattner }
34030fdc8d8SChris Lattner
AddValueUInt64(CFStringRef key,uint64_t value,bool can_create)341b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueUInt64(CFStringRef key, uint64_t value,
342b9c1b51eSKate Stone bool can_create) {
34330fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
344b9c1b51eSKate Stone if (dict != NULL) {
345b9c1b51eSKate Stone // The number may appear negative if the MSBit is set in "value". Due to a
34605097246SAdrian Prantl // limitation of CFNumber, there isn't a way to have it show up otherwise
34705097246SAdrian Prantl // as of this writing.
348b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
349b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
350b9c1b51eSKate Stone if (cf_number.get()) {
35130fdc8d8SChris Lattner // Let the dictionary own the CFNumber
35230fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_number.get());
35330fdc8d8SChris Lattner return true;
35430fdc8d8SChris Lattner }
35530fdc8d8SChris Lattner }
35630fdc8d8SChris Lattner return false;
35730fdc8d8SChris Lattner }
35830fdc8d8SChris Lattner
SetValueUInt64(CFStringRef key,uint64_t value,bool can_create)359b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueUInt64(CFStringRef key, uint64_t value,
360b9c1b51eSKate Stone bool can_create) {
36130fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
362b9c1b51eSKate Stone if (dict != NULL) {
363b9c1b51eSKate Stone // The number may appear negative if the MSBit is set in "value". Due to a
36405097246SAdrian Prantl // limitation of CFNumber, there isn't a way to have it show up otherwise
36505097246SAdrian Prantl // as of this writing.
366b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
367b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
368b9c1b51eSKate Stone if (cf_number.get()) {
36930fdc8d8SChris Lattner // Let the dictionary own the CFNumber
37030fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_number.get());
37130fdc8d8SChris Lattner return true;
37230fdc8d8SChris Lattner }
37330fdc8d8SChris Lattner }
37430fdc8d8SChris Lattner return false;
37530fdc8d8SChris Lattner }
37630fdc8d8SChris Lattner
AddValueDouble(CFStringRef key,double value,bool can_create)377b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueDouble(CFStringRef key, double value,
378b9c1b51eSKate Stone bool can_create) {
379f58cececSEnrico Granata CFMutableDictionaryRef dict = Dictionary(can_create);
380b9c1b51eSKate Stone if (dict != NULL) {
381b9c1b51eSKate Stone // The number may appear negative if the MSBit is set in "value". Due to a
38205097246SAdrian Prantl // limitation of CFNumber, there isn't a way to have it show up otherwise
38305097246SAdrian Prantl // as of this writing.
384b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
385b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &value));
386b9c1b51eSKate Stone if (cf_number.get()) {
387f58cececSEnrico Granata // Let the dictionary own the CFNumber
388f58cececSEnrico Granata ::CFDictionaryAddValue(dict, key, cf_number.get());
389f58cececSEnrico Granata return true;
390f58cececSEnrico Granata }
391f58cececSEnrico Granata }
392f58cececSEnrico Granata return false;
393f58cececSEnrico Granata }
394f58cececSEnrico Granata
SetValueDouble(CFStringRef key,double value,bool can_create)395b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueDouble(CFStringRef key, double value,
396b9c1b51eSKate Stone bool can_create) {
397f58cececSEnrico Granata CFMutableDictionaryRef dict = Dictionary(can_create);
398b9c1b51eSKate Stone if (dict != NULL) {
399b9c1b51eSKate Stone // The number may appear negative if the MSBit is set in "value". Due to a
40005097246SAdrian Prantl // limitation of CFNumber, there isn't a way to have it show up otherwise
40105097246SAdrian Prantl // as of this writing.
402b9c1b51eSKate Stone CFCReleaser<CFNumberRef> cf_number(
403b9c1b51eSKate Stone ::CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &value));
404b9c1b51eSKate Stone if (cf_number.get()) {
405f58cececSEnrico Granata // Let the dictionary own the CFNumber
406f58cececSEnrico Granata ::CFDictionarySetValue(dict, key, cf_number.get());
407f58cececSEnrico Granata return true;
408f58cececSEnrico Granata }
409f58cececSEnrico Granata }
410f58cececSEnrico Granata return false;
411f58cececSEnrico Granata }
412f58cececSEnrico Granata
AddValueCString(CFStringRef key,const char * cstr,bool can_create)413b9c1b51eSKate Stone bool CFCMutableDictionary::AddValueCString(CFStringRef key, const char *cstr,
414b9c1b51eSKate Stone bool can_create) {
41530fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
416b9c1b51eSKate Stone if (dict != NULL) {
41730fdc8d8SChris Lattner CFCString cf_str(cstr, kCFStringEncodingUTF8);
418b9c1b51eSKate Stone if (cf_str.get()) {
41930fdc8d8SChris Lattner // Let the dictionary own the CFNumber
42030fdc8d8SChris Lattner ::CFDictionaryAddValue(dict, key, cf_str.get());
42130fdc8d8SChris Lattner return true;
42230fdc8d8SChris Lattner }
42330fdc8d8SChris Lattner }
42430fdc8d8SChris Lattner return false;
42530fdc8d8SChris Lattner }
42630fdc8d8SChris Lattner
SetValueCString(CFStringRef key,const char * cstr,bool can_create)427b9c1b51eSKate Stone bool CFCMutableDictionary::SetValueCString(CFStringRef key, const char *cstr,
428b9c1b51eSKate Stone bool can_create) {
42930fdc8d8SChris Lattner CFMutableDictionaryRef dict = Dictionary(can_create);
430b9c1b51eSKate Stone if (dict != NULL) {
43130fdc8d8SChris Lattner CFCString cf_str(cstr, kCFStringEncodingUTF8);
432b9c1b51eSKate Stone if (cf_str.get()) {
43330fdc8d8SChris Lattner // Let the dictionary own the CFNumber
43430fdc8d8SChris Lattner ::CFDictionarySetValue(dict, key, cf_str.get());
43530fdc8d8SChris Lattner return true;
43630fdc8d8SChris Lattner }
43730fdc8d8SChris Lattner }
43830fdc8d8SChris Lattner return false;
43930fdc8d8SChris Lattner }
44030fdc8d8SChris Lattner
RemoveAllValues()441b9c1b51eSKate Stone void CFCMutableDictionary::RemoveAllValues() {
44230fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
44330fdc8d8SChris Lattner if (dict)
44430fdc8d8SChris Lattner ::CFDictionaryRemoveAllValues(dict);
44530fdc8d8SChris Lattner }
44630fdc8d8SChris Lattner
RemoveValue(const void * value)447b9c1b51eSKate Stone void CFCMutableDictionary::RemoveValue(const void *value) {
44830fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
44930fdc8d8SChris Lattner if (dict)
45030fdc8d8SChris Lattner ::CFDictionaryRemoveValue(dict, value);
45130fdc8d8SChris Lattner }
ReplaceValue(const void * key,const void * value)452b9c1b51eSKate Stone void CFCMutableDictionary::ReplaceValue(const void *key, const void *value) {
45330fdc8d8SChris Lattner CFMutableDictionaryRef dict = get();
45430fdc8d8SChris Lattner if (dict)
45530fdc8d8SChris Lattner ::CFDictionaryReplaceValue(dict, key, value);
45630fdc8d8SChris Lattner }
457