Skip to main content

objc2_core_foundation/generated/
CFBag.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/cfbagretaincallback?language=objc)
13pub type CFBagRetainCallBack =
14    Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void>;
15
16/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagreleasecallback?language=objc)
17pub type CFBagReleaseCallBack =
18    Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>;
19
20/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagcopydescriptioncallback?language=objc)
21pub type CFBagCopyDescriptionCallBack =
22    Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
23
24/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagequalcallback?language=objc)
25pub type CFBagEqualCallBack =
26    Option<unsafe extern "C-unwind" fn(*const c_void, *const c_void) -> Boolean>;
27
28/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbaghashcallback?language=objc)
29pub type CFBagHashCallBack = Option<unsafe extern "C-unwind" fn(*const c_void) -> CFHashCode>;
30
31/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagcallbacks?language=objc)
32#[repr(C)]
33#[allow(unpredictable_function_pointer_comparisons)]
34#[derive(Clone, Copy, Debug, PartialEq)]
35pub struct CFBagCallBacks {
36    pub version: CFIndex,
37    pub retain: CFBagRetainCallBack,
38    pub release: CFBagReleaseCallBack,
39    pub copyDescription: CFBagCopyDescriptionCallBack,
40    pub equal: CFBagEqualCallBack,
41    pub hash: CFBagHashCallBack,
42}
43
44#[cfg(feature = "objc2")]
45unsafe impl Encode for CFBagCallBacks {
46    const ENCODING: Encoding = Encoding::Struct(
47        "?",
48        &[
49            <CFIndex>::ENCODING,
50            <CFBagRetainCallBack>::ENCODING,
51            <CFBagReleaseCallBack>::ENCODING,
52            <CFBagCopyDescriptionCallBack>::ENCODING,
53            <CFBagEqualCallBack>::ENCODING,
54            <CFBagHashCallBack>::ENCODING,
55        ],
56    );
57}
58
59#[cfg(feature = "objc2")]
60unsafe impl RefEncode for CFBagCallBacks {
61    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
62}
63
64extern "C" {
65    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcftypebagcallbacks?language=objc)
66    pub static kCFTypeBagCallBacks: CFBagCallBacks;
67}
68
69extern "C" {
70    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcopystringbagcallbacks?language=objc)
71    pub static kCFCopyStringBagCallBacks: CFBagCallBacks;
72}
73
74/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbagapplierfunction?language=objc)
75pub type CFBagApplierFunction = Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
76
77/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfbag?language=objc)
78#[doc(alias = "CFBagRef")]
79#[repr(C)]
80pub struct CFBag<T: ?Sized = Opaque> {
81    inner: [u8; 0],
82    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
83    _generics: PhantomData<(*mut T,)>,
84}
85
86cf_type!(
87    unsafe impl<T: ?Sized> CFBag<T> {}
88);
89#[cfg(feature = "objc2")]
90cf_objc2_type!(
91    unsafe impl<T: ?Sized> RefEncode<"__CFBag"> for CFBag<T> {}
92);
93
94impl<T: ?Sized> CFBag<T> {
95    /// Unchecked conversion of the generic parameter.
96    ///
97    /// # Safety
98    ///
99    /// The generic must be valid to reinterpret as the given type.
100    #[inline]
101    pub unsafe fn cast_unchecked<NewT: ?Sized>(&self) -> &CFBag<NewT> {
102        unsafe { &*((self as *const Self).cast()) }
103    }
104
105    /// Convert to the opaque/untyped variant.
106    #[inline]
107    pub fn as_opaque(&self) -> &CFBag {
108        unsafe { self.cast_unchecked() }
109    }
110}
111
112/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutablebag?language=objc)
113#[doc(alias = "CFMutableBagRef")]
114#[repr(C)]
115pub struct CFMutableBag<T: ?Sized = Opaque> {
116    inner: [u8; 0],
117    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
118    _generics: PhantomData<(*mut T,)>,
119}
120
121cf_type!(
122    unsafe impl<T: ?Sized> CFMutableBag<T>: CFBag<T> {}
123);
124#[cfg(feature = "objc2")]
125cf_objc2_type!(
126    unsafe impl<T: ?Sized> RefEncode<"__CFBag"> for CFMutableBag<T> {}
127);
128
129impl<T: ?Sized> CFMutableBag<T> {
130    /// Unchecked conversion of the generic parameter.
131    ///
132    /// # Safety
133    ///
134    /// The generic must be valid to reinterpret as the given type.
135    #[inline]
136    pub unsafe fn cast_unchecked<NewT: ?Sized>(&self) -> &CFMutableBag<NewT> {
137        unsafe { &*((self as *const Self).cast()) }
138    }
139
140    /// Convert to the opaque/untyped variant.
141    #[inline]
142    pub fn as_opaque(&self) -> &CFMutableBag {
143        unsafe { self.cast_unchecked() }
144    }
145}
146
147unsafe impl ConcreteType for CFBag {
148    #[doc(alias = "CFBagGetTypeID")]
149    #[inline]
150    fn type_id() -> CFTypeID {
151        extern "C-unwind" {
152            fn CFBagGetTypeID() -> CFTypeID;
153        }
154        unsafe { CFBagGetTypeID() }
155    }
156}
157
158impl CFBag {
159    /// # Safety
160    ///
161    /// - `allocator` might not allow `None`.
162    /// - `values` must be a valid pointer.
163    /// - `call_backs` must be a valid pointer.
164    #[doc(alias = "CFBagCreate")]
165    #[inline]
166    pub unsafe fn new(
167        allocator: Option<&CFAllocator>,
168        values: *mut *const c_void,
169        num_values: CFIndex,
170        call_backs: *const CFBagCallBacks,
171    ) -> Option<CFRetained<CFBag>> {
172        extern "C-unwind" {
173            fn CFBagCreate(
174                allocator: Option<&CFAllocator>,
175                values: *mut *const c_void,
176                num_values: CFIndex,
177                call_backs: *const CFBagCallBacks,
178            ) -> Option<NonNull<CFBag>>;
179        }
180        let ret = unsafe { CFBagCreate(allocator, values, num_values, call_backs) };
181        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
182    }
183
184    /// # Safety
185    ///
186    /// - `allocator` might not allow `None`.
187    /// - `the_bag` generic must be of the correct type.
188    /// - `the_bag` might not allow `None`.
189    #[doc(alias = "CFBagCreateCopy")]
190    #[inline]
191    pub unsafe fn new_copy(
192        allocator: Option<&CFAllocator>,
193        the_bag: Option<&CFBag>,
194    ) -> Option<CFRetained<CFBag>> {
195        extern "C-unwind" {
196            fn CFBagCreateCopy(
197                allocator: Option<&CFAllocator>,
198                the_bag: Option<&CFBag>,
199            ) -> Option<NonNull<CFBag>>;
200        }
201        let ret = unsafe { CFBagCreateCopy(allocator, the_bag) };
202        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
203    }
204}
205
206impl CFMutableBag {
207    /// # Safety
208    ///
209    /// - `allocator` might not allow `None`.
210    /// - `call_backs` must be a valid pointer.
211    /// - The returned generic must be of the correct type.
212    #[doc(alias = "CFBagCreateMutable")]
213    #[inline]
214    pub unsafe fn new(
215        allocator: Option<&CFAllocator>,
216        capacity: CFIndex,
217        call_backs: *const CFBagCallBacks,
218    ) -> Option<CFRetained<CFMutableBag>> {
219        extern "C-unwind" {
220            fn CFBagCreateMutable(
221                allocator: Option<&CFAllocator>,
222                capacity: CFIndex,
223                call_backs: *const CFBagCallBacks,
224            ) -> Option<NonNull<CFMutableBag>>;
225        }
226        let ret = unsafe { CFBagCreateMutable(allocator, capacity, call_backs) };
227        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
228    }
229
230    /// # Safety
231    ///
232    /// - `allocator` might not allow `None`.
233    /// - `the_bag` generic must be of the correct type.
234    /// - `the_bag` might not allow `None`.
235    /// - The returned generic must be of the correct type.
236    #[doc(alias = "CFBagCreateMutableCopy")]
237    #[inline]
238    pub unsafe fn new_copy(
239        allocator: Option<&CFAllocator>,
240        capacity: CFIndex,
241        the_bag: Option<&CFBag>,
242    ) -> Option<CFRetained<CFMutableBag>> {
243        extern "C-unwind" {
244            fn CFBagCreateMutableCopy(
245                allocator: Option<&CFAllocator>,
246                capacity: CFIndex,
247                the_bag: Option<&CFBag>,
248            ) -> Option<NonNull<CFMutableBag>>;
249        }
250        let ret = unsafe { CFBagCreateMutableCopy(allocator, capacity, the_bag) };
251        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
252    }
253}
254
255impl CFBag {
256    /// # Safety
257    ///
258    /// `the_bag` generic must be of the correct type.
259    #[doc(alias = "CFBagGetCount")]
260    #[inline]
261    pub unsafe fn count(&self) -> CFIndex {
262        extern "C-unwind" {
263            fn CFBagGetCount(the_bag: &CFBag) -> CFIndex;
264        }
265        unsafe { CFBagGetCount(self) }
266    }
267
268    /// # Safety
269    ///
270    /// - `the_bag` generic must be of the correct type.
271    /// - `value` must be a valid pointer.
272    #[doc(alias = "CFBagGetCountOfValue")]
273    #[inline]
274    pub unsafe fn count_of_value(&self, value: *const c_void) -> CFIndex {
275        extern "C-unwind" {
276            fn CFBagGetCountOfValue(the_bag: &CFBag, value: *const c_void) -> CFIndex;
277        }
278        unsafe { CFBagGetCountOfValue(self, value) }
279    }
280
281    /// # Safety
282    ///
283    /// - `the_bag` generic must be of the correct type.
284    /// - `value` must be a valid pointer.
285    #[doc(alias = "CFBagContainsValue")]
286    #[inline]
287    pub unsafe fn contains_value(&self, value: *const c_void) -> bool {
288        extern "C-unwind" {
289            fn CFBagContainsValue(the_bag: &CFBag, value: *const c_void) -> Boolean;
290        }
291        let ret = unsafe { CFBagContainsValue(self, value) };
292        ret != 0
293    }
294
295    /// # Safety
296    ///
297    /// - `the_bag` generic must be of the correct type.
298    /// - `value` must be a valid pointer.
299    #[doc(alias = "CFBagGetValue")]
300    #[inline]
301    pub unsafe fn value(&self, value: *const c_void) -> *const c_void {
302        extern "C-unwind" {
303            fn CFBagGetValue(the_bag: &CFBag, value: *const c_void) -> *const c_void;
304        }
305        unsafe { CFBagGetValue(self, value) }
306    }
307
308    /// # Safety
309    ///
310    /// - `the_bag` generic must be of the correct type.
311    /// - `candidate` must be a valid pointer.
312    /// - `value` must be a valid pointer.
313    #[doc(alias = "CFBagGetValueIfPresent")]
314    #[inline]
315    pub unsafe fn value_if_present(
316        &self,
317        candidate: *const c_void,
318        value: *mut *const c_void,
319    ) -> bool {
320        extern "C-unwind" {
321            fn CFBagGetValueIfPresent(
322                the_bag: &CFBag,
323                candidate: *const c_void,
324                value: *mut *const c_void,
325            ) -> Boolean;
326        }
327        let ret = unsafe { CFBagGetValueIfPresent(self, candidate, value) };
328        ret != 0
329    }
330
331    /// # Safety
332    ///
333    /// - `the_bag` generic must be of the correct type.
334    /// - `values` must be a valid pointer.
335    #[doc(alias = "CFBagGetValues")]
336    #[inline]
337    pub unsafe fn values(&self, values: *mut *const c_void) {
338        extern "C-unwind" {
339            fn CFBagGetValues(the_bag: &CFBag, values: *mut *const c_void);
340        }
341        unsafe { CFBagGetValues(self, values) }
342    }
343
344    /// # Safety
345    ///
346    /// - `the_bag` generic must be of the correct type.
347    /// - `applier` must be implemented correctly.
348    /// - `context` must be a valid pointer.
349    #[doc(alias = "CFBagApplyFunction")]
350    #[inline]
351    pub unsafe fn apply_function(&self, applier: CFBagApplierFunction, context: *mut c_void) {
352        extern "C-unwind" {
353            fn CFBagApplyFunction(
354                the_bag: &CFBag,
355                applier: CFBagApplierFunction,
356                context: *mut c_void,
357            );
358        }
359        unsafe { CFBagApplyFunction(self, applier, context) }
360    }
361}
362
363impl CFMutableBag {
364    /// # Safety
365    ///
366    /// - `the_bag` generic must be of the correct type.
367    /// - `the_bag` might not allow `None`.
368    /// - `value` must be a valid pointer.
369    #[doc(alias = "CFBagAddValue")]
370    #[inline]
371    pub unsafe fn add_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
372        extern "C-unwind" {
373            fn CFBagAddValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
374        }
375        unsafe { CFBagAddValue(the_bag, value) }
376    }
377
378    /// # Safety
379    ///
380    /// - `the_bag` generic must be of the correct type.
381    /// - `the_bag` might not allow `None`.
382    /// - `value` must be a valid pointer.
383    #[doc(alias = "CFBagReplaceValue")]
384    #[inline]
385    pub unsafe fn replace_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
386        extern "C-unwind" {
387            fn CFBagReplaceValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
388        }
389        unsafe { CFBagReplaceValue(the_bag, value) }
390    }
391
392    /// # Safety
393    ///
394    /// - `the_bag` generic must be of the correct type.
395    /// - `the_bag` might not allow `None`.
396    /// - `value` must be a valid pointer.
397    #[doc(alias = "CFBagSetValue")]
398    #[inline]
399    pub unsafe fn set_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
400        extern "C-unwind" {
401            fn CFBagSetValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
402        }
403        unsafe { CFBagSetValue(the_bag, value) }
404    }
405
406    /// # Safety
407    ///
408    /// - `the_bag` generic must be of the correct type.
409    /// - `the_bag` might not allow `None`.
410    /// - `value` must be a valid pointer.
411    #[doc(alias = "CFBagRemoveValue")]
412    #[inline]
413    pub unsafe fn remove_value(the_bag: Option<&CFMutableBag>, value: *const c_void) {
414        extern "C-unwind" {
415            fn CFBagRemoveValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
416        }
417        unsafe { CFBagRemoveValue(the_bag, value) }
418    }
419
420    /// # Safety
421    ///
422    /// - `the_bag` generic must be of the correct type.
423    /// - `the_bag` might not allow `None`.
424    #[doc(alias = "CFBagRemoveAllValues")]
425    #[inline]
426    pub unsafe fn remove_all_values(the_bag: Option<&CFMutableBag>) {
427        extern "C-unwind" {
428            fn CFBagRemoveAllValues(the_bag: Option<&CFMutableBag>);
429        }
430        unsafe { CFBagRemoveAllValues(the_bag) }
431    }
432}
433
434#[deprecated = "renamed to `CFBag::new`"]
435#[inline]
436pub unsafe extern "C-unwind" fn CFBagCreate(
437    allocator: Option<&CFAllocator>,
438    values: *mut *const c_void,
439    num_values: CFIndex,
440    call_backs: *const CFBagCallBacks,
441) -> Option<CFRetained<CFBag>> {
442    extern "C-unwind" {
443        fn CFBagCreate(
444            allocator: Option<&CFAllocator>,
445            values: *mut *const c_void,
446            num_values: CFIndex,
447            call_backs: *const CFBagCallBacks,
448        ) -> Option<NonNull<CFBag>>;
449    }
450    let ret = unsafe { CFBagCreate(allocator, values, num_values, call_backs) };
451    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
452}
453
454#[deprecated = "renamed to `CFBag::new_copy`"]
455#[inline]
456pub unsafe extern "C-unwind" fn CFBagCreateCopy(
457    allocator: Option<&CFAllocator>,
458    the_bag: Option<&CFBag>,
459) -> Option<CFRetained<CFBag>> {
460    extern "C-unwind" {
461        fn CFBagCreateCopy(
462            allocator: Option<&CFAllocator>,
463            the_bag: Option<&CFBag>,
464        ) -> Option<NonNull<CFBag>>;
465    }
466    let ret = unsafe { CFBagCreateCopy(allocator, the_bag) };
467    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
468}
469
470#[deprecated = "renamed to `CFMutableBag::new`"]
471#[inline]
472pub unsafe extern "C-unwind" fn CFBagCreateMutable(
473    allocator: Option<&CFAllocator>,
474    capacity: CFIndex,
475    call_backs: *const CFBagCallBacks,
476) -> Option<CFRetained<CFMutableBag>> {
477    extern "C-unwind" {
478        fn CFBagCreateMutable(
479            allocator: Option<&CFAllocator>,
480            capacity: CFIndex,
481            call_backs: *const CFBagCallBacks,
482        ) -> Option<NonNull<CFMutableBag>>;
483    }
484    let ret = unsafe { CFBagCreateMutable(allocator, capacity, call_backs) };
485    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
486}
487
488#[deprecated = "renamed to `CFMutableBag::new_copy`"]
489#[inline]
490pub unsafe extern "C-unwind" fn CFBagCreateMutableCopy(
491    allocator: Option<&CFAllocator>,
492    capacity: CFIndex,
493    the_bag: Option<&CFBag>,
494) -> Option<CFRetained<CFMutableBag>> {
495    extern "C-unwind" {
496        fn CFBagCreateMutableCopy(
497            allocator: Option<&CFAllocator>,
498            capacity: CFIndex,
499            the_bag: Option<&CFBag>,
500        ) -> Option<NonNull<CFMutableBag>>;
501    }
502    let ret = unsafe { CFBagCreateMutableCopy(allocator, capacity, the_bag) };
503    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
504}
505
506extern "C-unwind" {
507    #[deprecated = "renamed to `CFBag::count`"]
508    pub fn CFBagGetCount(the_bag: &CFBag) -> CFIndex;
509}
510
511extern "C-unwind" {
512    #[deprecated = "renamed to `CFBag::count_of_value`"]
513    pub fn CFBagGetCountOfValue(the_bag: &CFBag, value: *const c_void) -> CFIndex;
514}
515
516#[deprecated = "renamed to `CFBag::contains_value`"]
517#[inline]
518pub unsafe extern "C-unwind" fn CFBagContainsValue(the_bag: &CFBag, value: *const c_void) -> bool {
519    extern "C-unwind" {
520        fn CFBagContainsValue(the_bag: &CFBag, value: *const c_void) -> Boolean;
521    }
522    let ret = unsafe { CFBagContainsValue(the_bag, value) };
523    ret != 0
524}
525
526extern "C-unwind" {
527    #[deprecated = "renamed to `CFBag::value`"]
528    pub fn CFBagGetValue(the_bag: &CFBag, value: *const c_void) -> *const c_void;
529}
530
531#[deprecated = "renamed to `CFBag::value_if_present`"]
532#[inline]
533pub unsafe extern "C-unwind" fn CFBagGetValueIfPresent(
534    the_bag: &CFBag,
535    candidate: *const c_void,
536    value: *mut *const c_void,
537) -> bool {
538    extern "C-unwind" {
539        fn CFBagGetValueIfPresent(
540            the_bag: &CFBag,
541            candidate: *const c_void,
542            value: *mut *const c_void,
543        ) -> Boolean;
544    }
545    let ret = unsafe { CFBagGetValueIfPresent(the_bag, candidate, value) };
546    ret != 0
547}
548
549extern "C-unwind" {
550    #[deprecated = "renamed to `CFBag::values`"]
551    pub fn CFBagGetValues(the_bag: &CFBag, values: *mut *const c_void);
552}
553
554extern "C-unwind" {
555    #[deprecated = "renamed to `CFBag::apply_function`"]
556    pub fn CFBagApplyFunction(the_bag: &CFBag, applier: CFBagApplierFunction, context: *mut c_void);
557}
558
559extern "C-unwind" {
560    #[deprecated = "renamed to `CFMutableBag::add_value`"]
561    pub fn CFBagAddValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
562}
563
564extern "C-unwind" {
565    #[deprecated = "renamed to `CFMutableBag::replace_value`"]
566    pub fn CFBagReplaceValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
567}
568
569extern "C-unwind" {
570    #[deprecated = "renamed to `CFMutableBag::set_value`"]
571    pub fn CFBagSetValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
572}
573
574extern "C-unwind" {
575    #[deprecated = "renamed to `CFMutableBag::remove_value`"]
576    pub fn CFBagRemoveValue(the_bag: Option<&CFMutableBag>, value: *const c_void);
577}
578
579extern "C-unwind" {
580    #[deprecated = "renamed to `CFMutableBag::remove_all_values`"]
581    pub fn CFBagRemoveAllValues(the_bag: Option<&CFMutableBag>);
582}