use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::{NSObject, ProtocolObject},
};
use objc2_foundation::{CopyingHelper, NSArray, NSCopying, NSObjectProtocol, NSString};
use crate::MTLFunctionStitchingFunctionNode;
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLFunctionStitchingGraph;
);
extern_conformance!(
unsafe impl NSCopying for MTLFunctionStitchingGraph {}
);
unsafe impl CopyingHelper for MTLFunctionStitchingGraph {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLFunctionStitchingGraph {}
);
impl MTLFunctionStitchingGraph {
extern_methods!(
#[unsafe(method(outputNode))]
#[unsafe(method_family = none)]
pub fn output_node(&self) -> Option<Retained<MTLFunctionStitchingFunctionNode>>;
#[unsafe(method(setOutputNode:))]
#[unsafe(method_family = none)]
pub fn set_output_node(
&self,
output_node: Option<&MTLFunctionStitchingFunctionNode>,
);
);
pub fn nodes(&self) -> Box<[Retained<MTLFunctionStitchingFunctionNode>]> {
let nodes: Retained<NSArray<MTLFunctionStitchingFunctionNode>> = unsafe { msg_send![self, nodes] };
nodes.to_vec().into_boxed_slice()
}
pub fn set_nodes(
&self,
nodes: &[&MTLFunctionStitchingFunctionNode],
) {
let nodes = NSArray::from_slice(nodes);
unsafe {
let _: () = msg_send![self, setNodes: &*nodes];
}
}
pub fn attributes(&self) -> Box<[Retained<ProtocolObject<dyn super::MTLFunctionStitchingAttribute>>]> {
let attributes: Retained<NSArray<ProtocolObject<dyn super::MTLFunctionStitchingAttribute>>> =
unsafe { msg_send![self, attributes] };
attributes.to_vec().into_boxed_slice()
}
pub fn set_attributes(
&self,
attributes: &[&ProtocolObject<dyn super::MTLFunctionStitchingAttribute>],
) {
let attributes = NSArray::from_slice(attributes);
unsafe {
let _: () = msg_send![self, setAttributes: &*attributes];
}
}
pub fn init_with_function_name_nodes_output_node_attributes(
this: Allocated<Self>,
function_name: &str,
nodes: &[&MTLFunctionStitchingFunctionNode],
output_node: Option<&MTLFunctionStitchingFunctionNode>,
attributes: &[&ProtocolObject<dyn super::MTLFunctionStitchingAttribute>],
) -> Retained<Self> {
let function_name = NSString::from_str(function_name);
let nodes = NSArray::from_slice(nodes);
let attributes = NSArray::from_slice(attributes);
unsafe {
msg_send![
this,
initWithFunctionName: &*function_name,
nodes: &*nodes,
outputNode: output_node,
attributes: &*attributes
]
}
}
}
#[allow(unused)]
impl MTLFunctionStitchingGraph {
fn function_name(&self) -> String {
let s: Retained<NSString> = unsafe { msg_send![self, functionName] };
s.to_string()
}
fn set_function_name(
&self,
name: &str,
) {
unsafe {
let _: () = msg_send![self, setFunctionName: &*NSString::from_str(name)];
}
}
}