use core::{ffi::c_void, ops::Range, ptr::NonNull};
use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::NSObject,
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObjectProtocol, NSRange, NSString};
use crate::MTLDataType;
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLFunctionConstantValues;
);
extern_conformance!(
unsafe impl NSCopying for MTLFunctionConstantValues {}
);
unsafe impl CopyingHelper for MTLFunctionConstantValues {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLFunctionConstantValues {}
);
impl MTLFunctionConstantValues {
extern_methods!(
#[unsafe(method(setConstantValue:type:atIndex:))]
#[unsafe(method_family = none)]
pub fn set_constant_value_type_at_index(
&self,
value: NonNull<c_void>,
r#type: MTLDataType,
index: usize,
);
#[unsafe(method(reset))]
#[unsafe(method_family = none)]
pub fn reset(&self);
);
}
impl MTLFunctionConstantValues {
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>;
);
pub fn set_constant_values_type_with_range(
&self,
values: NonNull<c_void>,
r#type: MTLDataType,
range: Range<usize>,
) {
unsafe {
msg_send![
self,
setConstantValues: values,
type: r#type,
withRange: NSRange::from(range),
]
}
}
pub fn set_constant_value_type_with_name(
&self,
value: NonNull<c_void>,
r#type: MTLDataType,
name: &str,
) {
unsafe {
msg_send![
self,
setConstantValue: value,
type: r#type,
withName: &*NSString::from_str(name),
]
}
}
}