zoop
zoop.Fn
pub fn Fn(comptime T: type) typeFunction: Calculate all Method of T, refer to Fn principle
parameter:
T: Class
Returns: A tuple containing all the methods returned by calling the Fn function of T and all its superclasses.
example:
const SomeClass = struct {
pub const extends = .{BaseClass}
pub usingnamespace zoop.Fn(@This());
}zoop.Api
pub fn Api(comptime I: type) typeFunction: Calculate all ApiMethod of I, refer to Api principle
parameter:
I: Interface
Returns: A tuple containing all ApiMethods returned by calling the Api functions of I and all its parent interfaces.
example:
pub const ISome = struct {
pub const extends = .{IBase}
pub usingnamespace zoop.Api(@This());
}zoop.DefVtable
pub fn DefVtable(comptime I: type, comptime APIs: type) typeFunction: Calculate the Vtable of I
parameter:
I: InterfaceAPIs: a zig struct containing pointers to the function interfaces defined byI
Returns: a zig struct containing pointer data of the function interface defined by I and its parent interface
example:
pub const ISome = struct {
pub const extends = .{IBase}
pub const Vtable = zoop.DefVtable(@This(), struct {
someFunc1: *fn const(*anyopaque) void,
someFunc2: *fn const(*anyopaque) void,
});
}zoop.Mixin
pub fn Mixin(comptime T: type) typeFunction: Calculate the Mixin data type of T, refer to Mixin design
parameter:
T: Class
Returns: the Mixin data type of T
example:
const SomeClass = struct {
mixin: zoop.Mixin(@This()),
}zoop.Method
pub const Method = tuple.Init;Function: Same as tuple.Init
example:
pub const Some = struct {
pub fn Fn(comptime T: type) type {
return zoop.Method(.{
struct {
pub fn someFunc(this: *T) void { _ = this; }
},
});
}
}zoop.Interfaces
pub fn Interfaces(comptime T: type) typeFunction: Get all interfaces implemented/inherited by T (excluding zoop.IObject)
parameter:
Returns: A tuple containing all interfaces implemented/inherited by T (excluding zoop.IObject)
zoop.SuperClasses
pub fn SuperClasses(comptime T: type) typeFunction: Get all direct or indirect parent classes of T
parameter:
T:Class
Returns: a tuple containing all direct or indirect parent classes of T
zoop.DirectSuperClasses
pub fn DirectSuperClasses(comptime T: type) typeFunction: Get a tuple containing all direct parent classes of T
parameter:
T:Class
Returns: a tuple containing all direct superclasses of T
zoop.SuperRoute
pub fn SuperRoute(comptime T: type, comptime Target: type) typeFunction: Calculate all classes from T to Target in the inheritance tree
parameter:
T: Starting point ClassTarget: endpoint [Class] (principle#term)
Returns: a tuple containing all the classes from T to Target in the inheritance tree (the result contains Target but not T)
zoop.typeId
pub fn typeId(any: anytype) u32Function:Get the typeid of any
parameter:
Returns: typeid for any
zoop.typeInfo
pub fn typeInfo(any: anytype) *const TypeInfoFunction: Get the TypeInfo of any
parameter:
Returns: TypeInfo for any
example:
const t = std.testing;
var obj = try Some.new(t.allocator);
defer obj.destroy();
var iface = o.as(zoop.IObject).?;
try t.expect(zoop.typeInfo(obj) == zoop.typeInfo(iface));
try t.expect(zoop.typeInfo(obj) == zoop.typeInfo(Some));zoop.metaInfo
pub fn metaInfo(any: anytype) *const MetaInfoFunction: Get the MetaInfo of any
parameter:
Returns: MetaInfo of any
example:
const t = std.testing;
var obj = try Some.new(t.allocator);
defer obj.destroy();
var iface = o.as(zoop.IObject).?;
try t.expect(zoop.metaInfo(obj) == zoop.metaInfo(iface));zoop.isRootPtr
pub inline fn isRootPtr(ptr: anytype) bool {Function: Determine whether ptr is equal to rootptr
parameter:
ptr: Class instance pointer
Returns: ptr is equal to rootptr returns true otherwise false
example:
const t = std.testing;
var sub = try SubClass.new(t.allocator);
defer sub.destroy();
var base = sub.cast(BaseClass);
try t.expect(zoop.isRootPtr(sub) == true);
try t.expect(zoop.isRootPtr(base) == false);zoop.isInterface
pub inline fn isInterface(comptime T: type) boolFunction: Determine whether T is an Interface
parameter:
T: any zig type
Returns: T is Interface returns true otherwise false
zoop.isClass
pub inline fn isClass(comptime T: type) boolFunction: Determine whether T is Class
parameter:
T: any zig type
Returns: T is Class returns true otherwise false
zoop.mixinName
pub fn mixinName(comptime T: type) []const u8Function: Calculate the name of T in MixinData
parameter:
T: Class
Returns: The name of T in MixinData
example:
const t = std.testing;
try t.expectEqualStrings(zoop.mixinName(mymod.SomeClass), "mymod_SomeClass");zoop.mixinName0
pub fn mixinName0(comptime T: type) [:0]const u8Function: Same as mixinName, except that it returns a string ending with 0.
zoop.setHook
pub const HookFunc = *const fn (obj: IObject) void;
pub fn setHook(new_hook: ?HookFunc, destroy_hook: ?HookFunc) voidFunction: Set the hook function for monitoring object creation and destruction
parameter:
new_hook: object creation hook function, passing innullwill clear the previously set hook functiondestroy_hook: object destruction hook function, passing innullwill clear the previously set hook function
