Common structures: create and deinit functions.
parent
00eac1ff5f
commit
78080c43a0
|
@ -18,6 +18,15 @@ pub const Node = struct {
|
|||
type_name: [] const u8,
|
||||
properties: PropertyHashMap,
|
||||
children: NodeList,
|
||||
|
||||
pub fn deinit(self: *Node) void {
|
||||
self.properties.deinit();
|
||||
for (self.children.items) |k, v| {
|
||||
v.deinit();
|
||||
}
|
||||
self.children.deinit();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const PropertyValueTags = enum {
|
||||
|
@ -38,6 +47,24 @@ pub const PropertyValue = union(PropertyValueTags) {
|
|||
pub const Root = struct {
|
||||
definitions: Definitions,
|
||||
children: NodeList,
|
||||
|
||||
gpa: *Allocator,
|
||||
|
||||
pub fn create(allocator: *Allocator) !Root {
|
||||
return Root{
|
||||
.definitions = Definitions.init(allocator),
|
||||
.children = NodeList.init(allocator),
|
||||
.gpa = allocator,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Root) void {
|
||||
self.definitions.deinit();
|
||||
// for (self.children.items) |k, v| {
|
||||
// k.deinit();
|
||||
// }
|
||||
self.children.deinit();
|
||||
}
|
||||
};
|
||||
|
||||
test "simple test about structures" {
|
||||
|
@ -57,3 +84,22 @@ test "simple test about structures" {
|
|||
}
|
||||
|
||||
|
||||
test "init a Root structure" {
|
||||
const allocator = std.heap.page_allocator;
|
||||
var root = try Root.create(allocator);
|
||||
defer root.deinit();
|
||||
|
||||
std.debug.print("\n", .{});
|
||||
|
||||
std.debug.print("root.definitions:\n", .{});
|
||||
var it = root.definitions.iterator();
|
||||
while(it.next()) |kv| {
|
||||
std.debug.print("{} => {}:\n", .{kv.key, root.definitions.get(kv.key)});
|
||||
}
|
||||
|
||||
std.debug.print("root.children:\n", .{});
|
||||
for(root.children.items) |k, v| {
|
||||
std.debug.print("{} => {}:\n", .{k, v});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue