NSEnumerator.odin 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package objc_Foundation
  2. import "core:c"
  3. import "base:intrinsics"
  4. FastEnumerationState :: struct #packed {
  5. state: c.ulong,
  6. itemsPtr: [^]^Object,
  7. mutationsPtr: [^]c.ulong,
  8. extra: [5]c.ulong,
  9. }
  10. @(objc_class="NSFastEnumeration")
  11. FastEnumeration :: struct {using _: Object}
  12. @(objc_class="NSEnumerator")
  13. Enumerator :: struct($T: typeid) where intrinsics.type_is_pointer(T), intrinsics.type_is_subtype_of(T, ^Object) {
  14. using _: FastEnumeration,
  15. }
  16. @(objc_type=FastEnumeration, objc_name="alloc", objc_is_class_method=true)
  17. FastEnumeration_alloc :: proc "c" () -> ^FastEnumeration {
  18. return msgSend(^FastEnumeration, FastEnumeration, "alloc")
  19. }
  20. @(objc_type=FastEnumeration, objc_name="init")
  21. FastEnumeration_init :: proc "c" (self: ^FastEnumeration) -> ^FastEnumeration {
  22. return msgSend(^FastEnumeration, self, "init")
  23. }
  24. @(objc_type=FastEnumeration, objc_name="countByEnumerating")
  25. FastEnumeration_countByEnumerating :: proc "c" (self: ^FastEnumeration, state: ^FastEnumerationState, buffer: [^]^Object, len: UInteger) -> UInteger {
  26. return msgSend(UInteger, self, "countByEnumeratingWithState:objects:count:", state, buffer, len)
  27. }
  28. Enumerator_nextObject :: proc "c" (self: ^$E/Enumerator($T)) -> T {
  29. return msgSend(T, self, "nextObject")
  30. }
  31. Enumerator_allObjects :: proc "c" (self: ^$E/Enumerator($T)) -> (all: ^Array) {
  32. return msgSend(type_of(all), self, "allObjects")
  33. }
  34. Enumerator_iterator :: proc "contextless" (self: ^$E/Enumerator($T)) -> (obj: T, ok: bool) {
  35. obj = msgSend(T, self, "nextObject")
  36. ok = obj != nil
  37. return
  38. }