1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[cfg(feature = "NSPointerFunctions")]
13pub static NSMapTableStrongMemory: NSPointerFunctionsOptions =
14 NSPointerFunctionsOptions(NSPointerFunctionsOptions::StrongMemory.0);
15
16#[cfg(feature = "NSPointerFunctions")]
18pub static NSMapTableZeroingWeakMemory: NSPointerFunctionsOptions =
19 NSPointerFunctionsOptions(NSPointerFunctionsOptions::ZeroingWeakMemory.0);
20
21#[cfg(feature = "NSPointerFunctions")]
23pub static NSMapTableCopyIn: NSPointerFunctionsOptions =
24 NSPointerFunctionsOptions(NSPointerFunctionsOptions::CopyIn.0);
25
26#[cfg(feature = "NSPointerFunctions")]
28pub static NSMapTableObjectPointerPersonality: NSPointerFunctionsOptions =
29 NSPointerFunctionsOptions(NSPointerFunctionsOptions::ObjectPointerPersonality.0);
30
31#[cfg(feature = "NSPointerFunctions")]
33pub static NSMapTableWeakMemory: NSPointerFunctionsOptions =
34 NSPointerFunctionsOptions(NSPointerFunctionsOptions::WeakMemory.0);
35
36pub type NSMapTableOptions = NSUInteger;
38
39extern_class!(
40 #[unsafe(super(NSObject))]
42 #[derive(Debug, PartialEq, Eq, Hash)]
43 pub struct NSMapTable<KeyType: ?Sized = AnyObject, ObjectType: ?Sized = AnyObject>;
44);
45
46#[cfg(feature = "NSObject")]
47unsafe impl<KeyType: ?Sized + NSCoding, ObjectType: ?Sized + NSCoding> NSCoding
48 for NSMapTable<KeyType, ObjectType>
49{
50}
51
52#[cfg(feature = "NSObject")]
53unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying for NSMapTable<KeyType, ObjectType> {}
54
55#[cfg(feature = "NSObject")]
56unsafe impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> CopyingHelper
57 for NSMapTable<KeyType, ObjectType>
58{
59 type Result = Self;
60}
61
62#[cfg(feature = "NSEnumerator")]
63unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSFastEnumeration
64 for NSMapTable<KeyType, ObjectType>
65{
66}
67
68unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSObjectProtocol
69 for NSMapTable<KeyType, ObjectType>
70{
71}
72
73#[cfg(feature = "NSObject")]
74unsafe impl<KeyType: ?Sized + NSSecureCoding, ObjectType: ?Sized + NSSecureCoding> NSSecureCoding
75 for NSMapTable<KeyType, ObjectType>
76{
77}
78
79impl<KeyType: Message, ObjectType: Message> NSMapTable<KeyType, ObjectType> {
80 extern_methods!(
81 #[cfg(feature = "NSPointerFunctions")]
82 #[unsafe(method(initWithKeyOptions:valueOptions:capacity:))]
83 #[unsafe(method_family = init)]
84 pub unsafe fn initWithKeyOptions_valueOptions_capacity(
85 this: Allocated<Self>,
86 key_options: NSPointerFunctionsOptions,
87 value_options: NSPointerFunctionsOptions,
88 initial_capacity: NSUInteger,
89 ) -> Retained<Self>;
90
91 #[cfg(feature = "NSPointerFunctions")]
92 #[unsafe(method(initWithKeyPointerFunctions:valuePointerFunctions:capacity:))]
93 #[unsafe(method_family = init)]
94 pub unsafe fn initWithKeyPointerFunctions_valuePointerFunctions_capacity(
95 this: Allocated<Self>,
96 key_functions: &NSPointerFunctions,
97 value_functions: &NSPointerFunctions,
98 initial_capacity: NSUInteger,
99 ) -> Retained<Self>;
100
101 #[cfg(feature = "NSPointerFunctions")]
102 #[unsafe(method(mapTableWithKeyOptions:valueOptions:))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn mapTableWithKeyOptions_valueOptions(
105 key_options: NSPointerFunctionsOptions,
106 value_options: NSPointerFunctionsOptions,
107 ) -> Retained<NSMapTable<KeyType, ObjectType>>;
108
109 #[deprecated = "GC no longer supported"]
110 #[unsafe(method(mapTableWithStrongToStrongObjects))]
111 #[unsafe(method_family = none)]
112 pub unsafe fn mapTableWithStrongToStrongObjects() -> Retained<AnyObject>;
113
114 #[deprecated = "GC no longer supported"]
115 #[unsafe(method(mapTableWithWeakToStrongObjects))]
116 #[unsafe(method_family = none)]
117 pub unsafe fn mapTableWithWeakToStrongObjects() -> Retained<AnyObject>;
118
119 #[deprecated = "GC no longer supported"]
120 #[unsafe(method(mapTableWithStrongToWeakObjects))]
121 #[unsafe(method_family = none)]
122 pub unsafe fn mapTableWithStrongToWeakObjects() -> Retained<AnyObject>;
123
124 #[deprecated = "GC no longer supported"]
125 #[unsafe(method(mapTableWithWeakToWeakObjects))]
126 #[unsafe(method_family = none)]
127 pub unsafe fn mapTableWithWeakToWeakObjects() -> Retained<AnyObject>;
128
129 #[unsafe(method(strongToStrongObjectsMapTable))]
130 #[unsafe(method_family = none)]
131 pub unsafe fn strongToStrongObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
132
133 #[unsafe(method(weakToStrongObjectsMapTable))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn weakToStrongObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
136
137 #[unsafe(method(strongToWeakObjectsMapTable))]
138 #[unsafe(method_family = none)]
139 pub unsafe fn strongToWeakObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
140
141 #[unsafe(method(weakToWeakObjectsMapTable))]
142 #[unsafe(method_family = none)]
143 pub unsafe fn weakToWeakObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
144
145 #[cfg(feature = "NSPointerFunctions")]
146 #[unsafe(method(keyPointerFunctions))]
147 #[unsafe(method_family = none)]
148 pub unsafe fn keyPointerFunctions(&self) -> Retained<NSPointerFunctions>;
149
150 #[cfg(feature = "NSPointerFunctions")]
151 #[unsafe(method(valuePointerFunctions))]
152 #[unsafe(method_family = none)]
153 pub unsafe fn valuePointerFunctions(&self) -> Retained<NSPointerFunctions>;
154
155 #[unsafe(method(objectForKey:))]
156 #[unsafe(method_family = none)]
157 pub unsafe fn objectForKey(&self, a_key: Option<&KeyType>) -> Option<Retained<ObjectType>>;
158
159 #[unsafe(method(removeObjectForKey:))]
160 #[unsafe(method_family = none)]
161 pub unsafe fn removeObjectForKey(&self, a_key: Option<&KeyType>);
162
163 #[unsafe(method(setObject:forKey:))]
164 #[unsafe(method_family = none)]
165 pub unsafe fn setObject_forKey(
166 &self,
167 an_object: Option<&ObjectType>,
168 a_key: Option<&KeyType>,
169 );
170
171 #[unsafe(method(count))]
172 #[unsafe(method_family = none)]
173 pub unsafe fn count(&self) -> NSUInteger;
174
175 #[cfg(feature = "NSEnumerator")]
176 #[unsafe(method(keyEnumerator))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn keyEnumerator(&self) -> Retained<NSEnumerator<KeyType>>;
179
180 #[cfg(feature = "NSEnumerator")]
181 #[unsafe(method(objectEnumerator))]
182 #[unsafe(method_family = none)]
183 pub unsafe fn objectEnumerator(&self) -> Option<Retained<NSEnumerator<ObjectType>>>;
184
185 #[unsafe(method(removeAllObjects))]
186 #[unsafe(method_family = none)]
187 pub unsafe fn removeAllObjects(&self);
188
189 #[cfg(feature = "NSDictionary")]
190 #[unsafe(method(dictionaryRepresentation))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn dictionaryRepresentation(
193 &self,
194 ) -> Retained<NSDictionary<KeyType, ObjectType>>;
195 );
196}
197
198impl<KeyType: Message, ObjectType: Message> NSMapTable<KeyType, ObjectType> {
200 extern_methods!(
201 #[unsafe(method(init))]
202 #[unsafe(method_family = init)]
203 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
204
205 #[unsafe(method(new))]
206 #[unsafe(method_family = new)]
207 pub unsafe fn new() -> Retained<Self>;
208 );
209}
210
211#[repr(C)]
215#[derive(Clone, Copy, Debug, PartialEq)]
216pub struct NSMapEnumerator {
217 pub(crate) _pi: NSUInteger,
218 pub(crate) _si: NSUInteger,
219 pub(crate) _bs: *mut c_void,
220}
221
222unsafe impl Encode for NSMapEnumerator {
223 const ENCODING: Encoding = Encoding::Struct(
224 "?",
225 &[
226 <NSUInteger>::ENCODING,
227 <NSUInteger>::ENCODING,
228 <*mut c_void>::ENCODING,
229 ],
230 );
231}
232
233unsafe impl RefEncode for NSMapEnumerator {
234 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
235}
236
237extern "C-unwind" {
238 pub fn NSResetMapTable(table: &NSMapTable);
239}
240
241#[inline]
242pub unsafe extern "C-unwind" fn NSCompareMapTables(
243 table1: &NSMapTable,
244 table2: &NSMapTable,
245) -> bool {
246 extern "C-unwind" {
247 fn NSCompareMapTables(table1: &NSMapTable, table2: &NSMapTable) -> Bool;
248 }
249 unsafe { NSCompareMapTables(table1, table2) }.as_bool()
250}
251
252#[cfg(feature = "NSZone")]
253#[inline]
254pub unsafe extern "C-unwind" fn NSCopyMapTableWithZone(
255 table: &NSMapTable,
256 zone: *mut NSZone,
257) -> Retained<NSMapTable> {
258 extern "C-unwind" {
259 fn NSCopyMapTableWithZone(table: &NSMapTable, zone: *mut NSZone) -> *mut NSMapTable;
260 }
261 let ret = unsafe { NSCopyMapTableWithZone(table, zone) };
262 unsafe { Retained::from_raw(ret) }
263 .expect("function was marked as returning non-null, but actually returned NULL")
264}
265
266#[inline]
267pub unsafe extern "C-unwind" fn NSMapMember(
268 table: &NSMapTable,
269 key: NonNull<c_void>,
270 original_key: *mut *mut c_void,
271 value: *mut *mut c_void,
272) -> bool {
273 extern "C-unwind" {
274 fn NSMapMember(
275 table: &NSMapTable,
276 key: NonNull<c_void>,
277 original_key: *mut *mut c_void,
278 value: *mut *mut c_void,
279 ) -> Bool;
280 }
281 unsafe { NSMapMember(table, key, original_key, value) }.as_bool()
282}
283
284extern "C-unwind" {
285 pub fn NSMapGet(table: &NSMapTable, key: *const c_void) -> *mut c_void;
286}
287
288extern "C-unwind" {
289 pub fn NSMapInsert(table: &NSMapTable, key: *const c_void, value: *const c_void);
290}
291
292extern "C-unwind" {
293 pub fn NSMapInsertKnownAbsent(table: &NSMapTable, key: *const c_void, value: *const c_void);
294}
295
296extern "C-unwind" {
297 pub fn NSMapInsertIfAbsent(
298 table: &NSMapTable,
299 key: *const c_void,
300 value: *const c_void,
301 ) -> *mut c_void;
302}
303
304extern "C-unwind" {
305 pub fn NSMapRemove(table: &NSMapTable, key: *const c_void);
306}
307
308extern "C-unwind" {
309 pub fn NSEnumerateMapTable(table: &NSMapTable) -> NSMapEnumerator;
310}
311
312#[inline]
313pub unsafe extern "C-unwind" fn NSNextMapEnumeratorPair(
314 enumerator: NonNull<NSMapEnumerator>,
315 key: *mut *mut c_void,
316 value: *mut *mut c_void,
317) -> bool {
318 extern "C-unwind" {
319 fn NSNextMapEnumeratorPair(
320 enumerator: NonNull<NSMapEnumerator>,
321 key: *mut *mut c_void,
322 value: *mut *mut c_void,
323 ) -> Bool;
324 }
325 unsafe { NSNextMapEnumeratorPair(enumerator, key, value) }.as_bool()
326}
327
328extern "C-unwind" {
329 pub fn NSEndMapTableEnumeration(enumerator: NonNull<NSMapEnumerator>);
330}
331
332extern "C-unwind" {
333 pub fn NSCountMapTable(table: &NSMapTable) -> NSUInteger;
334}
335
336#[cfg(feature = "NSString")]
337#[inline]
338pub unsafe extern "C-unwind" fn NSStringFromMapTable(table: &NSMapTable) -> Retained<NSString> {
339 extern "C-unwind" {
340 fn NSStringFromMapTable(table: &NSMapTable) -> *mut NSString;
341 }
342 let ret = unsafe { NSStringFromMapTable(table) };
343 unsafe { Retained::retain_autoreleased(ret) }
344 .expect("function was marked as returning non-null, but actually returned NULL")
345}
346
347#[cfg(feature = "NSArray")]
348#[inline]
349pub unsafe extern "C-unwind" fn NSAllMapTableKeys(table: &NSMapTable) -> Retained<NSArray> {
350 extern "C-unwind" {
351 fn NSAllMapTableKeys(table: &NSMapTable) -> *mut NSArray;
352 }
353 let ret = unsafe { NSAllMapTableKeys(table) };
354 unsafe { Retained::retain_autoreleased(ret) }
355 .expect("function was marked as returning non-null, but actually returned NULL")
356}
357
358#[cfg(feature = "NSArray")]
359#[inline]
360pub unsafe extern "C-unwind" fn NSAllMapTableValues(table: &NSMapTable) -> Retained<NSArray> {
361 extern "C-unwind" {
362 fn NSAllMapTableValues(table: &NSMapTable) -> *mut NSArray;
363 }
364 let ret = unsafe { NSAllMapTableValues(table) };
365 unsafe { Retained::retain_autoreleased(ret) }
366 .expect("function was marked as returning non-null, but actually returned NULL")
367}
368
369#[cfg(feature = "NSString")]
373#[repr(C)]
374#[derive(Clone, Copy, Debug, PartialEq)]
375pub struct NSMapTableKeyCallBacks {
376 pub hash:
377 Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> NSUInteger>,
378 pub isEqual: Option<
379 unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>, NonNull<c_void>) -> Bool,
380 >,
381 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
382 pub release: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
383 pub describe:
384 Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> *mut NSString>,
385 pub notAKeyMarker: *const c_void,
386}
387
388#[cfg(feature = "NSString")]
389unsafe impl Encode for NSMapTableKeyCallBacks {
390 const ENCODING: Encoding = Encoding::Struct("?", &[
391 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,) -> NSUInteger>>::ENCODING,
392 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,NonNull<c_void>,) -> Bool>>::ENCODING,
393 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,)>>::ENCODING,
394 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,)>>::ENCODING,
395 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,) -> *mut NSString>>::ENCODING,
396 <*const c_void>::ENCODING,
397 ]);
398}
399
400#[cfg(feature = "NSString")]
401unsafe impl RefEncode for NSMapTableKeyCallBacks {
402 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
403}
404
405#[cfg(feature = "NSString")]
407#[repr(C)]
408#[derive(Clone, Copy, Debug, PartialEq)]
409pub struct NSMapTableValueCallBacks {
410 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
411 pub release: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
412 pub describe:
413 Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> *mut NSString>,
414}
415
416#[cfg(feature = "NSString")]
417unsafe impl Encode for NSMapTableValueCallBacks {
418 const ENCODING: Encoding = Encoding::Struct(
419 "?",
420 &[
421 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>>::ENCODING,
422 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>>::ENCODING,
423 <Option<
424 unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> *mut NSString,
425 >>::ENCODING,
426 ],
427 );
428}
429
430#[cfg(feature = "NSString")]
431unsafe impl RefEncode for NSMapTableValueCallBacks {
432 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
433}
434
435#[cfg(all(feature = "NSString", feature = "NSZone"))]
436#[inline]
437pub unsafe extern "C-unwind" fn NSCreateMapTableWithZone(
438 key_call_backs: NSMapTableKeyCallBacks,
439 value_call_backs: NSMapTableValueCallBacks,
440 capacity: NSUInteger,
441 zone: *mut NSZone,
442) -> Retained<NSMapTable> {
443 extern "C-unwind" {
444 fn NSCreateMapTableWithZone(
445 key_call_backs: NSMapTableKeyCallBacks,
446 value_call_backs: NSMapTableValueCallBacks,
447 capacity: NSUInteger,
448 zone: *mut NSZone,
449 ) -> *mut NSMapTable;
450 }
451 let ret = unsafe { NSCreateMapTableWithZone(key_call_backs, value_call_backs, capacity, zone) };
452 unsafe { Retained::from_raw(ret) }
453 .expect("function was marked as returning non-null, but actually returned NULL")
454}
455
456#[cfg(feature = "NSString")]
457#[inline]
458pub unsafe extern "C-unwind" fn NSCreateMapTable(
459 key_call_backs: NSMapTableKeyCallBacks,
460 value_call_backs: NSMapTableValueCallBacks,
461 capacity: NSUInteger,
462) -> Retained<NSMapTable> {
463 extern "C-unwind" {
464 fn NSCreateMapTable(
465 key_call_backs: NSMapTableKeyCallBacks,
466 value_call_backs: NSMapTableValueCallBacks,
467 capacity: NSUInteger,
468 ) -> *mut NSMapTable;
469 }
470 let ret = unsafe { NSCreateMapTable(key_call_backs, value_call_backs, capacity) };
471 unsafe { Retained::from_raw(ret) }
472 .expect("function was marked as returning non-null, but actually returned NULL")
473}
474
475extern "C" {
476 #[cfg(feature = "NSString")]
480 pub static NSIntegerMapKeyCallBacks: NSMapTableKeyCallBacks;
481}
482
483extern "C" {
484 #[cfg(feature = "NSString")]
486 pub static NSNonOwnedPointerMapKeyCallBacks: NSMapTableKeyCallBacks;
487}
488
489extern "C" {
490 #[cfg(feature = "NSString")]
492 pub static NSNonOwnedPointerOrNullMapKeyCallBacks: NSMapTableKeyCallBacks;
493}
494
495extern "C" {
496 #[cfg(feature = "NSString")]
498 pub static NSNonRetainedObjectMapKeyCallBacks: NSMapTableKeyCallBacks;
499}
500
501extern "C" {
502 #[cfg(feature = "NSString")]
504 pub static NSObjectMapKeyCallBacks: NSMapTableKeyCallBacks;
505}
506
507extern "C" {
508 #[cfg(feature = "NSString")]
510 pub static NSOwnedPointerMapKeyCallBacks: NSMapTableKeyCallBacks;
511}
512
513extern "C" {
514 #[cfg(feature = "NSString")]
516 pub static NSIntMapKeyCallBacks: NSMapTableKeyCallBacks;
517}
518
519extern "C" {
520 #[cfg(feature = "NSString")]
524 pub static NSIntegerMapValueCallBacks: NSMapTableValueCallBacks;
525}
526
527extern "C" {
528 #[cfg(feature = "NSString")]
530 pub static NSNonOwnedPointerMapValueCallBacks: NSMapTableValueCallBacks;
531}
532
533extern "C" {
534 #[cfg(feature = "NSString")]
536 pub static NSObjectMapValueCallBacks: NSMapTableValueCallBacks;
537}
538
539extern "C" {
540 #[cfg(feature = "NSString")]
542 pub static NSNonRetainedObjectMapValueCallBacks: NSMapTableValueCallBacks;
543}
544
545extern "C" {
546 #[cfg(feature = "NSString")]
548 pub static NSOwnedPointerMapValueCallBacks: NSMapTableValueCallBacks;
549}
550
551extern "C" {
552 #[cfg(feature = "NSString")]
554 pub static NSIntMapValueCallBacks: NSMapTableValueCallBacks;
555}