objc2_core_foundation/generated/CFBinaryHeap.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheapcomparecontext?language=objc)
13#[cfg(feature = "CFBase")]
14#[repr(C)]
15#[derive(Clone, Copy, Debug, PartialEq)]
16pub struct CFBinaryHeapCompareContext {
17 pub version: CFIndex,
18 pub info: *mut c_void,
19 pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
20 pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
21 pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
22}
23
24#[cfg(all(feature = "CFBase", feature = "objc2"))]
25unsafe impl Encode for CFBinaryHeapCompareContext {
26 const ENCODING: Encoding = Encoding::Struct(
27 "?",
28 &[
29 <CFIndex>::ENCODING,
30 <*mut c_void>::ENCODING,
31 <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
32 <Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
33 <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
34 ],
35 );
36}
37
38#[cfg(all(feature = "CFBase", feature = "objc2"))]
39unsafe impl RefEncode for CFBinaryHeapCompareContext {
40 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
41}
42
43/// Structure containing the callbacks for values of a CFBinaryHeap.
44/// Field: version The version number of the structure type being passed
45/// in as a parameter to the CFBinaryHeap creation functions.
46/// This structure is version 0.
47/// Field: retain The callback used to add a retain for the binary heap
48/// on values as they are put into the binary heap.
49/// This callback returns the value to use as the value in the
50/// binary heap, which is usually the value parameter passed to
51/// this callback, but may be a different value if a different
52/// value should be added to the binary heap. The binary heap's
53/// allocator is passed as the first argument.
54/// Field: release The callback used to remove a retain previously added
55/// for the binary heap from values as they are removed from
56/// the binary heap. The binary heap's allocator is passed as the
57/// first argument.
58/// Field: copyDescription The callback used to create a descriptive
59/// string representation of each value in the binary heap. This
60/// is used by the CFCopyDescription() function.
61/// Field: compare The callback used to compare values in the binary heap for
62/// equality in some operations.
63///
64/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheapcallbacks?language=objc)
65#[cfg(feature = "CFBase")]
66#[repr(C)]
67#[derive(Clone, Copy, Debug, PartialEq)]
68pub struct CFBinaryHeapCallBacks {
69 pub version: CFIndex,
70 pub retain:
71 Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void>,
72 pub release: Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>,
73 pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
74 pub compare: Option<
75 unsafe extern "C-unwind" fn(
76 *const c_void,
77 *const c_void,
78 *mut c_void,
79 ) -> CFComparisonResult,
80 >,
81}
82
83#[cfg(all(feature = "CFBase", feature = "objc2"))]
84unsafe impl Encode for CFBinaryHeapCallBacks {
85 const ENCODING: Encoding =
86 Encoding::Struct(
87 "?",
88 &[
89 <CFIndex>::ENCODING,
90 <Option<
91 unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void,
92 >>::ENCODING,
93 <Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>>::ENCODING,
94 <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
95 <Option<
96 unsafe extern "C-unwind" fn(
97 *const c_void,
98 *const c_void,
99 *mut c_void,
100 ) -> CFComparisonResult,
101 >>::ENCODING,
102 ],
103 );
104}
105
106#[cfg(all(feature = "CFBase", feature = "objc2"))]
107unsafe impl RefEncode for CFBinaryHeapCallBacks {
108 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
109}
110
111extern "C" {
112 /// Predefined CFBinaryHeapCallBacks structure containing a set
113 /// of callbacks appropriate for use when the values in a CFBinaryHeap
114 /// are all CFString types.
115 ///
116 /// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringbinaryheapcallbacks?language=objc)
117 #[cfg(feature = "CFBase")]
118 pub static kCFStringBinaryHeapCallBacks: CFBinaryHeapCallBacks;
119}
120
121/// Type of the callback function used by the apply functions of
122/// CFBinaryHeap.
123///
124/// Parameter `val`: The current value from the binary heap.
125///
126/// Parameter `context`: The user-defined context parameter given to the apply
127/// function.
128///
129/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheapapplierfunction?language=objc)
130pub type CFBinaryHeapApplierFunction =
131 Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
132
133/// This is the type of a reference to CFBinaryHeaps.
134///
135/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbinaryheap?language=objc)
136#[repr(C)]
137pub struct CFBinaryHeap {
138 inner: [u8; 0],
139 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
140}
141
142cf_type!(
143 #[encoding_name = "__CFBinaryHeap"]
144 unsafe impl CFBinaryHeap {}
145);
146
147#[cfg(feature = "CFBase")]
148unsafe impl ConcreteType for CFBinaryHeap {
149 /// Returns the type identifier of all CFBinaryHeap instances.
150 #[doc(alias = "CFBinaryHeapGetTypeID")]
151 #[inline]
152 fn type_id() -> CFTypeID {
153 extern "C-unwind" {
154 fn CFBinaryHeapGetTypeID() -> CFTypeID;
155 }
156 unsafe { CFBinaryHeapGetTypeID() }
157 }
158}
159
160/// Creates a new mutable binary heap with the given values.
161///
162/// Parameter `allocator`: The CFAllocator which should be used to allocate
163/// memory for the binary heap and its storage for values. This
164/// parameter may be NULL in which case the current default
165/// CFAllocator is used. If this reference is not a valid
166/// CFAllocator, the behavior is undefined.
167///
168/// Parameter `capacity`: A hint about the number of values that will be held
169/// by the CFBinaryHeap. Pass 0 for no hint. The implementation may
170/// ignore this hint, or may use it to optimize various
171/// operations. A heap's actual capacity is only limited by
172/// address space and available memory constraints). If this
173/// parameter is negative, the behavior is undefined.
174///
175/// Parameter `callBacks`: A pointer to a CFBinaryHeapCallBacks structure
176/// initialized with the callbacks for the binary heap to use on
177/// each value in the binary heap. A copy of the contents of the
178/// callbacks structure is made, so that a pointer to a structure
179/// on the stack can be passed in, or can be reused for multiple
180/// binary heap creations. If the version field of this callbacks
181/// structure is not one of the defined ones for CFBinaryHeap, the
182/// behavior is undefined. The retain field may be NULL, in which
183/// case the CFBinaryHeap will do nothing to add a retain to values
184/// as they are put into the binary heap. The release field may be
185/// NULL, in which case the CFBinaryHeap will do nothing to remove
186/// the binary heap's retain (if any) on the values when the
187/// heap is destroyed or a key-value pair is removed. If the
188/// copyDescription field is NULL, the binary heap will create a
189/// simple description for a value. If the equal field is NULL, the
190/// binary heap will use pointer equality to test for equality of
191/// values. This callbacks parameter itself may be NULL, which is
192/// treated as if a valid structure of version 0 with all fields
193/// NULL had been passed in. Otherwise,
194/// if any of the fields are not valid pointers to functions
195/// of the correct type, or this parameter is not a valid
196/// pointer to a CFBinaryHeapCallBacks callbacks structure,
197/// the behavior is undefined. If any of the values put into the
198/// binary heap is not one understood by one of the callback functions
199/// the behavior when that callback function is used is undefined.
200///
201/// Parameter `compareContext`: A pointer to a CFBinaryHeapCompareContext structure.
202///
203/// Returns: A reference to the new CFBinaryHeap.
204#[cfg(feature = "CFBase")]
205#[inline]
206pub unsafe extern "C-unwind" fn CFBinaryHeapCreate(
207 allocator: Option<&CFAllocator>,
208 capacity: CFIndex,
209 call_backs: *const CFBinaryHeapCallBacks,
210 compare_context: *const CFBinaryHeapCompareContext,
211) -> Option<CFRetained<CFBinaryHeap>> {
212 extern "C-unwind" {
213 fn CFBinaryHeapCreate(
214 allocator: Option<&CFAllocator>,
215 capacity: CFIndex,
216 call_backs: *const CFBinaryHeapCallBacks,
217 compare_context: *const CFBinaryHeapCompareContext,
218 ) -> Option<NonNull<CFBinaryHeap>>;
219 }
220 let ret = unsafe { CFBinaryHeapCreate(allocator, capacity, call_backs, compare_context) };
221 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
222}
223
224/// Creates a new mutable binary heap with the values from the given binary heap.
225///
226/// Parameter `allocator`: The CFAllocator which should be used to allocate
227/// memory for the binary heap and its storage for values. This
228/// parameter may be NULL in which case the current default
229/// CFAllocator is used. If this reference is not a valid
230/// CFAllocator, the behavior is undefined.
231///
232/// Parameter `capacity`: A hint about the number of values that will be held
233/// by the CFBinaryHeap. Pass 0 for no hint. The implementation may
234/// ignore this hint, or may use it to optimize various
235/// operations. A heap's actual capacity is only limited by
236/// address space and available memory constraints).
237/// This parameter must be greater than or equal
238/// to the count of the heap which is to be copied, or the
239/// behavior is undefined. If this parameter is negative, the
240/// behavior is undefined.
241///
242/// Parameter `heap`: The binary heap which is to be copied. The values from the
243/// binary heap are copied as pointers into the new binary heap (that is,
244/// the values themselves are copied, not that which the values
245/// point to, if anything). However, the values are also
246/// retained by the new binary heap. The count of the new binary will
247/// be the same as the given binary heap. The new binary heap uses the same
248/// callbacks as the binary heap to be copied. If this parameter is
249/// not a valid CFBinaryHeap, the behavior is undefined.
250///
251/// Returns: A reference to the new mutable binary heap.
252#[cfg(feature = "CFBase")]
253#[inline]
254pub unsafe extern "C-unwind" fn CFBinaryHeapCreateCopy(
255 allocator: Option<&CFAllocator>,
256 capacity: CFIndex,
257 heap: Option<&CFBinaryHeap>,
258) -> Option<CFRetained<CFBinaryHeap>> {
259 extern "C-unwind" {
260 fn CFBinaryHeapCreateCopy(
261 allocator: Option<&CFAllocator>,
262 capacity: CFIndex,
263 heap: Option<&CFBinaryHeap>,
264 ) -> Option<NonNull<CFBinaryHeap>>;
265 }
266 let ret = unsafe { CFBinaryHeapCreateCopy(allocator, capacity, heap) };
267 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
268}
269
270extern "C-unwind" {
271 /// Returns the number of values currently in the binary heap.
272 ///
273 /// Parameter `heap`: The binary heap to be queried. If this parameter is not a valid
274 /// CFBinaryHeap, the behavior is undefined.
275 ///
276 /// Returns: The number of values in the binary heap.
277 #[cfg(feature = "CFBase")]
278 pub fn CFBinaryHeapGetCount(heap: &CFBinaryHeap) -> CFIndex;
279}
280
281extern "C-unwind" {
282 /// Counts the number of times the given value occurs in the binary heap.
283 ///
284 /// Parameter `heap`: The binary heap to be searched. If this parameter is not a
285 /// valid CFBinaryHeap, the behavior is undefined.
286 ///
287 /// Parameter `value`: The value for which to find matches in the binary heap. The
288 /// compare() callback provided when the binary heap was created is
289 /// used to compare. If the compare() callback was NULL, pointer
290 /// equality (in C, ==) is used. If value, or any of the values
291 /// in the binary heap, are not understood by the compare() callback,
292 /// the behavior is undefined.
293 ///
294 /// Returns: The number of times the given value occurs in the binary heap.
295 #[cfg(feature = "CFBase")]
296 pub fn CFBinaryHeapGetCountOfValue(heap: &CFBinaryHeap, value: *const c_void) -> CFIndex;
297}
298
299/// Reports whether or not the value is in the binary heap.
300///
301/// Parameter `heap`: The binary heap to be searched. If this parameter is not a
302/// valid CFBinaryHeap, the behavior is undefined.
303///
304/// Parameter `value`: The value for which to find matches in the binary heap. The
305/// compare() callback provided when the binary heap was created is
306/// used to compare. If the compare() callback was NULL, pointer
307/// equality (in C, ==) is used. If value, or any of the values
308/// in the binary heap, are not understood by the compare() callback,
309/// the behavior is undefined.
310///
311/// Returns: true, if the value is in the specified binary heap, otherwise false.
312#[inline]
313pub unsafe extern "C-unwind" fn CFBinaryHeapContainsValue(
314 heap: &CFBinaryHeap,
315 value: *const c_void,
316) -> bool {
317 extern "C-unwind" {
318 fn CFBinaryHeapContainsValue(heap: &CFBinaryHeap, value: *const c_void) -> Boolean;
319 }
320 let ret = unsafe { CFBinaryHeapContainsValue(heap, value) };
321 ret != 0
322}
323
324extern "C-unwind" {
325 /// Returns the minimum value is in the binary heap. If the heap contains several equal
326 /// minimum values, any one may be returned.
327 ///
328 /// Parameter `heap`: The binary heap to be searched. If this parameter is not a
329 /// valid CFBinaryHeap, the behavior is undefined.
330 ///
331 /// Returns: A reference to the minimum value in the binary heap, or NULL if the
332 /// binary heap contains no values.
333 pub fn CFBinaryHeapGetMinimum(heap: &CFBinaryHeap) -> *const c_void;
334}
335
336/// Returns the minimum value is in the binary heap, if present. If the heap contains several equal
337/// minimum values, any one may be returned.
338///
339/// Parameter `heap`: The binary heap to be searched. If this parameter is not a
340/// valid CFBinaryHeap, the behavior is undefined.
341///
342/// Parameter `value`: A C pointer to pointer-sized storage to be filled with the minimum value in
343/// the binary heap. If this value is not a valid C pointer to a pointer-sized block
344/// of storage, the result is undefined. If the result of the function is false, the value
345/// stored at this address is undefined.
346///
347/// Returns: true, if a minimum value was found in the specified binary heap, otherwise false.
348#[inline]
349pub unsafe extern "C-unwind" fn CFBinaryHeapGetMinimumIfPresent(
350 heap: &CFBinaryHeap,
351 value: *mut *const c_void,
352) -> bool {
353 extern "C-unwind" {
354 fn CFBinaryHeapGetMinimumIfPresent(
355 heap: &CFBinaryHeap,
356 value: *mut *const c_void,
357 ) -> Boolean;
358 }
359 let ret = unsafe { CFBinaryHeapGetMinimumIfPresent(heap, value) };
360 ret != 0
361}
362
363extern "C-unwind" {
364 /// Fills the buffer with values from the binary heap.
365 ///
366 /// Parameter `heap`: The binary heap to be queried. If this parameter is not a
367 /// valid CFBinaryHeap, the behavior is undefined.
368 ///
369 /// Parameter `values`: A C array of pointer-sized values to be filled with
370 /// values from the binary heap. The values in the C array are ordered
371 /// from least to greatest. If this parameter is not a valid pointer to a
372 /// C array of at least CFBinaryHeapGetCount() pointers, the behavior is undefined.
373 pub fn CFBinaryHeapGetValues(heap: &CFBinaryHeap, values: *mut *const c_void);
374}
375
376extern "C-unwind" {
377 /// Calls a function once for each value in the binary heap.
378 ///
379 /// Parameter `heap`: The binary heap to be operated upon. If this parameter is not a
380 /// valid CFBinaryHeap, the behavior is undefined.
381 ///
382 /// Parameter `applier`: The callback function to call once for each value in
383 /// the given binary heap. If this parameter is not a
384 /// pointer to a function of the correct prototype, the behavior
385 /// is undefined. If there are values in the binary heap which the
386 /// applier function does not expect or cannot properly apply
387 /// to, the behavior is undefined.
388 ///
389 /// Parameter `context`: A pointer-sized user-defined value, which is passed
390 /// as the second parameter to the applier function, but is
391 /// otherwise unused by this function. If the context is not
392 /// what is expected by the applier function, the behavior is
393 /// undefined.
394 pub fn CFBinaryHeapApplyFunction(
395 heap: &CFBinaryHeap,
396 applier: CFBinaryHeapApplierFunction,
397 context: *mut c_void,
398 );
399}
400
401extern "C-unwind" {
402 /// Adds the value to the binary heap.
403 ///
404 /// Parameter `heap`: The binary heap to which the value is to be added. If this parameter is not a
405 /// valid mutable CFBinaryHeap, the behavior is undefined.
406 ///
407 /// Parameter `value`: The value to add to the binary heap. The value is retained by
408 /// the binary heap using the retain callback provided when the binary heap
409 /// was created. If the value is not of the sort expected by the
410 /// retain callback, the behavior is undefined.
411 pub fn CFBinaryHeapAddValue(heap: &CFBinaryHeap, value: *const c_void);
412}
413
414extern "C-unwind" {
415 /// Removes the minimum value from the binary heap.
416 ///
417 /// Parameter `heap`: The binary heap from which the minimum value is to be removed. If this
418 /// parameter is not a valid mutable CFBinaryHeap, the behavior is undefined.
419 pub fn CFBinaryHeapRemoveMinimumValue(heap: &CFBinaryHeap);
420}
421
422extern "C-unwind" {
423 /// Removes all the values from the binary heap, making it empty.
424 ///
425 /// Parameter `heap`: The binary heap from which all of the values are to be
426 /// removed. If this parameter is not a valid mutable CFBinaryHeap,
427 /// the behavior is undefined.
428 pub fn CFBinaryHeapRemoveAllValues(heap: &CFBinaryHeap);
429}