Переход на object_id
This commit is contained in:
@@ -29,6 +29,7 @@ pub const defaultCommonProperties: [default_common_data.len]Property = blk: {
|
||||
break :blk result;
|
||||
};
|
||||
|
||||
id: u64,
|
||||
shape: ShapeKind,
|
||||
properties: std.ArrayList(Property),
|
||||
children: std.ArrayList(Object),
|
||||
@@ -51,12 +52,12 @@ pub fn setProperty(self: *Object, allocator: std.mem.Allocator, prop: Property)
|
||||
return error.PropertyNotFound;
|
||||
}
|
||||
|
||||
pub fn addChild(self: *Object, allocator: std.mem.Allocator, template: Object) !void {
|
||||
const obj = try template.clone(allocator);
|
||||
pub fn addChild(self: *Object, allocator: std.mem.Allocator, template: Object, next_id: *u64) !void {
|
||||
const obj = try template.clone(allocator, next_id);
|
||||
try self.children.append(allocator, obj);
|
||||
}
|
||||
|
||||
pub fn clone(self: Object, allocator: std.mem.Allocator) !Object {
|
||||
pub fn clone(self: Object, allocator: std.mem.Allocator, next_id: *u64) !Object {
|
||||
var properties_list = std.ArrayList(Property).empty;
|
||||
errdefer properties_list.deinit(allocator);
|
||||
for (self.properties.items) |prop| {
|
||||
@@ -66,16 +67,23 @@ pub fn clone(self: Object, allocator: std.mem.Allocator) !Object {
|
||||
var children_list = std.ArrayList(Object).empty;
|
||||
errdefer children_list.deinit(allocator);
|
||||
for (self.children.items) |child| {
|
||||
try children_list.append(allocator, try child.clone(allocator));
|
||||
try children_list.append(allocator, try child.clone(allocator, next_id));
|
||||
}
|
||||
|
||||
return .{
|
||||
.id = allocId(next_id),
|
||||
.shape = self.shape,
|
||||
.properties = properties_list,
|
||||
.children = children_list,
|
||||
};
|
||||
}
|
||||
|
||||
fn allocId(next_id: *u64) u64 {
|
||||
const id = next_id.*;
|
||||
next_id.* += 1;
|
||||
return id;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Object, allocator: std.mem.Allocator) void {
|
||||
for (self.children.items) |*child| child.deinit(allocator);
|
||||
self.children.deinit(allocator);
|
||||
|
||||
Reference in New Issue
Block a user