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