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