pkg/macos: add missing functions to macos/foundation

This commit is contained in:
Mitchell Hashimoto
2024-04-04 11:25:34 -07:00
parent 5440fda3fb
commit 290496d7fe
2 changed files with 30 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const base = @import("base.zig");
const c = @import("c.zig");
const cftype = @import("type.zig");
const ComparisonResult = base.ComparisonResult;
const Range = base.Range;
@@ -42,6 +43,14 @@ pub const Array = opaque {
};
pub const MutableArray = opaque {
pub fn create() Allocator.Error!*MutableArray {
return CFArrayCreateMutable(
null,
0,
&c.kCFTypeArrayCallBacks,
) orelse error.OutOfMemory;
}
pub fn createCopy(array: *Array) Allocator.Error!*MutableArray {
return CFArrayCreateMutableCopy(
null,
@@ -54,6 +63,14 @@ pub const MutableArray = opaque {
cftype.CFRelease(self);
}
pub fn appendValue(
self: *MutableArray,
comptime Elem: type,
value: *const Elem,
) void {
CFArrayAppendValue(self, @constCast(@ptrCast(value)));
}
pub fn sortValues(
self: *MutableArray,
comptime Elem: type,
@@ -73,12 +90,20 @@ pub const MutableArray = opaque {
);
}
extern "c" fn CFArrayCreateMutable(
allocator: ?*anyopaque,
capacity: usize,
callbacks: ?*const anyopaque,
) ?*MutableArray;
extern "c" fn CFArrayCreateMutableCopy(
allocator: ?*anyopaque,
capacity: usize,
array: *Array,
) ?*MutableArray;
extern "c" fn CFArrayAppendValue(
*MutableArray,
*anyopaque,
) void;
extern "c" fn CFArraySortValues(
array: *MutableArray,
range: Range,