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::{MTLBinaryArchive, MTLFunctionConstantValues, MTLFunctionOptions};
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLFunctionDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLFunctionDescriptor {}
);
unsafe impl CopyingHelper for MTLFunctionDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLFunctionDescriptor {}
);
impl MTLFunctionDescriptor {
extern_methods!(
#[unsafe(method(functionDescriptor))]
#[unsafe(method_family = none)]
pub fn function_descriptor() -> Retained<MTLFunctionDescriptor>;
#[unsafe(method(options))]
#[unsafe(method_family = none)]
pub fn options(&self) -> MTLFunctionOptions;
#[unsafe(method(setOptions:))]
#[unsafe(method_family = none)]
pub fn set_options(
&self,
options: MTLFunctionOptions,
);
#[unsafe(method(constantValues))]
#[unsafe(method_family = none)]
pub fn constant_values(&self) -> Option<Retained<MTLFunctionConstantValues>>;
#[unsafe(method(setConstantValues:))]
#[unsafe(method_family = none)]
pub fn set_constant_values(
&self,
values: Option<&MTLFunctionConstantValues>,
);
);
}
impl MTLFunctionDescriptor {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new() -> Retained<Self>;
);
}
#[allow(unused)]
impl MTLFunctionDescriptor {
fn name(&self) -> Option<String> {
let s: Option<Retained<NSString>> = unsafe { msg_send![self, name] };
s.map(|v| v.to_string())
}
fn set_name(
&self,
name: Option<&str>,
) {
unsafe {
let _: () = msg_send![self, setName: name.map(NSString::from_str).as_deref()];
}
}
fn specialized_name(&self) -> Option<String> {
let s: Option<Retained<NSString>> = unsafe { msg_send![self, specializedName] };
s.map(|v| v.to_string())
}
fn set_specialized_name(
&self,
specialized_name: Option<&str>,
) {
unsafe {
let _: () = msg_send![
self,
setSpecializedName: specialized_name.map(NSString::from_str).as_deref()
];
}
}
fn binary_archives(&self) -> Option<Box<[Retained<ProtocolObject<dyn MTLBinaryArchive>>]>> {
let array: Option<Retained<NSArray<ProtocolObject<dyn MTLBinaryArchive>>>> =
unsafe { msg_send![self, binaryArchives] };
array.map(|a| a.to_vec().into_boxed_slice())
}
pub fn set_binary_archives(
&self,
archives: Option<&[&ProtocolObject<dyn MTLBinaryArchive>]>,
) {
let archives = archives.map(|archives| NSArray::from_slice(archives));
unsafe {
let _: () = msg_send![self, setBinaryArchives: archives.as_deref()];
}
}
}