Repository navigation
Expand file tree
/
Copy pathint.zig
More file actions
53 lines (44 loc) · 1.55 KB
/
Copy pathint.zig
File metadata and controls
53 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const std = @import("std");
const gi = @import("gi");
const core = gi.core;
const Object = gi.GObject.Object;
const PartialEq = @import("eq.zig").PartialEq;
const PartialOrd = @import("ord.zig").PartialOrd;
pub const TypedIntClass = extern struct {
parent_class: Object.Class,
};
pub const TypeIntPrivate = struct {
value: i32,
};
pub const TypedInt = extern struct {
parent: Parent,
private: *Private,
pub const Parent = Object;
pub const Private = TypeIntPrivate;
pub const Class = TypedIntClass;
pub const Interfaces = [_]type{ PartialEq, PartialOrd };
const Ext = core.Extend(@This());
pub const into = Ext.into;
pub const tryInto = Ext.tryInto;
pub const Override = struct {
pub fn eq_fn(self: *PartialEq, rhs: *PartialEq) bool {
const lhs_value = self.tryInto(TypedInt).?.private.value;
const rhs_value = rhs.tryInto(TypedInt).?.private.value;
return lhs_value == rhs_value;
}
pub fn cmp_fn(self: *PartialOrd, rhs: *PartialOrd) PartialOrd.Order {
const lhs_value = self.tryInto(TypedInt).?.private.value;
const rhs_value = rhs.tryInto(TypedInt).?.private.value;
if (lhs_value == rhs_value) return .eq;
return if (lhs_value < rhs_value) .lt else .gt;
}
};
pub fn new(value: i32) *TypedInt {
var object = core.newObject(TypedInt);
object.private.value = value;
return object;
}
pub fn gType() core.Type {
return core.registerType(TypedInt, "TypedInt", .{});
}
};