core_foundation_sys/
array.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, CFComparatorFunction, CFIndex, CFRange, CFTypeID};
13use crate::string::CFStringRef;
14
15pub type CFArrayRetainCallBack =
16    extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void;
17pub type CFArrayReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void);
18pub type CFArrayCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef;
19pub type CFArrayEqualCallBack =
20    extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean;
21pub type CFArrayApplierFunction = extern "C" fn(value: *const c_void, context: *mut c_void);
22
23#[repr(C)]
24#[derive(Clone, Copy, Debug)]
25pub struct CFArrayCallBacks {
26    pub version: CFIndex,
27    pub retain: CFArrayRetainCallBack,
28    pub release: CFArrayReleaseCallBack,
29    pub copyDescription: CFArrayCopyDescriptionCallBack,
30    pub equal: CFArrayEqualCallBack,
31}
32
33#[repr(C)]
34pub struct __CFArray(c_void);
35
36pub type CFArrayRef = *const __CFArray;
37pub type CFMutableArrayRef = *mut __CFArray;
38
39extern "C" {
40    /*
41     * CFArray.h
42     */
43
44    pub static kCFTypeArrayCallBacks: CFArrayCallBacks;
45
46    /* CFArray */
47    /* Creating an Array */
48    pub fn CFArrayCreate(
49        allocator: CFAllocatorRef,
50        values: *const *const c_void,
51        numValues: CFIndex,
52        callBacks: *const CFArrayCallBacks,
53    ) -> CFArrayRef;
54    pub fn CFArrayCreateCopy(allocator: CFAllocatorRef, theArray: CFArrayRef) -> CFArrayRef;
55
56    /* Examining an Array */
57    pub fn CFArrayBSearchValues(
58        theArray: CFArrayRef,
59        range: CFRange,
60        value: *const c_void,
61        comparator: CFComparatorFunction,
62        context: *mut c_void,
63    ) -> CFIndex;
64    pub fn CFArrayContainsValue(
65        theArray: CFArrayRef,
66        range: CFRange,
67        value: *const c_void,
68    ) -> Boolean;
69    pub fn CFArrayGetCount(theArray: CFArrayRef) -> CFIndex;
70    pub fn CFArrayGetCountOfValue(
71        theArray: CFArrayRef,
72        range: CFRange,
73        value: *const c_void,
74    ) -> CFIndex;
75    pub fn CFArrayGetFirstIndexOfValue(
76        theArray: CFArrayRef,
77        range: CFRange,
78        value: *const c_void,
79    ) -> CFIndex;
80    pub fn CFArrayGetLastIndexOfValue(
81        theArray: CFArrayRef,
82        range: CFRange,
83        value: *const c_void,
84    ) -> CFIndex;
85    pub fn CFArrayGetValues(theArray: CFArrayRef, range: CFRange, values: *mut *const c_void);
86    pub fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const c_void;
87
88    /* Applying a Function to Elements */
89    pub fn CFArrayApplyFunction(
90        theArray: CFArrayRef,
91        range: CFRange,
92        applier: CFArrayApplierFunction,
93        context: *mut c_void,
94    );
95
96    /* Getting the CFArray Type ID */
97    pub fn CFArrayGetTypeID() -> CFTypeID;
98
99    /* CFMutableArray */
100    /* CFMutableArray Miscellaneous Functions */
101    pub fn CFArrayAppendArray(
102        theArray: CFMutableArrayRef,
103        otherArray: CFArrayRef,
104        otherRange: CFRange,
105    );
106    pub fn CFArrayAppendValue(theArray: CFMutableArrayRef, value: *const c_void);
107    pub fn CFArrayCreateMutable(
108        allocator: CFAllocatorRef,
109        capacity: CFIndex,
110        callBacks: *const CFArrayCallBacks,
111    ) -> CFMutableArrayRef;
112    pub fn CFArrayCreateMutableCopy(
113        allocator: CFAllocatorRef,
114        capacity: CFIndex,
115        theArray: CFArrayRef,
116    ) -> CFMutableArrayRef;
117    pub fn CFArrayExchangeValuesAtIndices(
118        theArray: CFMutableArrayRef,
119        idx1: CFIndex,
120        idx2: CFIndex,
121    );
122    pub fn CFArrayInsertValueAtIndex(
123        theArray: CFMutableArrayRef,
124        idx: CFIndex,
125        value: *const c_void,
126    );
127    pub fn CFArrayRemoveAllValues(theArray: CFMutableArrayRef);
128    pub fn CFArrayRemoveValueAtIndex(theArray: CFMutableArrayRef, idx: CFIndex);
129    pub fn CFArrayReplaceValues(
130        theArray: CFMutableArrayRef,
131        range: CFRange,
132        newValues: *mut *const c_void,
133        newCount: CFIndex,
134    );
135    pub fn CFArraySetValueAtIndex(theArray: CFMutableArrayRef, idx: CFIndex, value: *const c_void);
136    pub fn CFArraySortValues(
137        theArray: CFMutableArrayRef,
138        range: CFRange,
139        comparator: CFComparatorFunction,
140        context: *mut c_void,
141    );
142}