objc2_core_foundation/generated/CFSet.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/// Type of the callback function used by CFSets for retaining values.
13///
14/// Parameter `allocator`: The allocator of the CFSet.
15///
16/// Parameter `value`: The value to retain.
17///
18/// Returns: The value to store in the set, which is usually the value
19/// parameter passed to this callback, but may be a different
20/// value if a different value should be stored in the set.
21///
22/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetretaincallback?language=objc)
23pub type CFSetRetainCallBack =
24 Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void) -> *const c_void>;
25
26/// Type of the callback function used by CFSets for releasing a retain on values.
27///
28/// Parameter `allocator`: The allocator of the CFSet.
29///
30/// Parameter `value`: The value to release.
31///
32/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetreleasecallback?language=objc)
33pub type CFSetReleaseCallBack =
34 Option<unsafe extern "C-unwind" fn(*const CFAllocator, *const c_void)>;
35
36/// Type of the callback function used by CFSets for describing values.
37///
38/// Parameter `value`: The value to describe.
39///
40/// Returns: A description of the specified value.
41///
42/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetcopydescriptioncallback?language=objc)
43pub type CFSetCopyDescriptionCallBack =
44 Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
45
46/// Type of the callback function used by CFSets for comparing values.
47///
48/// Parameter `value1`: The first value to compare.
49///
50/// Parameter `value2`: The second value to compare.
51///
52/// Returns: True if the values are equal, otherwise false.
53///
54/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetequalcallback?language=objc)
55pub type CFSetEqualCallBack =
56 Option<unsafe extern "C-unwind" fn(*const c_void, *const c_void) -> Boolean>;
57
58/// Type of the callback function used by CFSets for hashing values.
59///
60/// Parameter `value`: The value to hash.
61///
62/// Returns: The hash of the value.
63///
64/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsethashcallback?language=objc)
65pub type CFSetHashCallBack = Option<unsafe extern "C-unwind" fn(*const c_void) -> CFHashCode>;
66
67/// Structure containing the callbacks of a CFSet.
68/// Field: version The version number of the structure type being passed
69/// in as a parameter to the CFSet creation functions. This
70/// structure is version 0.
71/// Field: retain The callback used to add a retain for the set on
72/// values as they are put into the set. This callback returns
73/// the value to store in the set, which is usually the value
74/// parameter passed to this callback, but may be a different
75/// value if a different value should be stored in the set.
76/// The set's allocator is passed as the first argument.
77/// Field: release The callback used to remove a retain previously added
78/// for the set from values as they are removed from the
79/// set. The set's allocator is passed as the first
80/// argument.
81/// Field: copyDescription The callback used to create a descriptive
82/// string representation of each value in the set. This is
83/// used by the CFCopyDescription() function.
84/// Field: equal The callback used to compare values in the set for
85/// equality for some operations.
86/// Field: hash The callback used to compare values in the set for
87/// uniqueness for some operations.
88///
89/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetcallbacks?language=objc)
90#[repr(C)]
91#[allow(unpredictable_function_pointer_comparisons)]
92#[derive(Clone, Copy, Debug, PartialEq)]
93pub struct CFSetCallBacks {
94 pub version: CFIndex,
95 pub retain: CFSetRetainCallBack,
96 pub release: CFSetReleaseCallBack,
97 pub copyDescription: CFSetCopyDescriptionCallBack,
98 pub equal: CFSetEqualCallBack,
99 pub hash: CFSetHashCallBack,
100}
101
102#[cfg(feature = "objc2")]
103unsafe impl Encode for CFSetCallBacks {
104 const ENCODING: Encoding = Encoding::Struct(
105 "?",
106 &[
107 <CFIndex>::ENCODING,
108 <CFSetRetainCallBack>::ENCODING,
109 <CFSetReleaseCallBack>::ENCODING,
110 <CFSetCopyDescriptionCallBack>::ENCODING,
111 <CFSetEqualCallBack>::ENCODING,
112 <CFSetHashCallBack>::ENCODING,
113 ],
114 );
115}
116
117#[cfg(feature = "objc2")]
118unsafe impl RefEncode for CFSetCallBacks {
119 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
120}
121
122extern "C" {
123 /// Predefined CFSetCallBacks structure containing a set of callbacks
124 /// appropriate for use when the values in a CFSet are all CFTypes.
125 ///
126 /// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcftypesetcallbacks?language=objc)
127 pub static kCFTypeSetCallBacks: CFSetCallBacks;
128}
129
130extern "C" {
131 /// Predefined CFSetCallBacks structure containing a set of callbacks
132 /// appropriate for use when the values in a CFSet should be copies
133 /// of a CFString.
134 ///
135 /// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcopystringsetcallbacks?language=objc)
136 pub static kCFCopyStringSetCallBacks: CFSetCallBacks;
137}
138
139/// Type of the callback function used by the apply functions of
140/// CFSets.
141///
142/// Parameter `value`: The current value from the set.
143///
144/// Parameter `context`: The user-defined context parameter given to the apply
145/// function.
146///
147/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsetapplierfunction?language=objc)
148pub type CFSetApplierFunction = Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
149
150/// This is the type of a reference to immutable CFSets.
151///
152/// This is toll-free bridged with `NSSet`.
153///
154/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfset?language=objc)
155#[doc(alias = "CFSetRef")]
156#[repr(C)]
157pub struct CFSet<T: ?Sized = Opaque> {
158 inner: [u8; 0],
159 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
160 _generics: PhantomData<(*mut T,)>,
161}
162
163cf_type!(
164 unsafe impl<T: ?Sized> CFSet<T> {}
165);
166#[cfg(feature = "objc2")]
167cf_objc2_type!(
168 unsafe impl<T: ?Sized> RefEncode<"__CFSet"> for CFSet<T> {}
169);
170
171impl<T: ?Sized> CFSet<T> {
172 /// Unchecked conversion of the generic parameter.
173 ///
174 /// # Safety
175 ///
176 /// The generic must be valid to reinterpret as the given type.
177 #[inline]
178 pub unsafe fn cast_unchecked<NewT: ?Sized>(&self) -> &CFSet<NewT> {
179 unsafe { &*((self as *const Self).cast()) }
180 }
181
182 /// Convert to the opaque/untyped variant.
183 #[inline]
184 pub fn as_opaque(&self) -> &CFSet {
185 unsafe { self.cast_unchecked() }
186 }
187}
188
189/// This is the type of a reference to mutable CFSets.
190///
191/// This is toll-free bridged with `NSMutableSet`.
192///
193/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutableset?language=objc)
194#[doc(alias = "CFMutableSetRef")]
195#[repr(C)]
196pub struct CFMutableSet<T: ?Sized = Opaque> {
197 inner: [u8; 0],
198 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
199 _generics: PhantomData<(*mut T,)>,
200}
201
202cf_type!(
203 unsafe impl<T: ?Sized> CFMutableSet<T>: CFSet<T> {}
204);
205#[cfg(feature = "objc2")]
206cf_objc2_type!(
207 unsafe impl<T: ?Sized> RefEncode<"__CFSet"> for CFMutableSet<T> {}
208);
209
210impl<T: ?Sized> CFMutableSet<T> {
211 /// Unchecked conversion of the generic parameter.
212 ///
213 /// # Safety
214 ///
215 /// The generic must be valid to reinterpret as the given type.
216 #[inline]
217 pub unsafe fn cast_unchecked<NewT: ?Sized>(&self) -> &CFMutableSet<NewT> {
218 unsafe { &*((self as *const Self).cast()) }
219 }
220
221 /// Convert to the opaque/untyped variant.
222 #[inline]
223 pub fn as_opaque(&self) -> &CFMutableSet {
224 unsafe { self.cast_unchecked() }
225 }
226}
227
228unsafe impl ConcreteType for CFSet {
229 /// Returns the type identifier of all CFSet instances.
230 #[doc(alias = "CFSetGetTypeID")]
231 #[inline]
232 fn type_id() -> CFTypeID {
233 extern "C-unwind" {
234 fn CFSetGetTypeID() -> CFTypeID;
235 }
236 unsafe { CFSetGetTypeID() }
237 }
238}
239
240impl CFSet {
241 /// Creates a new immutable set with the given values.
242 ///
243 /// Parameter `allocator`: The CFAllocator which should be used to allocate
244 /// memory for the set and its storage for values. This
245 /// parameter may be NULL in which case the current default
246 /// CFAllocator is used. If this reference is not a valid
247 /// CFAllocator, the behavior is undefined.
248 ///
249 /// Parameter `values`: A C array of the pointer-sized values to be in the
250 /// set. This C array is not changed or freed by this function.
251 /// If this parameter is not a valid pointer to a C array of at
252 /// least numValues pointers, the behavior is undefined.
253 ///
254 /// Parameter `numValues`: The number of values to copy from the values C
255 /// array into the CFSet. This number will be the count of the
256 /// set. If this parameter is zero, negative, or greater than
257 /// the number of values actually in the values C array, the
258 /// behavior is undefined.
259 ///
260 /// Parameter `callBacks`: A C pointer to a CFSetCallBacks structure
261 /// initialized with the callbacks for the set to use on each
262 /// value in the set. A copy of the contents of the
263 /// callbacks structure is made, so that a pointer to a
264 /// structure on the stack can be passed in, or can be reused
265 /// for multiple set creations. If the version field of this
266 /// callbacks structure is not one of the defined ones for
267 /// CFSet, the behavior is undefined. The retain field may be
268 /// NULL, in which case the CFSet will do nothing to add a
269 /// retain to the contained values for the set. The release
270 /// field may be NULL, in which case the CFSet will do nothing
271 /// to remove the set's retain (if any) on the values when the
272 /// set is destroyed. If the copyDescription field is NULL,
273 /// the set will create a simple description for the value. If
274 /// the equal field is NULL, the set will use pointer equality
275 /// to test for equality of values. The hash field may be NULL,
276 /// in which case the CFSet will determine uniqueness by pointer
277 /// equality. This callbacks parameter
278 /// itself may be NULL, which is treated as if a valid structure
279 /// of version 0 with all fields NULL had been passed in.
280 /// Otherwise, if any of the fields are not valid pointers to
281 /// functions of the correct type, or this parameter is not a
282 /// valid pointer to a CFSetCallBacks callbacks structure,
283 /// the behavior is undefined. If any of the values put into the
284 /// set is not one understood by one of the callback functions
285 /// the behavior when that callback function is used is
286 /// undefined.
287 ///
288 /// Returns: A reference to the new immutable CFSet.
289 ///
290 /// # Safety
291 ///
292 /// - `allocator` might not allow `None`.
293 /// - `values` must be a valid pointer.
294 /// - `call_backs` must be a valid pointer.
295 #[doc(alias = "CFSetCreate")]
296 #[inline]
297 pub unsafe fn new(
298 allocator: Option<&CFAllocator>,
299 values: *mut *const c_void,
300 num_values: CFIndex,
301 call_backs: *const CFSetCallBacks,
302 ) -> Option<CFRetained<CFSet>> {
303 extern "C-unwind" {
304 fn CFSetCreate(
305 allocator: Option<&CFAllocator>,
306 values: *mut *const c_void,
307 num_values: CFIndex,
308 call_backs: *const CFSetCallBacks,
309 ) -> Option<NonNull<CFSet>>;
310 }
311 let ret = unsafe { CFSetCreate(allocator, values, num_values, call_backs) };
312 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
313 }
314
315 /// Creates a new immutable set with the values from the given set.
316 ///
317 /// Parameter `allocator`: The CFAllocator which should be used to allocate
318 /// memory for the set and its storage for values. This
319 /// parameter may be NULL in which case the current default
320 /// CFAllocator is used. If this reference is not a valid
321 /// CFAllocator, the behavior is undefined.
322 ///
323 /// Parameter `theSet`: The set which is to be copied. The values from the
324 /// set are copied as pointers into the new set (that is,
325 /// the values themselves are copied, not that which the values
326 /// point to, if anything). However, the values are also
327 /// retained by the new set. The count of the new set will
328 /// be the same as the copied set. The new set uses the same
329 /// callbacks as the set to be copied. If this parameter is
330 /// not a valid CFSet, the behavior is undefined.
331 ///
332 /// Returns: A reference to the new immutable CFSet.
333 #[doc(alias = "CFSetCreateCopy")]
334 #[inline]
335 pub fn new_copy(
336 allocator: Option<&CFAllocator>,
337 the_set: Option<&CFSet>,
338 ) -> Option<CFRetained<CFSet>> {
339 extern "C-unwind" {
340 fn CFSetCreateCopy(
341 allocator: Option<&CFAllocator>,
342 the_set: Option<&CFSet>,
343 ) -> Option<NonNull<CFSet>>;
344 }
345 let ret = unsafe { CFSetCreateCopy(allocator, the_set) };
346 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
347 }
348}
349
350impl CFMutableSet {
351 /// Creates a new empty mutable set.
352 ///
353 /// Parameter `allocator`: The CFAllocator which should be used to allocate
354 /// memory for the set and its storage for values. This
355 /// parameter may be NULL in which case the current default
356 /// CFAllocator is used. If this reference is not a valid
357 /// CFAllocator, the behavior is undefined.
358 ///
359 /// Parameter `capacity`: A hint about the number of values that will be held
360 /// by the CFSet. Pass 0 for no hint. The implementation may
361 /// ignore this hint, or may use it to optimize various
362 /// operations. A set's actual capacity is only limited by
363 /// address space and available memory constraints). If this
364 /// parameter is negative, the behavior is undefined.
365 ///
366 /// Parameter `callBacks`: A C pointer to a CFSetCallBacks structure
367 /// initialized with the callbacks for the set to use on each
368 /// value in the set. A copy of the contents of the
369 /// callbacks structure is made, so that a pointer to a
370 /// structure on the stack can be passed in, or can be reused
371 /// for multiple set creations. If the version field of this
372 /// callbacks structure is not one of the defined ones for
373 /// CFSet, the behavior is undefined. The retain field may be
374 /// NULL, in which case the CFSet will do nothing to add a
375 /// retain to the contained values for the set. The release
376 /// field may be NULL, in which case the CFSet will do nothing
377 /// to remove the set's retain (if any) on the values when the
378 /// set is destroyed. If the copyDescription field is NULL,
379 /// the set will create a simple description for the value. If
380 /// the equal field is NULL, the set will use pointer equality
381 /// to test for equality of values. The hash field may be NULL,
382 /// in which case the CFSet will determine uniqueness by pointer
383 /// equality. This callbacks parameter
384 /// itself may be NULL, which is treated as if a valid structure
385 /// of version 0 with all fields NULL had been passed in.
386 /// Otherwise, if any of the fields are not valid pointers to
387 /// functions of the correct type, or this parameter is not a
388 /// valid pointer to a CFSetCallBacks callbacks structure,
389 /// the behavior is undefined. If any of the values put into the
390 /// set is not one understood by one of the callback functions
391 /// the behavior when that callback function is used is
392 /// undefined.
393 ///
394 /// Returns: A reference to the new mutable CFSet.
395 ///
396 /// # Safety
397 ///
398 /// - `allocator` might not allow `None`.
399 /// - `call_backs` must be a valid pointer.
400 /// - The returned generic must be of the correct type.
401 #[doc(alias = "CFSetCreateMutable")]
402 #[inline]
403 pub unsafe fn new(
404 allocator: Option<&CFAllocator>,
405 capacity: CFIndex,
406 call_backs: *const CFSetCallBacks,
407 ) -> Option<CFRetained<CFMutableSet>> {
408 extern "C-unwind" {
409 fn CFSetCreateMutable(
410 allocator: Option<&CFAllocator>,
411 capacity: CFIndex,
412 call_backs: *const CFSetCallBacks,
413 ) -> Option<NonNull<CFMutableSet>>;
414 }
415 let ret = unsafe { CFSetCreateMutable(allocator, capacity, call_backs) };
416 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
417 }
418
419 /// Creates a new immutable set with the values from the given set.
420 ///
421 /// Parameter `allocator`: The CFAllocator which should be used to allocate
422 /// memory for the set and its storage for values. This
423 /// parameter may be NULL in which case the current default
424 /// CFAllocator is used. If this reference is not a valid
425 /// CFAllocator, the behavior is undefined.
426 ///
427 /// Parameter `capacity`: A hint about the number of values that will be held
428 /// by the CFSet. Pass 0 for no hint. The implementation may
429 /// ignore this hint, or may use it to optimize various
430 /// operations. A set's actual capacity is only limited by
431 /// address space and available memory constraints).
432 /// This parameter must be greater than or equal
433 /// to the count of the set which is to be copied, or the
434 /// behavior is undefined. If this parameter is negative, the
435 /// behavior is undefined.
436 ///
437 /// Parameter `theSet`: The set which is to be copied. The values from the
438 /// set are copied as pointers into the new set (that is,
439 /// the values themselves are copied, not that which the values
440 /// point to, if anything). However, the values are also
441 /// retained by the new set. The count of the new set will
442 /// be the same as the copied set. The new set uses the same
443 /// callbacks as the set to be copied. If this parameter is
444 /// not a valid CFSet, the behavior is undefined.
445 ///
446 /// Returns: A reference to the new mutable CFSet.
447 ///
448 /// # Safety
449 ///
450 /// - `allocator` might not allow `None`.
451 /// - `the_set` generic must be of the correct type.
452 /// - `the_set` might not allow `None`.
453 /// - The returned generic must be of the correct type.
454 #[doc(alias = "CFSetCreateMutableCopy")]
455 #[inline]
456 pub unsafe fn new_copy(
457 allocator: Option<&CFAllocator>,
458 capacity: CFIndex,
459 the_set: Option<&CFSet>,
460 ) -> Option<CFRetained<CFMutableSet>> {
461 extern "C-unwind" {
462 fn CFSetCreateMutableCopy(
463 allocator: Option<&CFAllocator>,
464 capacity: CFIndex,
465 the_set: Option<&CFSet>,
466 ) -> Option<NonNull<CFMutableSet>>;
467 }
468 let ret = unsafe { CFSetCreateMutableCopy(allocator, capacity, the_set) };
469 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
470 }
471}
472
473impl CFSet {
474 /// Returns the number of values currently in the set.
475 ///
476 /// Parameter `theSet`: The set to be queried. If this parameter is not a valid
477 /// CFSet, the behavior is undefined.
478 ///
479 /// Returns: The number of values in the set.
480 #[doc(alias = "CFSetGetCount")]
481 #[inline]
482 pub fn count(&self) -> CFIndex {
483 extern "C-unwind" {
484 fn CFSetGetCount(the_set: &CFSet) -> CFIndex;
485 }
486 unsafe { CFSetGetCount(self) }
487 }
488
489 /// Counts the number of times the given value occurs in the set. Since
490 /// sets by definition contain only one instance of a value, this function
491 /// is synonymous to CFSetContainsValue.
492 ///
493 /// Parameter `theSet`: The set to be searched. If this parameter is not a
494 /// valid CFSet, the behavior is undefined.
495 ///
496 /// Parameter `value`: The value for which to find matches in the set. The
497 /// equal() callback provided when the set was created is
498 /// used to compare. If the equal() callback was NULL, pointer
499 /// equality (in C, ==) is used. If value, or any of the values
500 /// in the set, are not understood by the equal() callback,
501 /// the behavior is undefined.
502 ///
503 /// Returns: The number of times the given value occurs in the set.
504 ///
505 /// # Safety
506 ///
507 /// - `the_set` generic must be of the correct type.
508 /// - `value` must be a valid pointer.
509 #[doc(alias = "CFSetGetCountOfValue")]
510 #[inline]
511 pub unsafe fn count_of_value(&self, value: *const c_void) -> CFIndex {
512 extern "C-unwind" {
513 fn CFSetGetCountOfValue(the_set: &CFSet, value: *const c_void) -> CFIndex;
514 }
515 unsafe { CFSetGetCountOfValue(self, value) }
516 }
517
518 /// Reports whether or not the value is in the set.
519 ///
520 /// Parameter `theSet`: The set to be searched. If this parameter is not a
521 /// valid CFSet, the behavior is undefined.
522 ///
523 /// Parameter `value`: The value for which to find matches in the set. The
524 /// equal() callback provided when the set was created is
525 /// used to compare. If the equal() callback was NULL, pointer
526 /// equality (in C, ==) is used. If value, or any of the values
527 /// in the set, are not understood by the equal() callback,
528 /// the behavior is undefined.
529 ///
530 /// Returns: true, if the value is in the set, otherwise false.
531 ///
532 /// # Safety
533 ///
534 /// - `the_set` generic must be of the correct type.
535 /// - `value` must be a valid pointer.
536 #[doc(alias = "CFSetContainsValue")]
537 #[inline]
538 pub unsafe fn contains_value(&self, value: *const c_void) -> bool {
539 extern "C-unwind" {
540 fn CFSetContainsValue(the_set: &CFSet, value: *const c_void) -> Boolean;
541 }
542 let ret = unsafe { CFSetContainsValue(self, value) };
543 ret != 0
544 }
545
546 /// Retrieves a value in the set which hashes the same as the specified value.
547 ///
548 /// Parameter `theSet`: The set to be queried. If this parameter is not a
549 /// valid CFSet, the behavior is undefined.
550 ///
551 /// Parameter `value`: The value to retrieve. The equal() callback provided when
552 /// the set was created is used to compare. If the equal() callback
553 /// was NULL, pointer equality (in C, ==) is used. If a value, or
554 /// any of the values in the set, are not understood by the equal()
555 /// callback, the behavior is undefined.
556 ///
557 /// Returns: The value in the set with the given hash.
558 ///
559 /// # Safety
560 ///
561 /// - `the_set` generic must be of the correct type.
562 /// - `value` must be a valid pointer.
563 #[doc(alias = "CFSetGetValue")]
564 #[inline]
565 pub unsafe fn value(&self, value: *const c_void) -> *const c_void {
566 extern "C-unwind" {
567 fn CFSetGetValue(the_set: &CFSet, value: *const c_void) -> *const c_void;
568 }
569 unsafe { CFSetGetValue(self, value) }
570 }
571
572 /// Retrieves a value in the set which hashes the same as the specified value,
573 /// if present.
574 ///
575 /// Parameter `theSet`: The set to be queried. If this parameter is not a
576 /// valid CFSet, the behavior is undefined.
577 ///
578 /// Parameter `candidate`: This value is hashed and compared with values in the
579 /// set to determine which value to retrieve. The equal() callback provided when
580 /// the set was created is used to compare. If the equal() callback
581 /// was NULL, pointer equality (in C, ==) is used. If a value, or
582 /// any of the values in the set, are not understood by the equal()
583 /// callback, the behavior is undefined.
584 ///
585 /// Parameter `value`: A pointer to memory which should be filled with the
586 /// pointer-sized value if a matching value is found. If no
587 /// match is found, the contents of the storage pointed to by
588 /// this parameter are undefined. This parameter may be NULL,
589 /// in which case the value from the dictionary is not returned
590 /// (but the return value of this function still indicates
591 /// whether or not the value was present).
592 ///
593 /// Returns: True if the value was present in the set, otherwise false.
594 ///
595 /// # Safety
596 ///
597 /// - `the_set` generic must be of the correct type.
598 /// - `candidate` must be a valid pointer.
599 /// - `value` must be a valid pointer.
600 #[doc(alias = "CFSetGetValueIfPresent")]
601 #[inline]
602 pub unsafe fn value_if_present(
603 &self,
604 candidate: *const c_void,
605 value: *mut *const c_void,
606 ) -> bool {
607 extern "C-unwind" {
608 fn CFSetGetValueIfPresent(
609 the_set: &CFSet,
610 candidate: *const c_void,
611 value: *mut *const c_void,
612 ) -> Boolean;
613 }
614 let ret = unsafe { CFSetGetValueIfPresent(self, candidate, value) };
615 ret != 0
616 }
617
618 /// Fills the buffer with values from the set.
619 ///
620 /// Parameter `theSet`: The set to be queried. If this parameter is not a
621 /// valid CFSet, the behavior is undefined.
622 ///
623 /// Parameter `values`: A C array of pointer-sized values to be filled with
624 /// values from the set. The values in the C array are ordered
625 /// in the same order in which they appear in the set. If this
626 /// parameter is not a valid pointer to a C array of at least
627 /// CFSetGetCount() pointers, the behavior is undefined.
628 ///
629 /// # Safety
630 ///
631 /// - `the_set` generic must be of the correct type.
632 /// - `values` must be a valid pointer.
633 #[doc(alias = "CFSetGetValues")]
634 #[inline]
635 pub unsafe fn values(&self, values: *mut *const c_void) {
636 extern "C-unwind" {
637 fn CFSetGetValues(the_set: &CFSet, values: *mut *const c_void);
638 }
639 unsafe { CFSetGetValues(self, values) }
640 }
641
642 /// Calls a function once for each value in the set.
643 ///
644 /// Parameter `theSet`: The set to be operated upon. If this parameter is not
645 /// a valid CFSet, the behavior is undefined.
646 ///
647 /// Parameter `applier`: The callback function to call once for each value in
648 /// the given set. If this parameter is not a
649 /// pointer to a function of the correct prototype, the behavior
650 /// is undefined. If there are values in the set which the
651 /// applier function does not expect or cannot properly apply
652 /// to, the behavior is undefined.
653 ///
654 /// Parameter `context`: A pointer-sized user-defined value, which is passed
655 /// as the second parameter to the applier function, but is
656 /// otherwise unused by this function. If the context is not
657 /// what is expected by the applier function, the behavior is
658 /// undefined.
659 ///
660 /// # Safety
661 ///
662 /// - `the_set` generic must be of the correct type.
663 /// - `applier` must be implemented correctly.
664 /// - `context` must be a valid pointer.
665 #[doc(alias = "CFSetApplyFunction")]
666 #[inline]
667 pub unsafe fn apply_function(&self, applier: CFSetApplierFunction, context: *mut c_void) {
668 extern "C-unwind" {
669 fn CFSetApplyFunction(
670 the_set: &CFSet,
671 applier: CFSetApplierFunction,
672 context: *mut c_void,
673 );
674 }
675 unsafe { CFSetApplyFunction(self, applier, context) }
676 }
677}
678
679impl CFMutableSet {
680 /// Adds the value to the set if it is not already present.
681 ///
682 /// Parameter `theSet`: The set to which the value is to be added. If this
683 /// parameter is not a valid mutable CFSet, the behavior is
684 /// undefined.
685 ///
686 /// Parameter `value`: The value to add to the set. The value is retained by
687 /// the set using the retain callback provided when the set
688 /// was created. If the value is not of the sort expected by the
689 /// retain callback, the behavior is undefined. The count of the
690 /// set is increased by one.
691 ///
692 /// # Safety
693 ///
694 /// - `the_set` generic must be of the correct type.
695 /// - `the_set` might not allow `None`.
696 /// - `value` must be a valid pointer.
697 #[doc(alias = "CFSetAddValue")]
698 #[inline]
699 pub unsafe fn add_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
700 extern "C-unwind" {
701 fn CFSetAddValue(the_set: Option<&CFMutableSet>, value: *const c_void);
702 }
703 unsafe { CFSetAddValue(the_set, value) }
704 }
705
706 /// Replaces the value in the set if it is present.
707 ///
708 /// Parameter `theSet`: The set to which the value is to be replaced. If this
709 /// parameter is not a valid mutable CFSet, the behavior is
710 /// undefined.
711 ///
712 /// Parameter `value`: The value to replace in the set. The equal() callback provided when
713 /// the set was created is used to compare. If the equal() callback
714 /// was NULL, pointer equality (in C, ==) is used. If a value, or
715 /// any of the values in the set, are not understood by the equal()
716 /// callback, the behavior is undefined. The value is retained by
717 /// the set using the retain callback provided when the set
718 /// was created. If the value is not of the sort expected by the
719 /// retain callback, the behavior is undefined. The count of the
720 /// set is increased by one.
721 ///
722 /// # Safety
723 ///
724 /// - `the_set` generic must be of the correct type.
725 /// - `the_set` might not allow `None`.
726 /// - `value` must be a valid pointer.
727 #[doc(alias = "CFSetReplaceValue")]
728 #[inline]
729 pub unsafe fn replace_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
730 extern "C-unwind" {
731 fn CFSetReplaceValue(the_set: Option<&CFMutableSet>, value: *const c_void);
732 }
733 unsafe { CFSetReplaceValue(the_set, value) }
734 }
735
736 /// Replaces the value in the set if it is present, or adds the value to
737 /// the set if it is absent.
738 ///
739 /// Parameter `theSet`: The set to which the value is to be replaced. If this
740 /// parameter is not a valid mutable CFSet, the behavior is
741 /// undefined.
742 ///
743 /// Parameter `value`: The value to set in the CFSet. The equal() callback provided when
744 /// the set was created is used to compare. If the equal() callback
745 /// was NULL, pointer equality (in C, ==) is used. If a value, or
746 /// any of the values in the set, are not understood by the equal()
747 /// callback, the behavior is undefined. The value is retained by
748 /// the set using the retain callback provided when the set
749 /// was created. If the value is not of the sort expected by the
750 /// retain callback, the behavior is undefined. The count of the
751 /// set is increased by one.
752 ///
753 /// # Safety
754 ///
755 /// - `the_set` generic must be of the correct type.
756 /// - `the_set` might not allow `None`.
757 /// - `value` must be a valid pointer.
758 #[doc(alias = "CFSetSetValue")]
759 #[inline]
760 pub unsafe fn set_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
761 extern "C-unwind" {
762 fn CFSetSetValue(the_set: Option<&CFMutableSet>, value: *const c_void);
763 }
764 unsafe { CFSetSetValue(the_set, value) }
765 }
766
767 /// Removes the specified value from the set.
768 ///
769 /// Parameter `theSet`: The set from which the value is to be removed.
770 /// If this parameter is not a valid mutable CFSet,
771 /// the behavior is undefined.
772 ///
773 /// Parameter `value`: The value to remove. The equal() callback provided when
774 /// the set was created is used to compare. If the equal() callback
775 /// was NULL, pointer equality (in C, ==) is used. If a value, or
776 /// any of the values in the set, are not understood by the equal()
777 /// callback, the behavior is undefined.
778 ///
779 /// # Safety
780 ///
781 /// - `the_set` generic must be of the correct type.
782 /// - `the_set` might not allow `None`.
783 /// - `value` must be a valid pointer.
784 #[doc(alias = "CFSetRemoveValue")]
785 #[inline]
786 pub unsafe fn remove_value(the_set: Option<&CFMutableSet>, value: *const c_void) {
787 extern "C-unwind" {
788 fn CFSetRemoveValue(the_set: Option<&CFMutableSet>, value: *const c_void);
789 }
790 unsafe { CFSetRemoveValue(the_set, value) }
791 }
792
793 /// Removes all the values from the set, making it empty.
794 ///
795 /// Parameter `theSet`: The set from which all of the values are to be
796 /// removed. If this parameter is not a valid mutable CFSet,
797 /// the behavior is undefined.
798 #[doc(alias = "CFSetRemoveAllValues")]
799 #[inline]
800 pub fn remove_all_values(the_set: Option<&CFMutableSet>) {
801 extern "C-unwind" {
802 fn CFSetRemoveAllValues(the_set: Option<&CFMutableSet>);
803 }
804 unsafe { CFSetRemoveAllValues(the_set) }
805 }
806}
807
808#[deprecated = "renamed to `CFSet::new`"]
809#[inline]
810pub unsafe extern "C-unwind" fn CFSetCreate(
811 allocator: Option<&CFAllocator>,
812 values: *mut *const c_void,
813 num_values: CFIndex,
814 call_backs: *const CFSetCallBacks,
815) -> Option<CFRetained<CFSet>> {
816 extern "C-unwind" {
817 fn CFSetCreate(
818 allocator: Option<&CFAllocator>,
819 values: *mut *const c_void,
820 num_values: CFIndex,
821 call_backs: *const CFSetCallBacks,
822 ) -> Option<NonNull<CFSet>>;
823 }
824 let ret = unsafe { CFSetCreate(allocator, values, num_values, call_backs) };
825 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
826}
827
828#[deprecated = "renamed to `CFSet::new_copy`"]
829#[inline]
830pub extern "C-unwind" fn CFSetCreateCopy(
831 allocator: Option<&CFAllocator>,
832 the_set: Option<&CFSet>,
833) -> Option<CFRetained<CFSet>> {
834 extern "C-unwind" {
835 fn CFSetCreateCopy(
836 allocator: Option<&CFAllocator>,
837 the_set: Option<&CFSet>,
838 ) -> Option<NonNull<CFSet>>;
839 }
840 let ret = unsafe { CFSetCreateCopy(allocator, the_set) };
841 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
842}
843
844#[deprecated = "renamed to `CFMutableSet::new`"]
845#[inline]
846pub unsafe extern "C-unwind" fn CFSetCreateMutable(
847 allocator: Option<&CFAllocator>,
848 capacity: CFIndex,
849 call_backs: *const CFSetCallBacks,
850) -> Option<CFRetained<CFMutableSet>> {
851 extern "C-unwind" {
852 fn CFSetCreateMutable(
853 allocator: Option<&CFAllocator>,
854 capacity: CFIndex,
855 call_backs: *const CFSetCallBacks,
856 ) -> Option<NonNull<CFMutableSet>>;
857 }
858 let ret = unsafe { CFSetCreateMutable(allocator, capacity, call_backs) };
859 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
860}
861
862#[deprecated = "renamed to `CFMutableSet::new_copy`"]
863#[inline]
864pub unsafe extern "C-unwind" fn CFSetCreateMutableCopy(
865 allocator: Option<&CFAllocator>,
866 capacity: CFIndex,
867 the_set: Option<&CFSet>,
868) -> Option<CFRetained<CFMutableSet>> {
869 extern "C-unwind" {
870 fn CFSetCreateMutableCopy(
871 allocator: Option<&CFAllocator>,
872 capacity: CFIndex,
873 the_set: Option<&CFSet>,
874 ) -> Option<NonNull<CFMutableSet>>;
875 }
876 let ret = unsafe { CFSetCreateMutableCopy(allocator, capacity, the_set) };
877 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
878}
879
880#[deprecated = "renamed to `CFSet::count`"]
881#[inline]
882pub extern "C-unwind" fn CFSetGetCount(the_set: &CFSet) -> CFIndex {
883 extern "C-unwind" {
884 fn CFSetGetCount(the_set: &CFSet) -> CFIndex;
885 }
886 unsafe { CFSetGetCount(the_set) }
887}
888
889extern "C-unwind" {
890 #[deprecated = "renamed to `CFSet::count_of_value`"]
891 pub fn CFSetGetCountOfValue(the_set: &CFSet, value: *const c_void) -> CFIndex;
892}
893
894#[deprecated = "renamed to `CFSet::contains_value`"]
895#[inline]
896pub unsafe extern "C-unwind" fn CFSetContainsValue(the_set: &CFSet, value: *const c_void) -> bool {
897 extern "C-unwind" {
898 fn CFSetContainsValue(the_set: &CFSet, value: *const c_void) -> Boolean;
899 }
900 let ret = unsafe { CFSetContainsValue(the_set, value) };
901 ret != 0
902}
903
904extern "C-unwind" {
905 #[deprecated = "renamed to `CFSet::value`"]
906 pub fn CFSetGetValue(the_set: &CFSet, value: *const c_void) -> *const c_void;
907}
908
909#[deprecated = "renamed to `CFSet::value_if_present`"]
910#[inline]
911pub unsafe extern "C-unwind" fn CFSetGetValueIfPresent(
912 the_set: &CFSet,
913 candidate: *const c_void,
914 value: *mut *const c_void,
915) -> bool {
916 extern "C-unwind" {
917 fn CFSetGetValueIfPresent(
918 the_set: &CFSet,
919 candidate: *const c_void,
920 value: *mut *const c_void,
921 ) -> Boolean;
922 }
923 let ret = unsafe { CFSetGetValueIfPresent(the_set, candidate, value) };
924 ret != 0
925}
926
927extern "C-unwind" {
928 #[deprecated = "renamed to `CFSet::values`"]
929 pub fn CFSetGetValues(the_set: &CFSet, values: *mut *const c_void);
930}
931
932extern "C-unwind" {
933 #[deprecated = "renamed to `CFSet::apply_function`"]
934 pub fn CFSetApplyFunction(the_set: &CFSet, applier: CFSetApplierFunction, context: *mut c_void);
935}
936
937extern "C-unwind" {
938 #[deprecated = "renamed to `CFMutableSet::add_value`"]
939 pub fn CFSetAddValue(the_set: Option<&CFMutableSet>, value: *const c_void);
940}
941
942extern "C-unwind" {
943 #[deprecated = "renamed to `CFMutableSet::replace_value`"]
944 pub fn CFSetReplaceValue(the_set: Option<&CFMutableSet>, value: *const c_void);
945}
946
947extern "C-unwind" {
948 #[deprecated = "renamed to `CFMutableSet::set_value`"]
949 pub fn CFSetSetValue(the_set: Option<&CFMutableSet>, value: *const c_void);
950}
951
952extern "C-unwind" {
953 #[deprecated = "renamed to `CFMutableSet::remove_value`"]
954 pub fn CFSetRemoveValue(the_set: Option<&CFMutableSet>, value: *const c_void);
955}
956
957#[deprecated = "renamed to `CFMutableSet::remove_all_values`"]
958#[inline]
959pub extern "C-unwind" fn CFSetRemoveAllValues(the_set: Option<&CFMutableSet>) {
960 extern "C-unwind" {
961 fn CFSetRemoveAllValues(the_set: Option<&CFMutableSet>);
962 }
963 unsafe { CFSetRemoveAllValues(the_set) }
964}