1use libc::{c_char, c_double, c_float, c_void};
2use objc::{msg_send, sel, sel_impl};
3
4use crate::core_graphics::{CGPoint, CGRect, CGSize};
5use crate::{object,
6 objective_c_runtime::{
7 id,
8 macros::{interface_impl},
9 traits::{PNSObject, ToId},
10 },
11 utils::to_bool,
12};
13
14use super::{
15 Int, Int32, Int64, NSDecodingFailurePolicy, NSPoint, NSRect, NSSize, NSString, UInt, UInt8,
16};
17
18object! {
19 unsafe pub struct NSCoder;
21}
22
23#[interface_impl(NSObject)]
24impl NSCoder {
25 #[property]
30 pub fn allows_keyed_coding(&self) -> bool {
31 unsafe { to_bool(msg_send![self.m_self(), allowsKeyedCoding]) }
32 }
33
34 #[method]
36 pub fn contains_value_for_key(&self, key: NSString) -> bool {
37 unsafe { to_bool(msg_send![self.m_self(), containsValueForKey: key]) }
38 }
39
40 #[property]
42 pub fn decoding_failure_policy(&self) -> NSDecodingFailurePolicy {
43 unsafe { msg_send![self.m_self(), decodingFailurePolicy] }
44 }
45
46 #[method]
51 pub fn encode_array_of_objc_type_count_at(
52 &mut self,
53 type_: *const c_char,
54 count: usize,
55 array: *const c_void,
56 ) {
57 unsafe { msg_send![self.m_self(), encodeArrayOfObjCType: type_ count: count at: array] }
58 }
59
60 #[method]
62 pub fn encode_bool_for_key(&mut self, value: bool, key: NSString) {
63 unsafe { msg_send![self.m_self(), encodeBool: value forKey: key] }
64 }
65
66 #[method]
68 pub fn encode_bycopy_object<T>(&mut self, object: T)
69 where
70 T: PNSObject + ToId,
71 {
72 unsafe { msg_send![self.m_self(), encodeBycopy: object.to_id()] }
73 }
74
75 #[method]
77 pub fn encode_byref_object<T>(&mut self, object: T)
78 where
79 T: PNSObject,
80 {
81 unsafe { msg_send![self.m_self(), encodeByref: object] }
82 }
83
84 #[method]
86 pub fn encode_bytes_length(&mut self, bytes: *const c_void, length: UInt) {
87 unsafe { msg_send![self.m_self(), encodeBytes: bytes length: length] }
88 }
89
90 #[method]
92 pub fn encode_bytes_length_for_key(
93 &mut self,
94 bytes: *const UInt8,
95 length: UInt,
96 key: NSString,
97 ) {
98 unsafe { msg_send![self.m_self(), encodeBytes: bytes length: length forKey: key] }
99 }
100
101 #[method]
103 pub fn encode_conditional_object<T>(&mut self, object: T)
104 where
105 T: PNSObject,
106 {
107 unsafe { msg_send![self.m_self(), encodeConditionalObject: object] }
108 }
109
110 #[method]
112 pub fn encode_conditional_object_for_key<T>(&mut self, object: T, key: NSString)
113 where
114 T: PNSObject,
115 {
116 unsafe { msg_send![self.m_self(), encodeConditionalObject: object forKey: key] }
117 }
118
119 #[method]
121 pub fn encode_data_object<T>(&mut self, object: T)
122 where
123 T: PNSObject,
124 {
125 unsafe { msg_send![self.m_self(), encodeDataObject: object] }
126 }
127
128 #[method]
130 pub fn encode_double_for_key(&mut self, value: c_double, key: NSString) {
131 unsafe { msg_send![self.m_self(), encodeDouble: value forKey: key] }
132 }
133
134 #[method]
136 pub fn encode_float_for_key(&mut self, value: c_float, key: NSString) {
137 unsafe { msg_send![self.m_self(), encodeFloat: value forKey: key] }
138 }
139
140 #[method]
142 pub fn encode_int_for_key(&mut self, value: Int, key: NSString) {
143 unsafe { msg_send![self.m_self(), encodeInt: value forKey: key] }
144 }
145
146 #[method]
148 pub fn encode_integer_for_key(&mut self, value: Int, key: NSString) {
149 unsafe { msg_send![self.m_self(), encodeInteger: value forKey: key] }
150 }
151
152 #[method]
154 pub fn encode_int32_for_key(&mut self, value: Int32, key: NSString) {
155 unsafe { msg_send![self.m_self(), encodeInt32: value forKey: key] }
156 }
157
158 #[method]
160 pub fn encode_int64_for_key(&mut self, value: Int64, key: NSString) {
161 unsafe { msg_send![self.m_self(), encodeInt64: value forKey: key] }
162 }
163
164 #[method]
166 pub fn encode_object<T>(&mut self, object: T)
167 where
168 T: PNSObject,
169 {
170 unsafe { msg_send![self.m_self(), encodeObject: object] }
171 }
172
173 #[method]
175 pub fn encode_object_for_key<T>(&mut self, object: T, key: NSString)
176 where
177 T: PNSObject,
178 {
179 unsafe { msg_send![self.m_self(), encodeObject: object forKey: key] }
180 }
181
182 #[method]
184 pub fn encode_point(&mut self, point: NSPoint) {
185 unsafe { msg_send![self.m_self(), encodePoint: point] }
186 }
187
188 #[method]
190 pub fn encode_point_for_key(&mut self, point: NSPoint, key: NSString) {
191 unsafe { msg_send![self.m_self(), encodePoint: point forKey: key] }
192 }
193
194 #[method]
196 pub fn encode_property_list(&mut self, property_list: id) {
197 unsafe { msg_send![self.m_self(), encodePropertyList: property_list] }
198 }
199
200 #[method]
202 pub fn encode_rect(&mut self, rect: NSRect) {
203 unsafe { msg_send![self.m_self(), encodeRect: rect] }
204 }
205
206 #[method]
208 pub fn encode_rect_for_key(&mut self, rect: NSRect, key: NSString) {
209 unsafe { msg_send![self.m_self(), encodeRect: rect forKey: key] }
210 }
211
212 #[method]
214 pub fn encode_root_object(&mut self, root_object: id) {
215 unsafe { msg_send![self.m_self(), encodeRootObject: root_object] }
216 }
217
218 #[method]
220 pub fn encode_size(&mut self, size: NSSize) {
221 unsafe { msg_send![self.m_self(), encodeSize: size] }
222 }
223
224 #[method]
226 pub fn encode_size_for_key(&mut self, size: NSSize, key: NSString) {
227 unsafe { msg_send![self.m_self(), encodeSize: size forKey: key] }
228 }
229
230 #[method]
232 pub fn encode_value_of_objc_type_at(&mut self, _type: *const c_char, addr: *const c_void) {
233 unsafe { msg_send![self.m_self(), encodeValueOfObjCType: _type at: addr] }
234 }
235
236 #[method]
238 pub fn encode_cgpoint_for_key(&mut self, point: CGPoint, key: NSString) {
239 unsafe { msg_send![self.m_self(), encodeCGPoint: point forKey: key] }
240 }
241
242 #[method]
244 pub fn encode_cgrect_for_key(&mut self, rect: CGRect, key: NSString) {
245 unsafe { msg_send![self.m_self(), encodeCGRect: rect forKey: key] }
246 }
247
248 #[method]
250 pub fn encode_cgzize_for_key(&mut self, size: CGSize, key: NSString) {
251 unsafe { msg_send![self.m_self(), encodeCGSize: size forKey: key] }
252 }
253}