objc2_foundation/generated/
NSHashTable.rs1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[cfg(feature = "NSPointerFunctions")]
11pub static NSHashTableStrongMemory: NSPointerFunctionsOptions =
12 NSPointerFunctionsOptions(NSPointerFunctionsOptions::StrongMemory.0);
13
14#[cfg(feature = "NSPointerFunctions")]
16pub static NSHashTableZeroingWeakMemory: NSPointerFunctionsOptions =
17 NSPointerFunctionsOptions(NSPointerFunctionsOptions::ZeroingWeakMemory.0);
18
19#[cfg(feature = "NSPointerFunctions")]
21pub static NSHashTableCopyIn: NSPointerFunctionsOptions =
22 NSPointerFunctionsOptions(NSPointerFunctionsOptions::CopyIn.0);
23
24#[cfg(feature = "NSPointerFunctions")]
26pub static NSHashTableObjectPointerPersonality: NSPointerFunctionsOptions =
27 NSPointerFunctionsOptions(NSPointerFunctionsOptions::ObjectPointerPersonality.0);
28
29#[cfg(feature = "NSPointerFunctions")]
31pub static NSHashTableWeakMemory: NSPointerFunctionsOptions =
32 NSPointerFunctionsOptions(NSPointerFunctionsOptions::WeakMemory.0);
33
34pub type NSHashTableOptions = NSUInteger;
36
37extern_class!(
38 #[unsafe(super(NSObject))]
40 #[derive(Debug, PartialEq, Eq, Hash)]
41 pub struct NSHashTable<ObjectType: ?Sized = AnyObject>;
42);
43
44#[cfg(feature = "NSObject")]
45extern_conformance!(
46 unsafe impl<ObjectType: ?Sized + NSCoding> NSCoding for NSHashTable<ObjectType> {}
47);
48
49#[cfg(feature = "NSObject")]
50extern_conformance!(
51 unsafe impl<ObjectType: ?Sized> NSCopying for NSHashTable<ObjectType> {}
52);
53
54#[cfg(feature = "NSObject")]
55unsafe impl<ObjectType: ?Sized + Message> CopyingHelper for NSHashTable<ObjectType> {
56 type Result = Self;
57}
58
59#[cfg(feature = "NSEnumerator")]
60extern_conformance!(
61 unsafe impl<ObjectType: ?Sized> NSFastEnumeration for NSHashTable<ObjectType> {}
62);
63
64extern_conformance!(
65 unsafe impl<ObjectType: ?Sized> NSObjectProtocol for NSHashTable<ObjectType> {}
66);
67
68#[cfg(feature = "NSObject")]
69extern_conformance!(
70 unsafe impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSHashTable<ObjectType> {}
71);
72
73impl<ObjectType: Message> NSHashTable<ObjectType> {
74 extern_methods!(
75 #[cfg(feature = "NSPointerFunctions")]
76 #[unsafe(method(initWithOptions:capacity:))]
77 #[unsafe(method_family = init)]
78 pub unsafe fn initWithOptions_capacity(
79 this: Allocated<Self>,
80 options: NSPointerFunctionsOptions,
81 initial_capacity: NSUInteger,
82 ) -> Retained<Self>;
83
84 #[cfg(feature = "NSPointerFunctions")]
85 #[unsafe(method(initWithPointerFunctions:capacity:))]
86 #[unsafe(method_family = init)]
87 pub unsafe fn initWithPointerFunctions_capacity(
88 this: Allocated<Self>,
89 functions: &NSPointerFunctions,
90 initial_capacity: NSUInteger,
91 ) -> Retained<Self>;
92
93 #[cfg(feature = "NSPointerFunctions")]
94 #[unsafe(method(hashTableWithOptions:))]
95 #[unsafe(method_family = none)]
96 pub unsafe fn hashTableWithOptions(
97 options: NSPointerFunctionsOptions,
98 ) -> Retained<NSHashTable<ObjectType>>;
99
100 #[deprecated = "GC no longer supported"]
101 #[unsafe(method(hashTableWithWeakObjects))]
102 #[unsafe(method_family = none)]
103 pub unsafe fn hashTableWithWeakObjects() -> Retained<AnyObject>;
104
105 #[unsafe(method(weakObjectsHashTable))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn weakObjectsHashTable() -> Retained<NSHashTable<ObjectType>>;
108
109 #[cfg(feature = "NSPointerFunctions")]
110 #[unsafe(method(pointerFunctions))]
111 #[unsafe(method_family = none)]
112 pub unsafe fn pointerFunctions(&self) -> Retained<NSPointerFunctions>;
113
114 #[unsafe(method(count))]
115 #[unsafe(method_family = none)]
116 pub unsafe fn count(&self) -> NSUInteger;
117
118 #[unsafe(method(member:))]
119 #[unsafe(method_family = none)]
120 pub unsafe fn member(&self, object: Option<&ObjectType>) -> Option<Retained<ObjectType>>;
121
122 #[cfg(feature = "NSEnumerator")]
123 #[unsafe(method(objectEnumerator))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>;
126
127 #[unsafe(method(addObject:))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn addObject(&self, object: Option<&ObjectType>);
130
131 #[unsafe(method(removeObject:))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn removeObject(&self, object: Option<&ObjectType>);
134
135 #[unsafe(method(removeAllObjects))]
136 #[unsafe(method_family = none)]
137 pub unsafe fn removeAllObjects(&self);
138
139 #[cfg(feature = "NSArray")]
140 #[unsafe(method(allObjects))]
141 #[unsafe(method_family = none)]
142 pub unsafe fn allObjects(&self) -> Retained<NSArray<ObjectType>>;
143
144 #[unsafe(method(anyObject))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn anyObject(&self) -> Option<Retained<ObjectType>>;
147
148 #[unsafe(method(containsObject:))]
149 #[unsafe(method_family = none)]
150 pub unsafe fn containsObject(&self, an_object: Option<&ObjectType>) -> bool;
151
152 #[unsafe(method(intersectsHashTable:))]
153 #[unsafe(method_family = none)]
154 pub unsafe fn intersectsHashTable(&self, other: &NSHashTable<ObjectType>) -> bool;
155
156 #[unsafe(method(isEqualToHashTable:))]
157 #[unsafe(method_family = none)]
158 pub unsafe fn isEqualToHashTable(&self, other: &NSHashTable<ObjectType>) -> bool;
159
160 #[unsafe(method(isSubsetOfHashTable:))]
161 #[unsafe(method_family = none)]
162 pub unsafe fn isSubsetOfHashTable(&self, other: &NSHashTable<ObjectType>) -> bool;
163
164 #[unsafe(method(intersectHashTable:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn intersectHashTable(&self, other: &NSHashTable<ObjectType>);
167
168 #[unsafe(method(unionHashTable:))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn unionHashTable(&self, other: &NSHashTable<ObjectType>);
171
172 #[unsafe(method(minusHashTable:))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn minusHashTable(&self, other: &NSHashTable<ObjectType>);
175
176 #[cfg(feature = "NSSet")]
177 #[unsafe(method(setRepresentation))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn setRepresentation(&self) -> Retained<NSSet<ObjectType>>;
180 );
181}
182
183impl<ObjectType: Message> NSHashTable<ObjectType> {
185 extern_methods!(
186 #[unsafe(method(init))]
187 #[unsafe(method_family = init)]
188 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
189
190 #[unsafe(method(new))]
191 #[unsafe(method_family = new)]
192 pub unsafe fn new() -> Retained<Self>;
193 );
194}
195
196#[repr(C)]
200#[derive(Clone, Copy, Debug, PartialEq)]
201pub struct NSHashEnumerator {
202 pub(crate) _pi: NSUInteger,
203 pub(crate) _si: NSUInteger,
204 pub(crate) _bs: *mut c_void,
205}
206
207unsafe impl Encode for NSHashEnumerator {
208 const ENCODING: Encoding = Encoding::Struct(
209 "?",
210 &[
211 <NSUInteger>::ENCODING,
212 <NSUInteger>::ENCODING,
213 <*mut c_void>::ENCODING,
214 ],
215 );
216}
217
218unsafe impl RefEncode for NSHashEnumerator {
219 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
220}
221
222extern "C-unwind" {
223 pub fn NSFreeHashTable(table: &NSHashTable);
224}
225
226extern "C-unwind" {
227 pub fn NSResetHashTable(table: &NSHashTable);
228}
229
230#[inline]
231pub unsafe extern "C-unwind" fn NSCompareHashTables(
232 table1: &NSHashTable,
233 table2: &NSHashTable,
234) -> bool {
235 extern "C-unwind" {
236 fn NSCompareHashTables(table1: &NSHashTable, table2: &NSHashTable) -> Bool;
237 }
238 unsafe { NSCompareHashTables(table1, table2) }.as_bool()
239}
240
241#[cfg(feature = "NSZone")]
242#[inline]
243pub unsafe extern "C-unwind" fn NSCopyHashTableWithZone(
244 table: &NSHashTable,
245 zone: *mut NSZone,
246) -> Retained<NSHashTable> {
247 extern "C-unwind" {
248 fn NSCopyHashTableWithZone(table: &NSHashTable, zone: *mut NSZone) -> *mut NSHashTable;
249 }
250 let ret = unsafe { NSCopyHashTableWithZone(table, zone) };
251 unsafe { Retained::from_raw(ret) }
252 .expect("function was marked as returning non-null, but actually returned NULL")
253}
254
255#[inline]
256pub unsafe extern "C-unwind" fn NSHashGet(
257 table: &NSHashTable,
258 pointer: *const c_void,
259) -> NonNull<c_void> {
260 extern "C-unwind" {
261 fn NSHashGet(table: &NSHashTable, pointer: *const c_void) -> Option<NonNull<c_void>>;
262 }
263 let ret = unsafe { NSHashGet(table, pointer) };
264 ret.expect("function was marked as returning non-null, but actually returned NULL")
265}
266
267extern "C-unwind" {
268 pub fn NSHashInsert(table: &NSHashTable, pointer: *const c_void);
269}
270
271extern "C-unwind" {
272 pub fn NSHashInsertKnownAbsent(table: &NSHashTable, pointer: *const c_void);
273}
274
275extern "C-unwind" {
276 pub fn NSHashInsertIfAbsent(table: &NSHashTable, pointer: *const c_void) -> *mut c_void;
277}
278
279extern "C-unwind" {
280 pub fn NSHashRemove(table: &NSHashTable, pointer: *const c_void);
281}
282
283extern "C-unwind" {
284 pub fn NSEnumerateHashTable(table: &NSHashTable) -> NSHashEnumerator;
285}
286
287extern "C-unwind" {
288 pub fn NSNextHashEnumeratorItem(enumerator: NonNull<NSHashEnumerator>) -> *mut c_void;
289}
290
291extern "C-unwind" {
292 pub fn NSEndHashTableEnumeration(enumerator: NonNull<NSHashEnumerator>);
293}
294
295extern "C-unwind" {
296 pub fn NSCountHashTable(table: &NSHashTable) -> NSUInteger;
297}
298
299#[cfg(feature = "NSString")]
300impl NSString {
301 #[doc(alias = "NSStringFromHashTable")]
302 #[cfg(feature = "NSString")]
303 #[inline]
304 pub unsafe fn from_hash_table(table: &NSHashTable) -> Retained<NSString> {
305 extern "C-unwind" {
306 fn NSStringFromHashTable(table: &NSHashTable) -> *mut NSString;
307 }
308 let ret = unsafe { NSStringFromHashTable(table) };
309 unsafe { Retained::retain_autoreleased(ret) }
310 .expect("function was marked as returning non-null, but actually returned NULL")
311 }
312}
313
314#[cfg(feature = "NSArray")]
315#[inline]
316pub unsafe extern "C-unwind" fn NSAllHashTableObjects(table: &NSHashTable) -> Retained<NSArray> {
317 extern "C-unwind" {
318 fn NSAllHashTableObjects(table: &NSHashTable) -> *mut NSArray;
319 }
320 let ret = unsafe { NSAllHashTableObjects(table) };
321 unsafe { Retained::retain_autoreleased(ret) }
322 .expect("function was marked as returning non-null, but actually returned NULL")
323}
324
325#[cfg(feature = "NSString")]
329#[repr(C)]
330#[derive(Clone, Copy, Debug, PartialEq)]
331pub struct NSHashTableCallBacks {
332 pub hash:
333 Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> NSUInteger>,
334 pub isEqual: Option<
335 unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>, NonNull<c_void>) -> Bool,
336 >,
337 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>,
338 pub release: Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>,
339 pub describe:
340 Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> *mut NSString>,
341}
342
343#[cfg(feature = "NSString")]
344unsafe impl Encode for NSHashTableCallBacks {
345 const ENCODING: Encoding = Encoding::Struct(
346 "?",
347 &[
348 <Option<
349 unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> NSUInteger,
350 >>::ENCODING,
351 <Option<
352 unsafe extern "C-unwind" fn(
353 NonNull<NSHashTable>,
354 NonNull<c_void>,
355 NonNull<c_void>,
356 ) -> Bool,
357 >>::ENCODING,
358 <Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>>::ENCODING,
359 <Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>>::ENCODING,
360 <Option<
361 unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> *mut NSString,
362 >>::ENCODING,
363 ],
364 );
365}
366
367#[cfg(feature = "NSString")]
368unsafe impl RefEncode for NSHashTableCallBacks {
369 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
370}
371
372#[cfg(all(feature = "NSString", feature = "NSZone"))]
373#[inline]
374pub unsafe extern "C-unwind" fn NSCreateHashTableWithZone(
375 call_backs: NSHashTableCallBacks,
376 capacity: NSUInteger,
377 zone: *mut NSZone,
378) -> Retained<NSHashTable> {
379 extern "C-unwind" {
380 fn NSCreateHashTableWithZone(
381 call_backs: NSHashTableCallBacks,
382 capacity: NSUInteger,
383 zone: *mut NSZone,
384 ) -> *mut NSHashTable;
385 }
386 let ret = unsafe { NSCreateHashTableWithZone(call_backs, capacity, zone) };
387 unsafe { Retained::from_raw(ret) }
388 .expect("function was marked as returning non-null, but actually returned NULL")
389}
390
391#[cfg(feature = "NSString")]
392#[inline]
393pub unsafe extern "C-unwind" fn NSCreateHashTable(
394 call_backs: NSHashTableCallBacks,
395 capacity: NSUInteger,
396) -> Retained<NSHashTable> {
397 extern "C-unwind" {
398 fn NSCreateHashTable(
399 call_backs: NSHashTableCallBacks,
400 capacity: NSUInteger,
401 ) -> *mut NSHashTable;
402 }
403 let ret = unsafe { NSCreateHashTable(call_backs, capacity) };
404 unsafe { Retained::from_raw(ret) }
405 .expect("function was marked as returning non-null, but actually returned NULL")
406}
407
408extern "C" {
409 #[cfg(feature = "NSString")]
411 pub static NSIntegerHashCallBacks: NSHashTableCallBacks;
412}
413
414extern "C" {
415 #[cfg(feature = "NSString")]
417 pub static NSNonOwnedPointerHashCallBacks: NSHashTableCallBacks;
418}
419
420extern "C" {
421 #[cfg(feature = "NSString")]
423 pub static NSNonRetainedObjectHashCallBacks: NSHashTableCallBacks;
424}
425
426extern "C" {
427 #[cfg(feature = "NSString")]
429 pub static NSObjectHashCallBacks: NSHashTableCallBacks;
430}
431
432extern "C" {
433 #[cfg(feature = "NSString")]
435 pub static NSOwnedObjectIdentityHashCallBacks: NSHashTableCallBacks;
436}
437
438extern "C" {
439 #[cfg(feature = "NSString")]
441 pub static NSOwnedPointerHashCallBacks: NSHashTableCallBacks;
442}
443
444extern "C" {
445 #[cfg(feature = "NSString")]
447 pub static NSPointerToStructHashCallBacks: NSHashTableCallBacks;
448}
449
450extern "C" {
451 #[cfg(feature = "NSString")]
453 pub static NSIntHashCallBacks: NSHashTableCallBacks;
454}
455
456#[cfg(feature = "NSString")]
457#[deprecated = "renamed to `NSString::from_hash_table`"]
458#[inline]
459pub unsafe extern "C-unwind" fn NSStringFromHashTable(table: &NSHashTable) -> Retained<NSString> {
460 extern "C-unwind" {
461 fn NSStringFromHashTable(table: &NSHashTable) -> *mut NSString;
462 }
463 let ret = unsafe { NSStringFromHashTable(table) };
464 unsafe { Retained::retain_autoreleased(ret) }
465 .expect("function was marked as returning non-null, but actually returned NULL")
466}