use libc::{c_char, c_double, c_float, c_void};
use objc::{msg_send, sel, sel_impl};
use crate::core_graphics::{CGPoint, CGRect, CGSize};
use crate::{object,
objective_c_runtime::{
id,
macros::{interface_impl},
traits::{PNSObject, ToId},
},
utils::to_bool,
};
use super::{
Int, Int32, Int64, NSDecodingFailurePolicy, NSPoint, NSRect, NSSize, NSString, UInt, UInt8,
};
object! {
unsafe pub struct NSCoder;
}
#[interface_impl(NSObject)]
impl NSCoder {
#[property]
pub fn allows_keyed_coding(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), allowsKeyedCoding]) }
}
#[method]
pub fn contains_value_for_key(&self, key: NSString) -> bool {
unsafe { to_bool(msg_send![self.m_self(), containsValueForKey: key]) }
}
#[property]
pub fn decoding_failure_policy(&self) -> NSDecodingFailurePolicy {
unsafe { msg_send![self.m_self(), decodingFailurePolicy] }
}
#[method]
pub fn encode_array_of_objc_type_count_at(
&mut self,
type_: *const c_char,
count: usize,
array: *const c_void,
) {
unsafe { msg_send![self.m_self(), encodeArrayOfObjCType: type_ count: count at: array] }
}
#[method]
pub fn encode_bool_for_key(&mut self, value: bool, key: NSString) {
unsafe { msg_send![self.m_self(), encodeBool: value forKey: key] }
}
#[method]
pub fn encode_bycopy_object<T>(&mut self, object: T)
where
T: PNSObject + ToId,
{
unsafe { msg_send![self.m_self(), encodeBycopy: object.to_id()] }
}
#[method]
pub fn encode_byref_object<T>(&mut self, object: T)
where
T: PNSObject,
{
unsafe { msg_send![self.m_self(), encodeByref: object] }
}
#[method]
pub fn encode_bytes_length(&mut self, bytes: *const c_void, length: UInt) {
unsafe { msg_send![self.m_self(), encodeBytes: bytes length: length] }
}
#[method]
pub fn encode_bytes_length_for_key(
&mut self,
bytes: *const UInt8,
length: UInt,
key: NSString,
) {
unsafe { msg_send![self.m_self(), encodeBytes: bytes length: length forKey: key] }
}
#[method]
pub fn encode_conditional_object<T>(&mut self, object: T)
where
T: PNSObject,
{
unsafe { msg_send![self.m_self(), encodeConditionalObject: object] }
}
#[method]
pub fn encode_conditional_object_for_key<T>(&mut self, object: T, key: NSString)
where
T: PNSObject,
{
unsafe { msg_send![self.m_self(), encodeConditionalObject: object forKey: key] }
}
#[method]
pub fn encode_data_object<T>(&mut self, object: T)
where
T: PNSObject,
{
unsafe { msg_send![self.m_self(), encodeDataObject: object] }
}
#[method]
pub fn encode_double_for_key(&mut self, value: c_double, key: NSString) {
unsafe { msg_send![self.m_self(), encodeDouble: value forKey: key] }
}
#[method]
pub fn encode_float_for_key(&mut self, value: c_float, key: NSString) {
unsafe { msg_send![self.m_self(), encodeFloat: value forKey: key] }
}
#[method]
pub fn encode_int_for_key(&mut self, value: Int, key: NSString) {
unsafe { msg_send![self.m_self(), encodeInt: value forKey: key] }
}
#[method]
pub fn encode_integer_for_key(&mut self, value: Int, key: NSString) {
unsafe { msg_send![self.m_self(), encodeInteger: value forKey: key] }
}
#[method]
pub fn encode_int32_for_key(&mut self, value: Int32, key: NSString) {
unsafe { msg_send![self.m_self(), encodeInt32: value forKey: key] }
}
#[method]
pub fn encode_int64_for_key(&mut self, value: Int64, key: NSString) {
unsafe { msg_send![self.m_self(), encodeInt64: value forKey: key] }
}
#[method]
pub fn encode_object<T>(&mut self, object: T)
where
T: PNSObject,
{
unsafe { msg_send![self.m_self(), encodeObject: object] }
}
#[method]
pub fn encode_object_for_key<T>(&mut self, object: T, key: NSString)
where
T: PNSObject,
{
unsafe { msg_send![self.m_self(), encodeObject: object forKey: key] }
}
#[method]
pub fn encode_point(&mut self, point: NSPoint) {
unsafe { msg_send![self.m_self(), encodePoint: point] }
}
#[method]
pub fn encode_point_for_key(&mut self, point: NSPoint, key: NSString) {
unsafe { msg_send![self.m_self(), encodePoint: point forKey: key] }
}
#[method]
pub fn encode_property_list(&mut self, property_list: id) {
unsafe { msg_send![self.m_self(), encodePropertyList: property_list] }
}
#[method]
pub fn encode_rect(&mut self, rect: NSRect) {
unsafe { msg_send![self.m_self(), encodeRect: rect] }
}
#[method]
pub fn encode_rect_for_key(&mut self, rect: NSRect, key: NSString) {
unsafe { msg_send![self.m_self(), encodeRect: rect forKey: key] }
}
#[method]
pub fn encode_root_object(&mut self, root_object: id) {
unsafe { msg_send![self.m_self(), encodeRootObject: root_object] }
}
#[method]
pub fn encode_size(&mut self, size: NSSize) {
unsafe { msg_send![self.m_self(), encodeSize: size] }
}
#[method]
pub fn encode_size_for_key(&mut self, size: NSSize, key: NSString) {
unsafe { msg_send![self.m_self(), encodeSize: size forKey: key] }
}
#[method]
pub fn encode_value_of_objc_type_at(&mut self, _type: *const c_char, addr: *const c_void) {
unsafe { msg_send![self.m_self(), encodeValueOfObjCType: _type at: addr] }
}
#[method]
pub fn encode_cgpoint_for_key(&mut self, point: CGPoint, key: NSString) {
unsafe { msg_send![self.m_self(), encodeCGPoint: point forKey: key] }
}
#[method]
pub fn encode_cgrect_for_key(&mut self, rect: CGRect, key: NSString) {
unsafe { msg_send![self.m_self(), encodeCGRect: rect forKey: key] }
}
#[method]
pub fn encode_cgzize_for_key(&mut self, size: CGSize, key: NSString) {
unsafe { msg_send![self.m_self(), encodeCGSize: size forKey: key] }
}
}