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::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkdecisionnode?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKDecisionNode;
);

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

impl GKDecisionNode {
    extern_methods!(
        /// Creates a numeric branch to a node containing the specified attribute
        ///
        ///
        /// Parameter `value`: The value to create a branch with
        ///
        /// Parameter `attribute`: The attribute of the created node
        ///
        /// Returns: The node lead to by the branch
        ///
        /// # Safety
        ///
        /// `attribute` should be of the correct type.
        #[unsafe(method(createBranchWithValue:attribute:))]
        #[unsafe(method_family = none)]
        pub unsafe fn createBranchWithValue_attribute(
            &self,
            value: &NSNumber,
            attribute: &ProtocolObject<dyn NSObjectProtocol>,
        ) -> Retained<Self>;

        /// Creates a predicated branch to a node containing the specified attribute
        ///
        ///
        /// Parameter `predicate`: The predicate to create a branch with
        ///
        /// Parameter `attribute`: The attribute of the created node
        ///
        /// Returns: The node lead to by the branch
        ///
        /// # Safety
        ///
        /// `attribute` should be of the correct type.
        #[unsafe(method(createBranchWithPredicate:attribute:))]
        #[unsafe(method_family = none)]
        pub unsafe fn createBranchWithPredicate_attribute(
            &self,
            predicate: &NSPredicate,
            attribute: &ProtocolObject<dyn NSObjectProtocol>,
        ) -> Retained<Self>;

        /// Creates a random branch to a node containing the specified attribute
        ///
        ///
        /// Parameter `weight`: The weight to create a branch with (weighted for random selection)
        ///
        /// Parameter `attribute`: The attribute of the created node
        ///
        /// Returns: The node lead to by the branch
        ///
        ///
        /// See: GKDecisionTree
        ///
        /// # Safety
        ///
        /// `attribute` should be of the correct type.
        #[unsafe(method(createBranchWithWeight:attribute:))]
        #[unsafe(method_family = none)]
        pub unsafe fn createBranchWithWeight_attribute(
            &self,
            weight: NSInteger,
            attribute: &ProtocolObject<dyn NSObjectProtocol>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl GKDecisionNode {
    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!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkdecisiontree?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKDecisionTree;
);

extern_conformance!(
    unsafe impl NSCoding for GKDecisionTree {}
);

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

extern_conformance!(
    unsafe impl NSSecureCoding for GKDecisionTree {}
);

impl GKDecisionTree {
    extern_methods!(
        /// The node for the decision tree that all other nodes descend from
        #[unsafe(method(rootNode))]
        #[unsafe(method_family = none)]
        pub unsafe fn rootNode(&self) -> Option<Retained<GKDecisionNode>>;

        #[cfg(feature = "GKRandomSource")]
        /// The random source used by the decision tree when descending on a random branch
        /// This must be set before creating any weighted branches
        ///
        /// See: GKDecisionNode
        #[unsafe(method(randomSource))]
        #[unsafe(method_family = none)]
        pub unsafe fn randomSource(&self) -> Retained<GKRandomSource>;

        #[cfg(feature = "GKRandomSource")]
        /// Setter for [`randomSource`][Self::randomSource].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setRandomSource:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRandomSource(&self, random_source: &GKRandomSource);

        /// Initializes the decision tree with a root node containing the provided attribute
        ///
        ///
        /// Parameter `attribute`: The attribute to be contained at the root of the tree
        ///
        /// Returns: GKDecisionTree with the set root
        ///
        /// # Safety
        ///
        /// `attribute` should be of the correct type.
        #[unsafe(method(initWithAttribute:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithAttribute(
            this: Allocated<Self>,
            attribute: &ProtocolObject<dyn NSObjectProtocol>,
        ) -> Retained<Self>;

        /// Initializes and constructs a decision tree by learning from the provided examples
        /// &
        /// attributes
        ///
        ///
        /// Parameter `examples`: Must be an array of examples (with each example being a collection of the various attributes at a given state)
        ///
        /// Parameter `actions`: An array of the corresponding actions for each example. Ordered such that the first action matches with the first example in examples.
        ///
        /// Parameter `attributes`: The list of attributes. Ordered such that the first attribute matches with the first result in each example.
        /// So if we have two attributes: [distance, jump height], and two examples: [[20, 8], [15, 14]], and the resulting actions here: [Roll, Jump], we can think of this as a matrix:
        ///
        /// distance| height
        /// <
        /// -  Attributes
        /// _______|_______
        /// |       |       |
        /// |  20   |   8   |  jump
        /// |-------|-------|-------
        /// <
        /// -  Results
        /// |  15   |   14  |  roll
        /// |_______|_______|
        /// ^
        /// |
        /// Examples
        ///
        ///
        /// Returns: GKDecisionTree created by learning from the provided examples for the provided attributes
        ///
        /// # Safety
        ///
        /// - `examples` generic generic should be of the correct type.
        /// - `actions` generic should be of the correct type.
        /// - `attributes` generic should be of the correct type.
        #[unsafe(method(initWithExamples:actions:attributes:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithExamples_actions_attributes(
            this: Allocated<Self>,
            examples: &NSArray<NSArray<ProtocolObject<dyn NSObjectProtocol>>>,
            actions: &NSArray<ProtocolObject<dyn NSObjectProtocol>>,
            attributes: &NSArray<ProtocolObject<dyn NSObjectProtocol>>,
        ) -> Retained<Self>;

        /// Initializes a decision tree from the contents of a file
        ///
        ///
        /// Parameter `url`: The URL from which the contents will be loaded
        ///
        /// Returns: The instance of the decision tree constructed
        #[unsafe(method(initWithURL:error:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithURL_error(
            this: Allocated<Self>,
            url: &NSURL,
            error: Option<&NSError>,
        ) -> Retained<Self>;

        /// Exports a decision tree to the given URL
        ///
        ///
        /// Parameter `url`: The URL to which the contents will be exported
        ///
        /// Returns: The response indicating the status of the decision tree being successfully exported
        #[unsafe(method(exportToURL:error:))]
        #[unsafe(method_family = none)]
        pub unsafe fn exportToURL_error(&self, url: &NSURL, error: Option<&NSError>) -> bool;

        /// Will branch down from the root node to find the correct action attribute for the given collection of results and their respective attributes
        ///
        ///
        /// Parameter `answers`: The dictionary of attributes (keys) and their answers (values)
        ///
        /// Returns: The attribute found by traversing the tree given the provided answers
        ///
        /// # Safety
        ///
        /// - `answers` generic should be of the correct type.
        /// - `answers` generic should be of the correct type.
        #[unsafe(method(findActionForAnswers:))]
        #[unsafe(method_family = none)]
        pub unsafe fn findActionForAnswers(
            &self,
            answers: &NSDictionary<
                ProtocolObject<dyn NSObjectProtocol>,
                ProtocolObject<dyn NSObjectProtocol>,
            >,
        ) -> Option<Retained<ProtocolObject<dyn NSObjectProtocol>>>;
    );
}

/// Methods declared on superclass `NSObject`.
impl GKDecisionTree {
    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>;
    );
}