работающее сохранение
This commit is contained in:
@@ -23,6 +23,23 @@ pub fn deinit(self: *Document, allocator: std.mem.Allocator) void {
|
||||
self.objects.deinit(allocator);
|
||||
}
|
||||
|
||||
pub fn clone(self: *const Document, allocator: std.mem.Allocator) !Document {
|
||||
var objects_list = std.ArrayList(Object).empty;
|
||||
errdefer {
|
||||
for (objects_list.items) |*obj| obj.deinit(allocator);
|
||||
objects_list.deinit(allocator);
|
||||
}
|
||||
var next_id = self.next_object_id;
|
||||
for (self.objects.items) |obj| {
|
||||
try objects_list.append(allocator, try obj.clone(allocator, &next_id));
|
||||
}
|
||||
return .{
|
||||
.size = self.size,
|
||||
.objects = objects_list,
|
||||
.next_object_id = next_id,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn addObject(self: *Document, allocator: std.mem.Allocator, template: Object) !void {
|
||||
const obj = try template.clone(allocator, &self.next_object_id);
|
||||
try self.objects.append(allocator, obj);
|
||||
|
||||
Reference in New Issue
Block a user