objc2-gameplay-kit 0.3.2

Bindings to the GameplayKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use objc2::__framework_prelude::*;

use crate::*;

extern_class!(
    /// The individual node(s) that make up a GKQuadtree.
    /// Used as a hint for faster removal via [GKQuadtree removeData:WithNode:]
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkquadtreenode?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKQuadtreeNode;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for GKQuadtreeNode {}
);

impl GKQuadtreeNode {
    extern_methods!();
}

/// Methods declared on superclass `NSObject`.
impl GKQuadtreeNode {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// A tree data structure where each level has 4 children that subdivide a given space into the four quadrants.
    /// Stores arbitrary NSObject data via points and quads.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkquadtree?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKQuadtree<ElementType: ?Sized = AnyObject>;
);

impl<ElementType: ?Sized + Message + AsRef<NSObject>> GKQuadtree<ElementType> {
    /// Unchecked conversion of the generic parameter.
    ///
    /// # Safety
    ///
    /// The generic must be valid to reinterpret as the given type.
    #[inline]
    pub unsafe fn cast_unchecked<NewElementType: ?Sized + Message + AsRef<NSObject>>(
        &self,
    ) -> &GKQuadtree<NewElementType> {
        unsafe { &*((self as *const Self).cast()) }
    }
}

extern_conformance!(
    unsafe impl<ElementType: ?Sized + AsRef<NSObject>> NSObjectProtocol for GKQuadtree<ElementType> {}
);

impl<ElementType: Message + AsRef<NSObject>> GKQuadtree<ElementType> {
    extern_methods!(
        /// Removes the given NSObject from this quad tree.
        /// Note that this is an exhaustive search and is slow.
        /// Cache the relevant GKQuadTreeNode and use removeElement:WithNode: for better performance.
        ///
        ///
        /// Parameter `element`: the data to be removed
        ///
        /// Returns: returns YES if the data was removed, NO otherwise
        #[unsafe(method(removeElement:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeElement(&self, element: &ElementType) -> bool;

        /// Removes the given NSObject from the given quadtree node
        /// Note that this is not an exhaustive search and is faster than removeData:
        ///
        ///
        /// Parameter `data`: the data to be removed
        ///
        /// Parameter `node`: the node in which this data resides
        ///
        /// Returns: returns YES if the data was removed, NO otherwise
        #[unsafe(method(removeElement:withNode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeElement_withNode(
            &self,
            data: &ElementType,
            node: &GKQuadtreeNode,
        ) -> bool;
    );
}

/// Methods declared on superclass `NSObject`.
impl<ElementType: Message + AsRef<NSObject>> GKQuadtree<ElementType> {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}