objc2_core_foundation/generated/
CFTree.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 to add a retain to the user-specified
13/// info parameter.  This callback may returns the value to use whenever the
14/// info parameter is retained, which is usually the value parameter passed
15/// to this callback, but may be a different value if a different value
16/// should be used.
17///
18/// Parameter `info`: A user-supplied info parameter provided in a CFTreeContext.
19///
20/// Returns: The retained info parameter.
21///
22/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreeretaincallback?language=objc)
23pub type CFTreeRetainCallBack = Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>;
24
25/// Type of the callback function used to remove a retain previously
26/// added to the user-specified info parameter.
27///
28/// Parameter `info`: A user-supplied info parameter provided in a CFTreeContext.
29///
30/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreereleasecallback?language=objc)
31pub type CFTreeReleaseCallBack = Option<unsafe extern "C-unwind" fn(*const c_void)>;
32
33/// Type of the callback function used to provide a description of the
34/// user-specified info parameter.
35///
36/// Parameter `info`: A user-supplied info parameter provided in a CFTreeContext.
37///
38/// Returns: A description of the info parameter.
39///
40/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreecopydescriptioncallback?language=objc)
41#[cfg(feature = "CFBase")]
42pub type CFTreeCopyDescriptionCallBack =
43    Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
44
45/// Structure containing user-specified data and callbacks for a CFTree.
46/// Field: version The version number of the structure type being passed
47/// in as a parameter to the CFTree creation function.
48/// This structure is version 0.
49/// Field: info A C pointer to a user-specified block of data.
50/// Field: retain The callback used to add a retain for the info field.
51/// If this parameter is not a pointer to a function of the correct
52/// prototype, the behavior is undefined.  The value may be NULL.
53/// Field: release The calllback used to remove a retain previously added
54/// for the info field.  If this parameter is not a pointer to a
55/// function of the correct prototype, the behavior is undefined.
56/// The value may be NULL.
57/// Field: copyDescription The callback used to provide a description of
58/// the info field.
59///
60/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreecontext?language=objc)
61#[cfg(feature = "CFBase")]
62#[repr(C)]
63#[derive(Clone, Copy, Debug, PartialEq)]
64pub struct CFTreeContext {
65    pub version: CFIndex,
66    pub info: *mut c_void,
67    pub retain: CFTreeRetainCallBack,
68    pub release: CFTreeReleaseCallBack,
69    pub copyDescription: CFTreeCopyDescriptionCallBack,
70}
71
72#[cfg(all(feature = "CFBase", feature = "objc2"))]
73unsafe impl Encode for CFTreeContext {
74    const ENCODING: Encoding = Encoding::Struct(
75        "?",
76        &[
77            <CFIndex>::ENCODING,
78            <*mut c_void>::ENCODING,
79            <CFTreeRetainCallBack>::ENCODING,
80            <CFTreeReleaseCallBack>::ENCODING,
81            <CFTreeCopyDescriptionCallBack>::ENCODING,
82        ],
83    );
84}
85
86#[cfg(all(feature = "CFBase", feature = "objc2"))]
87unsafe impl RefEncode for CFTreeContext {
88    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
89}
90
91/// Type of the callback function used by the apply functions of
92/// CFTree.
93///
94/// Parameter `value`: The current value from the CFTree
95///
96/// Parameter `context`: The user-defined context parameter give to the apply
97/// function.
98///
99/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftreeapplierfunction?language=objc)
100pub type CFTreeApplierFunction = Option<unsafe extern "C-unwind" fn(*const c_void, *mut c_void)>;
101
102/// This is the type of a reference to CFTrees.
103///
104/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cftree?language=objc)
105#[repr(C)]
106pub struct CFTree {
107    inner: [u8; 0],
108    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
109}
110
111cf_type!(
112    #[encoding_name = "__CFTree"]
113    unsafe impl CFTree {}
114);
115
116#[cfg(feature = "CFBase")]
117unsafe impl ConcreteType for CFTree {
118    /// Returns the type identifier of all CFTree instances.
119    #[doc(alias = "CFTreeGetTypeID")]
120    #[inline]
121    fn type_id() -> CFTypeID {
122        extern "C-unwind" {
123            fn CFTreeGetTypeID() -> CFTypeID;
124        }
125        unsafe { CFTreeGetTypeID() }
126    }
127}
128
129/// Creates a new mutable tree.
130///
131/// Parameter `allocator`: The CFAllocator which should be used to allocate
132/// memory for the tree and storage for its children.  This
133/// parameter may be NULL in which case the current default
134/// CFAllocator is used.  If this reference is not a valid
135/// CFAllocator, the behavior is undefined.
136///
137/// Parameter `context`: A C pointer to a CFTreeContext structure to be copied
138/// and used as the context of the new tree.  The info parameter
139/// will be retained by the tree if a retain function is provided.
140/// If this value is not a valid C pointer to a CFTreeContext
141/// structure-sized block of storage, the result is undefined.
142/// If the version number of the storage is not a valid CFTreeContext
143/// version number, the result is undefined.
144///
145/// Returns: A reference to the new CFTree.
146#[cfg(feature = "CFBase")]
147#[inline]
148pub unsafe extern "C-unwind" fn CFTreeCreate(
149    allocator: Option<&CFAllocator>,
150    context: *const CFTreeContext,
151) -> Option<CFRetained<CFTree>> {
152    extern "C-unwind" {
153        fn CFTreeCreate(
154            allocator: Option<&CFAllocator>,
155            context: *const CFTreeContext,
156        ) -> Option<NonNull<CFTree>>;
157    }
158    let ret = unsafe { CFTreeCreate(allocator, context) };
159    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
160}
161
162/// Returns the parent of the specified tree.
163///
164/// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
165/// CFTree, the behavior is undefined.
166///
167/// Returns: The parent of the tree.
168#[inline]
169pub unsafe extern "C-unwind" fn CFTreeGetParent(tree: &CFTree) -> Option<CFRetained<CFTree>> {
170    extern "C-unwind" {
171        fn CFTreeGetParent(tree: &CFTree) -> Option<NonNull<CFTree>>;
172    }
173    let ret = unsafe { CFTreeGetParent(tree) };
174    ret.map(|ret| unsafe { CFRetained::retain(ret) })
175}
176
177/// Returns the sibling after the specified tree in the parent tree's list.
178///
179/// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
180/// CFTree, the behavior is undefined.
181///
182/// Returns: The next sibling of the tree.
183#[inline]
184pub unsafe extern "C-unwind" fn CFTreeGetNextSibling(tree: &CFTree) -> Option<CFRetained<CFTree>> {
185    extern "C-unwind" {
186        fn CFTreeGetNextSibling(tree: &CFTree) -> Option<NonNull<CFTree>>;
187    }
188    let ret = unsafe { CFTreeGetNextSibling(tree) };
189    ret.map(|ret| unsafe { CFRetained::retain(ret) })
190}
191
192/// Returns the first child of the tree.
193///
194/// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
195/// CFTree, the behavior is undefined.
196///
197/// Returns: The first child of the tree.
198#[inline]
199pub unsafe extern "C-unwind" fn CFTreeGetFirstChild(tree: &CFTree) -> Option<CFRetained<CFTree>> {
200    extern "C-unwind" {
201        fn CFTreeGetFirstChild(tree: &CFTree) -> Option<NonNull<CFTree>>;
202    }
203    let ret = unsafe { CFTreeGetFirstChild(tree) };
204    ret.map(|ret| unsafe { CFRetained::retain(ret) })
205}
206
207extern "C-unwind" {
208    /// Returns the context of the specified tree.
209    ///
210    /// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
211    /// CFTree, the behavior is undefined.
212    ///
213    /// Parameter `context`: A C pointer to a CFTreeContext structure to be filled in with
214    /// the context of the specified tree.  If this value is not a valid C
215    /// pointer to a CFTreeContext structure-sized block of storage, the
216    /// result is undefined.  If the version number of the storage is not
217    /// a valid CFTreeContext version number, the result is undefined.
218    #[cfg(feature = "CFBase")]
219    pub fn CFTreeGetContext(tree: &CFTree, context: *mut CFTreeContext);
220}
221
222extern "C-unwind" {
223    /// Returns the number of children of the specified tree.
224    ///
225    /// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
226    /// CFTree, the behavior is undefined.
227    ///
228    /// Returns: The number of children.
229    #[cfg(feature = "CFBase")]
230    pub fn CFTreeGetChildCount(tree: &CFTree) -> CFIndex;
231}
232
233/// Returns the nth child of the specified tree.
234///
235/// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
236/// CFTree, the behavior is undefined.
237///
238/// Parameter `idx`: The index of the child tree to be returned.  If this parameter
239/// is less than zero or greater than the number of children of the
240/// tree, the result is undefined.
241///
242/// Returns: A reference to the specified child tree.
243#[cfg(feature = "CFBase")]
244#[inline]
245pub unsafe extern "C-unwind" fn CFTreeGetChildAtIndex(
246    tree: &CFTree,
247    idx: CFIndex,
248) -> Option<CFRetained<CFTree>> {
249    extern "C-unwind" {
250        fn CFTreeGetChildAtIndex(tree: &CFTree, idx: CFIndex) -> Option<NonNull<CFTree>>;
251    }
252    let ret = unsafe { CFTreeGetChildAtIndex(tree, idx) };
253    ret.map(|ret| unsafe { CFRetained::retain(ret) })
254}
255
256extern "C-unwind" {
257    /// Fills the buffer with children from the tree.
258    ///
259    /// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
260    /// CFTree, the behavior is undefined.
261    ///
262    /// Parameter `children`: A C array of pointer-sized values to be filled with
263    /// children from the tree.  If this parameter is not a valid pointer to a
264    /// C array of at least CFTreeGetChildCount() pointers, the behavior is undefined.
265    pub fn CFTreeGetChildren(tree: &CFTree, children: *mut *mut CFTree);
266}
267
268extern "C-unwind" {
269    /// Calls a function once for each child of the tree.  Note that the applier
270    /// only operates one level deep, and does not operate on descendents further
271    /// removed than the immediate children of the tree.
272    ///
273    /// Parameter `tree`: The tree to be operated upon.  If this parameter is not a
274    /// valid CFTree, the behavior is undefined.
275    ///
276    /// Parameter `applier`: The callback function to call once for each child of
277    /// the given tree.  If this parameter is not a pointer to a
278    /// function of the correct prototype, the behavior is undefined.
279    /// If there are values in the tree which the applier function does
280    /// not expect or cannot properly apply to, the behavior is undefined.
281    ///
282    /// Parameter `context`: A pointer-sized user-defined value, which is passed
283    /// as the second parameter to the applier function, but is
284    /// otherwise unused by this function.  If the context is not
285    /// what is expected by the applier function, the behavior is
286    /// undefined.
287    pub fn CFTreeApplyFunctionToChildren(
288        tree: &CFTree,
289        applier: CFTreeApplierFunction,
290        context: *mut c_void,
291    );
292}
293
294/// Returns the root tree of which the specified tree is a descendent.
295///
296/// Parameter `tree`: The tree to be queried.  If this parameter is not a valid
297/// CFTree, the behavior is undefined.
298///
299/// Returns: A reference to the root of the tree.
300#[inline]
301pub unsafe extern "C-unwind" fn CFTreeFindRoot(tree: &CFTree) -> Option<CFRetained<CFTree>> {
302    extern "C-unwind" {
303        fn CFTreeFindRoot(tree: &CFTree) -> Option<NonNull<CFTree>>;
304    }
305    let ret = unsafe { CFTreeFindRoot(tree) };
306    ret.map(|ret| unsafe { CFRetained::retain(ret) })
307}
308
309extern "C-unwind" {
310    /// Replaces the context of a tree.  The tree releases its retain on the
311    /// info of the previous context, and retains the info of the new context.
312    ///
313    /// Parameter `tree`: The tree to be operated on.  If this parameter is not a valid
314    /// CFTree, the behavior is undefined.
315    ///
316    /// Parameter `context`: A C pointer to a CFTreeContext structure to be copied
317    /// and used as the context of the new tree.  The info parameter
318    /// will be retained by the tree if a retain function is provided.
319    /// If this value is not a valid C pointer to a CFTreeContext
320    /// structure-sized block of storage, the result is undefined.
321    /// If the version number of the storage is not a valid CFTreeContext
322    /// version number, the result is undefined.
323    #[cfg(feature = "CFBase")]
324    pub fn CFTreeSetContext(tree: &CFTree, context: *const CFTreeContext);
325}
326
327extern "C-unwind" {
328    /// Adds the newChild to the specified tree as the first in its list of children.
329    ///
330    /// Parameter `tree`: The tree to be operated on.  If this parameter is not a valid
331    /// CFTree, the behavior is undefined.
332    ///
333    /// Parameter `newChild`: The child to be added.
334    /// If this parameter is not a valid CFTree, the behavior is undefined.
335    /// If this parameter is a tree which is already a child of any tree,
336    /// the behavior is undefined.
337    pub fn CFTreePrependChild(tree: &CFTree, new_child: Option<&CFTree>);
338}
339
340extern "C-unwind" {
341    /// Adds the newChild to the specified tree as the last in its list of children.
342    ///
343    /// Parameter `tree`: The tree to be operated on.  If this parameter is not a valid
344    /// CFTree, the behavior is undefined.
345    ///
346    /// Parameter `newChild`: The child to be added.
347    /// If this parameter is not a valid CFTree, the behavior is undefined.
348    /// If this parameter is a tree which is already a child of any tree,
349    /// the behavior is undefined.
350    pub fn CFTreeAppendChild(tree: &CFTree, new_child: Option<&CFTree>);
351}
352
353extern "C-unwind" {
354    /// Inserts newSibling into the the parent tree's linked list of children after
355    /// tree.  The newSibling will have the same parent as tree.
356    ///
357    /// Parameter `tree`: The tree to insert newSibling after.  If this parameter is not a valid
358    /// CFTree, the behavior is undefined.  If the tree does not have a
359    /// parent, the behavior is undefined.
360    ///
361    /// Parameter `newSibling`: The sibling to be added.
362    /// If this parameter is not a valid CFTree, the behavior is undefined.
363    /// If this parameter is a tree which is already a child of any tree,
364    /// the behavior is undefined.
365    pub fn CFTreeInsertSibling(tree: &CFTree, new_sibling: Option<&CFTree>);
366}
367
368extern "C-unwind" {
369    /// Removes the tree from its parent.
370    ///
371    /// Parameter `tree`: The tree to be removed.  If this parameter is not a valid
372    /// CFTree, the behavior is undefined.
373    pub fn CFTreeRemove(tree: &CFTree);
374}
375
376extern "C-unwind" {
377    /// Removes all the children of the tree.
378    ///
379    /// Parameter `tree`: The tree to remove all children from.  If this parameter is not a valid
380    /// CFTree, the behavior is undefined.
381    pub fn CFTreeRemoveAllChildren(tree: &CFTree);
382}
383
384extern "C-unwind" {
385    /// Sorts the children of the specified tree using the specified comparator function.
386    ///
387    /// Parameter `tree`: The tree to be operated on.  If this parameter is not a valid
388    /// CFTree, the behavior is undefined.
389    ///
390    /// Parameter `comparator`: The function with the comparator function type
391    /// signature which is used in the sort operation to compare
392    /// children of the tree with the given value. If this parameter
393    /// is not a pointer to a function of the correct prototype, the
394    /// the behavior is undefined. The children of the tree are sorted
395    /// from least to greatest according to this function.
396    ///
397    /// Parameter `context`: A pointer-sized user-defined value, which is passed
398    /// as the third parameter to the comparator function, but is
399    /// otherwise unused by this function. If the context is not
400    /// what is expected by the comparator function, the behavior is
401    /// undefined.
402    #[cfg(feature = "CFBase")]
403    pub fn CFTreeSortChildren(
404        tree: &CFTree,
405        comparator: CFComparatorFunction,
406        context: *mut c_void,
407    );
408}