core_foundation_sys/
dictionary.rs

1// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use std::os::raw::c_void;
11
12use crate::base::{Boolean, CFAllocatorRef, CFHashCode, CFIndex, CFTypeID};
13use crate::string::CFStringRef;
14
15pub type CFDictionaryApplierFunction =
16    extern "C" fn(key: *const c_void, value: *const c_void, context: *mut c_void);
17
18pub type CFDictionaryRetainCallBack =
19    extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void;
20pub type CFDictionaryReleaseCallBack =
21    extern "C" fn(allocator: CFAllocatorRef, value: *const c_void);
22pub type CFDictionaryCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef;
23pub type CFDictionaryEqualCallBack =
24    extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean;
25pub type CFDictionaryHashCallBack = extern "C" fn(value: *const c_void) -> CFHashCode;
26
27#[repr(C)]
28#[derive(Clone, Copy)]
29pub struct CFDictionaryKeyCallBacks {
30    pub version: CFIndex,
31    pub retain: CFDictionaryRetainCallBack,
32    pub release: CFDictionaryReleaseCallBack,
33    pub copyDescription: CFDictionaryCopyDescriptionCallBack,
34    pub equal: CFDictionaryEqualCallBack,
35    pub hash: CFDictionaryHashCallBack,
36}
37
38#[repr(C)]
39#[derive(Clone, Copy)]
40pub struct CFDictionaryValueCallBacks {
41    pub version: CFIndex,
42    pub retain: CFDictionaryRetainCallBack,
43    pub release: CFDictionaryReleaseCallBack,
44    pub copyDescription: CFDictionaryCopyDescriptionCallBack,
45    pub equal: CFDictionaryEqualCallBack,
46}
47
48#[repr(C)]
49pub struct __CFDictionary(c_void);
50
51pub type CFDictionaryRef = *const __CFDictionary;
52pub type CFMutableDictionaryRef = *mut __CFDictionary;
53
54extern "C" {
55    /*
56     * CFDictionary.h
57     */
58
59    pub static kCFTypeDictionaryKeyCallBacks: CFDictionaryKeyCallBacks;
60    pub static kCFCopyStringDictionaryKeyCallBacks: CFDictionaryKeyCallBacks;
61    pub static kCFTypeDictionaryValueCallBacks: CFDictionaryValueCallBacks;
62
63    /* CFDictionary */
64    /* Creating a dictionary */
65    pub fn CFDictionaryCreate(
66        allocator: CFAllocatorRef,
67        keys: *const *const c_void,
68        values: *const *const c_void,
69        numValues: CFIndex,
70        keyCallBacks: *const CFDictionaryKeyCallBacks,
71        valueCallBacks: *const CFDictionaryValueCallBacks,
72    ) -> CFDictionaryRef;
73    pub fn CFDictionaryCreateCopy(
74        allocator: CFAllocatorRef,
75        theDict: CFDictionaryRef,
76    ) -> CFDictionaryRef;
77
78    /* Examining a dictionary */
79    pub fn CFDictionaryContainsKey(theDict: CFDictionaryRef, key: *const c_void) -> Boolean;
80    pub fn CFDictionaryContainsValue(theDict: CFDictionaryRef, value: *const c_void) -> Boolean;
81    pub fn CFDictionaryGetCount(theDict: CFDictionaryRef) -> CFIndex;
82    pub fn CFDictionaryGetCountOfKey(theDict: CFDictionaryRef, key: *const c_void) -> CFIndex;
83    pub fn CFDictionaryGetCountOfValue(heDict: CFDictionaryRef, value: *const c_void) -> CFIndex;
84    pub fn CFDictionaryGetKeysAndValues(
85        theDict: CFDictionaryRef,
86        keys: *mut *const c_void,
87        values: *mut *const c_void,
88    );
89    pub fn CFDictionaryGetValue(theDict: CFDictionaryRef, key: *const c_void) -> *const c_void;
90    pub fn CFDictionaryGetValueIfPresent(
91        theDict: CFDictionaryRef,
92        key: *const c_void,
93        value: *mut *const c_void,
94    ) -> Boolean;
95
96    /* Applying a function to a dictionary */
97    pub fn CFDictionaryApplyFunction(
98        theDict: CFDictionaryRef,
99        applier: CFDictionaryApplierFunction,
100        context: *mut c_void,
101    );
102
103    /* Getting the CFDictionary type ID */
104    pub fn CFDictionaryGetTypeID() -> CFTypeID;
105
106    /* CFMutableDictionary */
107    /* Creating a Mutable Dictionary */
108    pub fn CFDictionaryCreateMutable(
109        allocator: CFAllocatorRef,
110        capacity: CFIndex,
111        keyCallbacks: *const CFDictionaryKeyCallBacks,
112        valueCallbacks: *const CFDictionaryValueCallBacks,
113    ) -> CFMutableDictionaryRef;
114    pub fn CFDictionaryCreateMutableCopy(
115        allocator: CFAllocatorRef,
116        capacity: CFIndex,
117        theDict: CFDictionaryRef,
118    ) -> CFMutableDictionaryRef;
119
120    /* Modifying a Dictionary */
121    pub fn CFDictionaryAddValue(
122        theDict: CFMutableDictionaryRef,
123        key: *const c_void,
124        value: *const c_void,
125    );
126    pub fn CFDictionaryRemoveAllValues(theDict: CFMutableDictionaryRef);
127    pub fn CFDictionaryRemoveValue(theDict: CFMutableDictionaryRef, key: *const c_void);
128    pub fn CFDictionaryReplaceValue(
129        theDict: CFMutableDictionaryRef,
130        key: *const c_void,
131        value: *const c_void,
132    );
133    pub fn CFDictionarySetValue(
134        theDict: CFMutableDictionaryRef,
135        key: *const c_void,
136        value: *const c_void,
137    );
138
139}