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")]
18#[deprecated = "GC no longer supported"]
19pub static NSMapTableZeroingWeakMemory: NSPointerFunctionsOptions =
20 NSPointerFunctionsOptions(NSPointerFunctionsOptions::ZeroingWeakMemory.0);
21
22#[cfg(feature = "NSPointerFunctions")]
24pub static NSMapTableCopyIn: NSPointerFunctionsOptions =
25 NSPointerFunctionsOptions(NSPointerFunctionsOptions::CopyIn.0);
26
27#[cfg(feature = "NSPointerFunctions")]
29pub static NSMapTableObjectPointerPersonality: NSPointerFunctionsOptions =
30 NSPointerFunctionsOptions(NSPointerFunctionsOptions::ObjectPointerPersonality.0);
31
32#[cfg(feature = "NSPointerFunctions")]
34pub static NSMapTableWeakMemory: NSPointerFunctionsOptions =
35 NSPointerFunctionsOptions(NSPointerFunctionsOptions::WeakMemory.0);
36
37pub type NSMapTableOptions = NSUInteger;
39
40extern_class!(
41 #[unsafe(super(NSObject))]
43 #[derive(Debug, PartialEq, Eq, Hash)]
44 pub struct NSMapTable<KeyType: ?Sized = AnyObject, ObjectType: ?Sized = AnyObject>;
45);
46
47impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> NSMapTable<KeyType, ObjectType> {
48 #[inline]
54 pub unsafe fn cast_unchecked<NewKeyType: ?Sized + Message, NewObjectType: ?Sized + Message>(
55 &self,
56 ) -> &NSMapTable<NewKeyType, NewObjectType> {
57 unsafe { &*((self as *const Self).cast()) }
58 }
59}
60
61#[cfg(feature = "NSObject")]
62extern_conformance!(
63 unsafe impl<KeyType: ?Sized + NSCoding, ObjectType: ?Sized + NSCoding> NSCoding
64 for NSMapTable<KeyType, ObjectType>
65 {
66 }
67);
68
69#[cfg(feature = "NSObject")]
70extern_conformance!(
71 unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying for NSMapTable<KeyType, ObjectType> {}
72);
73
74#[cfg(feature = "NSObject")]
75unsafe impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> CopyingHelper
76 for NSMapTable<KeyType, ObjectType>
77{
78 type Result = Self;
79}
80
81#[cfg(feature = "NSEnumerator")]
82extern_conformance!(
83 unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSFastEnumeration
84 for NSMapTable<KeyType, ObjectType>
85 {
86 }
87);
88
89extern_conformance!(
90 unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSObjectProtocol
91 for NSMapTable<KeyType, ObjectType>
92 {
93 }
94);
95
96#[cfg(feature = "NSObject")]
97extern_conformance!(
98 unsafe impl<KeyType: ?Sized + NSSecureCoding, ObjectType: ?Sized + NSSecureCoding>
99 NSSecureCoding for NSMapTable<KeyType, ObjectType>
100 {
101 }
102);
103
104impl<KeyType: Message, ObjectType: Message> NSMapTable<KeyType, ObjectType> {
105 extern_methods!(
106 #[cfg(feature = "NSPointerFunctions")]
107 #[unsafe(method(initWithKeyOptions:valueOptions:capacity:))]
108 #[unsafe(method_family = init)]
109 pub fn initWithKeyOptions_valueOptions_capacity(
110 this: Allocated<Self>,
111 key_options: NSPointerFunctionsOptions,
112 value_options: NSPointerFunctionsOptions,
113 initial_capacity: NSUInteger,
114 ) -> Retained<Self>;
115
116 #[cfg(feature = "NSPointerFunctions")]
117 #[unsafe(method(initWithKeyPointerFunctions:valuePointerFunctions:capacity:))]
118 #[unsafe(method_family = init)]
119 pub fn initWithKeyPointerFunctions_valuePointerFunctions_capacity(
120 this: Allocated<Self>,
121 key_functions: &NSPointerFunctions,
122 value_functions: &NSPointerFunctions,
123 initial_capacity: NSUInteger,
124 ) -> Retained<Self>;
125
126 #[cfg(feature = "NSPointerFunctions")]
127 #[unsafe(method(mapTableWithKeyOptions:valueOptions:))]
128 #[unsafe(method_family = none)]
129 pub fn mapTableWithKeyOptions_valueOptions(
130 key_options: NSPointerFunctionsOptions,
131 value_options: NSPointerFunctionsOptions,
132 ) -> Retained<NSMapTable<KeyType, ObjectType>>;
133
134 #[deprecated = "GC no longer supported"]
135 #[unsafe(method(mapTableWithStrongToStrongObjects))]
136 #[unsafe(method_family = none)]
137 pub fn mapTableWithStrongToStrongObjects() -> Retained<AnyObject>;
138
139 #[deprecated = "GC no longer supported"]
140 #[unsafe(method(mapTableWithWeakToStrongObjects))]
141 #[unsafe(method_family = none)]
142 pub fn mapTableWithWeakToStrongObjects() -> Retained<AnyObject>;
143
144 #[deprecated = "GC no longer supported"]
145 #[unsafe(method(mapTableWithStrongToWeakObjects))]
146 #[unsafe(method_family = none)]
147 pub fn mapTableWithStrongToWeakObjects() -> Retained<AnyObject>;
148
149 #[deprecated = "GC no longer supported"]
150 #[unsafe(method(mapTableWithWeakToWeakObjects))]
151 #[unsafe(method_family = none)]
152 pub fn mapTableWithWeakToWeakObjects() -> Retained<AnyObject>;
153
154 #[unsafe(method(strongToStrongObjectsMapTable))]
155 #[unsafe(method_family = none)]
156 pub fn strongToStrongObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
157
158 #[unsafe(method(weakToStrongObjectsMapTable))]
159 #[unsafe(method_family = none)]
160 pub fn weakToStrongObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
161
162 #[unsafe(method(strongToWeakObjectsMapTable))]
163 #[unsafe(method_family = none)]
164 pub fn strongToWeakObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
165
166 #[unsafe(method(weakToWeakObjectsMapTable))]
167 #[unsafe(method_family = none)]
168 pub fn weakToWeakObjectsMapTable() -> Retained<NSMapTable<KeyType, ObjectType>>;
169
170 #[cfg(feature = "NSPointerFunctions")]
171 #[unsafe(method(keyPointerFunctions))]
172 #[unsafe(method_family = none)]
173 pub fn keyPointerFunctions(&self) -> Retained<NSPointerFunctions>;
174
175 #[cfg(feature = "NSPointerFunctions")]
176 #[unsafe(method(valuePointerFunctions))]
177 #[unsafe(method_family = none)]
178 pub fn valuePointerFunctions(&self) -> Retained<NSPointerFunctions>;
179
180 #[unsafe(method(objectForKey:))]
181 #[unsafe(method_family = none)]
182 pub fn objectForKey(&self, a_key: Option<&KeyType>) -> Option<Retained<ObjectType>>;
183
184 #[unsafe(method(removeObjectForKey:))]
185 #[unsafe(method_family = none)]
186 pub fn removeObjectForKey(&self, a_key: Option<&KeyType>);
187
188 #[unsafe(method(setObject:forKey:))]
189 #[unsafe(method_family = none)]
190 pub fn setObject_forKey(&self, an_object: Option<&ObjectType>, a_key: Option<&KeyType>);
191
192 #[unsafe(method(count))]
193 #[unsafe(method_family = none)]
194 pub fn count(&self) -> NSUInteger;
195
196 #[cfg(feature = "NSEnumerator")]
197 #[unsafe(method(keyEnumerator))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn keyEnumerator(&self) -> Retained<NSEnumerator<KeyType>>;
203
204 #[cfg(feature = "NSEnumerator")]
205 #[unsafe(method(objectEnumerator))]
209 #[unsafe(method_family = none)]
210 pub unsafe fn objectEnumerator(&self) -> Option<Retained<NSEnumerator<ObjectType>>>;
211
212 #[unsafe(method(removeAllObjects))]
213 #[unsafe(method_family = none)]
214 pub fn removeAllObjects(&self);
215
216 #[cfg(feature = "NSDictionary")]
217 #[unsafe(method(dictionaryRepresentation))]
218 #[unsafe(method_family = none)]
219 pub fn dictionaryRepresentation(&self) -> Retained<NSDictionary<KeyType, ObjectType>>;
220 );
221}
222
223impl<KeyType: Message, ObjectType: Message> NSMapTable<KeyType, ObjectType> {
225 extern_methods!(
226 #[unsafe(method(init))]
227 #[unsafe(method_family = init)]
228 pub fn init(this: Allocated<Self>) -> Retained<Self>;
229
230 #[unsafe(method(new))]
231 #[unsafe(method_family = new)]
232 pub fn new() -> Retained<Self>;
233 );
234}
235
236impl<KeyType: Message, ObjectType: Message> DefaultRetained for NSMapTable<KeyType, ObjectType> {
237 #[inline]
238 fn default_retained() -> Retained<Self> {
239 Self::new()
240 }
241}
242
243#[repr(C)]
247#[derive(Clone, Copy, Debug, PartialEq)]
248pub struct NSMapEnumerator {
249 pub(crate) _pi: NSUInteger,
250 pub(crate) _si: NSUInteger,
251 pub(crate) _bs: *mut c_void,
252}
253
254unsafe impl Encode for NSMapEnumerator {
255 const ENCODING: Encoding = Encoding::Struct(
256 "?",
257 &[
258 <NSUInteger>::ENCODING,
259 <NSUInteger>::ENCODING,
260 <*mut c_void>::ENCODING,
261 ],
262 );
263}
264
265unsafe impl RefEncode for NSMapEnumerator {
266 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
267}
268
269extern "C-unwind" {
270 pub fn NSResetMapTable(table: &NSMapTable);
274}
275
276#[inline]
281pub unsafe extern "C-unwind" fn NSCompareMapTables(
282 table1: &NSMapTable,
283 table2: &NSMapTable,
284) -> bool {
285 extern "C-unwind" {
286 fn NSCompareMapTables(table1: &NSMapTable, table2: &NSMapTable) -> Bool;
287 }
288 unsafe { NSCompareMapTables(table1, table2) }.as_bool()
289}
290
291#[cfg(feature = "NSZone")]
296#[inline]
297pub unsafe extern "C-unwind" fn NSCopyMapTableWithZone(
298 table: &NSMapTable,
299 zone: *mut NSZone,
300) -> Retained<NSMapTable> {
301 extern "C-unwind" {
302 fn NSCopyMapTableWithZone(table: &NSMapTable, zone: *mut NSZone) -> *mut NSMapTable;
303 }
304 let ret = unsafe { NSCopyMapTableWithZone(table, zone) };
305 unsafe { Retained::from_raw(ret) }
306 .expect("function was marked as returning non-null, but actually returned NULL")
307}
308
309#[inline]
316pub unsafe extern "C-unwind" fn NSMapMember(
317 table: &NSMapTable,
318 key: NonNull<c_void>,
319 original_key: *mut *mut c_void,
320 value: *mut *mut c_void,
321) -> bool {
322 extern "C-unwind" {
323 fn NSMapMember(
324 table: &NSMapTable,
325 key: NonNull<c_void>,
326 original_key: *mut *mut c_void,
327 value: *mut *mut c_void,
328 ) -> Bool;
329 }
330 unsafe { NSMapMember(table, key, original_key, value) }.as_bool()
331}
332
333extern "C-unwind" {
334 pub fn NSMapGet(table: &NSMapTable, key: *const c_void) -> *mut c_void;
339}
340
341extern "C-unwind" {
342 pub fn NSMapInsert(table: &NSMapTable, key: *const c_void, value: *const c_void);
348}
349
350extern "C-unwind" {
351 pub fn NSMapInsertKnownAbsent(table: &NSMapTable, key: *const c_void, value: *const c_void);
357}
358
359extern "C-unwind" {
360 pub fn NSMapInsertIfAbsent(
366 table: &NSMapTable,
367 key: *const c_void,
368 value: *const c_void,
369 ) -> *mut c_void;
370}
371
372extern "C-unwind" {
373 pub fn NSMapRemove(table: &NSMapTable, key: *const c_void);
378}
379
380extern "C-unwind" {
381 pub fn NSEnumerateMapTable(table: &NSMapTable) -> NSMapEnumerator;
385}
386
387#[inline]
393pub unsafe extern "C-unwind" fn NSNextMapEnumeratorPair(
394 enumerator: NonNull<NSMapEnumerator>,
395 key: *mut *mut c_void,
396 value: *mut *mut c_void,
397) -> bool {
398 extern "C-unwind" {
399 fn NSNextMapEnumeratorPair(
400 enumerator: NonNull<NSMapEnumerator>,
401 key: *mut *mut c_void,
402 value: *mut *mut c_void,
403 ) -> Bool;
404 }
405 unsafe { NSNextMapEnumeratorPair(enumerator, key, value) }.as_bool()
406}
407
408extern "C-unwind" {
409 pub fn NSEndMapTableEnumeration(enumerator: NonNull<NSMapEnumerator>);
413}
414
415extern "C-unwind" {
416 pub fn NSCountMapTable(table: &NSMapTable) -> NSUInteger;
420}
421
422#[cfg(feature = "NSString")]
423impl NSString {
424 #[doc(alias = "NSStringFromMapTable")]
428 #[cfg(feature = "NSString")]
429 #[inline]
430 pub unsafe fn from_map_table(table: &NSMapTable) -> Retained<NSString> {
431 extern "C-unwind" {
432 fn NSStringFromMapTable(table: &NSMapTable) -> *mut NSString;
433 }
434 let ret = unsafe { NSStringFromMapTable(table) };
435 unsafe { Retained::retain_autoreleased(ret) }
436 .expect("function was marked as returning non-null, but actually returned NULL")
437 }
438}
439
440#[cfg(feature = "NSArray")]
444#[inline]
445pub unsafe extern "C-unwind" fn NSAllMapTableKeys(table: &NSMapTable) -> Retained<NSArray> {
446 extern "C-unwind" {
447 fn NSAllMapTableKeys(table: &NSMapTable) -> *mut NSArray;
448 }
449 let ret = unsafe { NSAllMapTableKeys(table) };
450 unsafe { Retained::retain_autoreleased(ret) }
451 .expect("function was marked as returning non-null, but actually returned NULL")
452}
453
454#[cfg(feature = "NSArray")]
458#[inline]
459pub unsafe extern "C-unwind" fn NSAllMapTableValues(table: &NSMapTable) -> Retained<NSArray> {
460 extern "C-unwind" {
461 fn NSAllMapTableValues(table: &NSMapTable) -> *mut NSArray;
462 }
463 let ret = unsafe { NSAllMapTableValues(table) };
464 unsafe { Retained::retain_autoreleased(ret) }
465 .expect("function was marked as returning non-null, but actually returned NULL")
466}
467
468#[cfg(feature = "NSString")]
472#[repr(C)]
473#[allow(unpredictable_function_pointer_comparisons)]
474#[derive(Clone, Copy, Debug, PartialEq)]
475pub struct NSMapTableKeyCallBacks {
476 pub hash:
477 Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> NSUInteger>,
478 pub isEqual: Option<
479 unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>, NonNull<c_void>) -> Bool,
480 >,
481 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
482 pub release: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
483 pub describe:
484 Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> *mut NSString>,
485 pub notAKeyMarker: *const c_void,
486}
487
488#[cfg(feature = "NSString")]
489unsafe impl Encode for NSMapTableKeyCallBacks {
490 const ENCODING: Encoding = Encoding::Struct("?", &[
491 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,) -> NSUInteger>>::ENCODING,
492 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,NonNull<c_void>,) -> Bool>>::ENCODING,
493 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,)>>::ENCODING,
494 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,)>>::ENCODING,
495 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>,NonNull<c_void>,) -> *mut NSString>>::ENCODING,
496 <*const c_void>::ENCODING,
497 ]);
498}
499
500#[cfg(feature = "NSString")]
501unsafe impl RefEncode for NSMapTableKeyCallBacks {
502 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
503}
504
505#[cfg(feature = "NSString")]
507#[repr(C)]
508#[allow(unpredictable_function_pointer_comparisons)]
509#[derive(Clone, Copy, Debug, PartialEq)]
510pub struct NSMapTableValueCallBacks {
511 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
512 pub release: Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>,
513 pub describe:
514 Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> *mut NSString>,
515}
516
517#[cfg(feature = "NSString")]
518unsafe impl Encode for NSMapTableValueCallBacks {
519 const ENCODING: Encoding = Encoding::Struct(
520 "?",
521 &[
522 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>>::ENCODING,
523 <Option<unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>)>>::ENCODING,
524 <Option<
525 unsafe extern "C-unwind" fn(NonNull<NSMapTable>, NonNull<c_void>) -> *mut NSString,
526 >>::ENCODING,
527 ],
528 );
529}
530
531#[cfg(feature = "NSString")]
532unsafe impl RefEncode for NSMapTableValueCallBacks {
533 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
534}
535
536#[cfg(all(feature = "NSString", feature = "NSZone"))]
549#[inline]
550pub unsafe extern "C-unwind" fn NSCreateMapTableWithZone(
551 key_call_backs: NSMapTableKeyCallBacks,
552 value_call_backs: NSMapTableValueCallBacks,
553 capacity: NSUInteger,
554 zone: *mut NSZone,
555) -> Retained<NSMapTable> {
556 extern "C-unwind" {
557 fn NSCreateMapTableWithZone(
558 key_call_backs: NSMapTableKeyCallBacks,
559 value_call_backs: NSMapTableValueCallBacks,
560 capacity: NSUInteger,
561 zone: *mut NSZone,
562 ) -> *mut NSMapTable;
563 }
564 let ret = unsafe { NSCreateMapTableWithZone(key_call_backs, value_call_backs, capacity, zone) };
565 unsafe { Retained::from_raw(ret) }
566 .expect("function was marked as returning non-null, but actually returned NULL")
567}
568
569#[cfg(feature = "NSString")]
581#[inline]
582pub unsafe extern "C-unwind" fn NSCreateMapTable(
583 key_call_backs: NSMapTableKeyCallBacks,
584 value_call_backs: NSMapTableValueCallBacks,
585 capacity: NSUInteger,
586) -> Retained<NSMapTable> {
587 extern "C-unwind" {
588 fn NSCreateMapTable(
589 key_call_backs: NSMapTableKeyCallBacks,
590 value_call_backs: NSMapTableValueCallBacks,
591 capacity: NSUInteger,
592 ) -> *mut NSMapTable;
593 }
594 let ret = unsafe { NSCreateMapTable(key_call_backs, value_call_backs, capacity) };
595 unsafe { Retained::from_raw(ret) }
596 .expect("function was marked as returning non-null, but actually returned NULL")
597}
598
599extern "C" {
600 #[cfg(feature = "NSString")]
604 pub static NSIntegerMapKeyCallBacks: NSMapTableKeyCallBacks;
605}
606
607extern "C" {
608 #[cfg(feature = "NSString")]
610 pub static NSNonOwnedPointerMapKeyCallBacks: NSMapTableKeyCallBacks;
611}
612
613extern "C" {
614 #[cfg(feature = "NSString")]
616 pub static NSNonOwnedPointerOrNullMapKeyCallBacks: NSMapTableKeyCallBacks;
617}
618
619extern "C" {
620 #[cfg(feature = "NSString")]
622 pub static NSNonRetainedObjectMapKeyCallBacks: NSMapTableKeyCallBacks;
623}
624
625extern "C" {
626 #[cfg(feature = "NSString")]
628 pub static NSObjectMapKeyCallBacks: NSMapTableKeyCallBacks;
629}
630
631extern "C" {
632 #[cfg(feature = "NSString")]
634 pub static NSOwnedPointerMapKeyCallBacks: NSMapTableKeyCallBacks;
635}
636
637extern "C" {
638 #[cfg(feature = "NSString")]
640 #[deprecated = "Not supported"]
641 pub static NSIntMapKeyCallBacks: NSMapTableKeyCallBacks;
642}
643
644extern "C" {
645 #[cfg(feature = "NSString")]
649 pub static NSIntegerMapValueCallBacks: NSMapTableValueCallBacks;
650}
651
652extern "C" {
653 #[cfg(feature = "NSString")]
655 pub static NSNonOwnedPointerMapValueCallBacks: NSMapTableValueCallBacks;
656}
657
658extern "C" {
659 #[cfg(feature = "NSString")]
661 pub static NSObjectMapValueCallBacks: NSMapTableValueCallBacks;
662}
663
664extern "C" {
665 #[cfg(feature = "NSString")]
667 pub static NSNonRetainedObjectMapValueCallBacks: NSMapTableValueCallBacks;
668}
669
670extern "C" {
671 #[cfg(feature = "NSString")]
673 pub static NSOwnedPointerMapValueCallBacks: NSMapTableValueCallBacks;
674}
675
676extern "C" {
677 #[cfg(feature = "NSString")]
679 #[deprecated = "Not supported"]
680 pub static NSIntMapValueCallBacks: NSMapTableValueCallBacks;
681}
682
683#[cfg(feature = "NSString")]
684#[deprecated = "renamed to `NSString::from_map_table`"]
685#[inline]
686pub unsafe extern "C-unwind" fn NSStringFromMapTable(table: &NSMapTable) -> Retained<NSString> {
687 extern "C-unwind" {
688 fn NSStringFromMapTable(table: &NSMapTable) -> *mut NSString;
689 }
690 let ret = unsafe { NSStringFromMapTable(table) };
691 unsafe { Retained::retain_autoreleased(ret) }
692 .expect("function was marked as returning non-null, but actually returned NULL")
693}