MOS Source Code
Loading...
Searching...
No Matches
tree.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
7#include <mos/types.hpp>
8
9typedef struct tree_node tree_node_t;
10
17
21#define as_tree tree_node_t tree_node
22
23typedef const struct
24{
25 void (*get_node_name)(const tree_node_t *node, char **name, size_t *name_len);
26} tree_op_t;
27
28#define tree_entry(node, type) container_of((node), type, tree_node)
29#define tree_node(element) (&((element)->tree_node))
30#define tree_parent(node, type) (tree_entry(tree_node(node)->parent, type))
31
32#define tree_children_list(node) (&((node)->tree_node.children))
33#define tree_child_entry(node, type) container_of(container_of((node), tree_node_t, list_node), type, tree_node)
34#define tree_child_node(node) (&((node)->tree_node.list_node))
35
36#define tree_foreach_child(t, v, h) \
37 for (auto v = tree_child_entry(tree_children_list(h)->next, t); tree_child_node(v) != tree_children_list(h); v = tree_child_entry(tree_child_node(v)->next, t))
38
40MOSAPI void tree_add_child(tree_node_t *parent, tree_node_t *child);
MOSAPI void(1, 2) fatal_abort(const char *fmt
list_node_t list_head
A linked list head.
Definition list.hpp:23
#define MOSAPI
Definition mos_global.h:112
const char * name
Definition slab.cpp:35
list_head children
Definition tree.hpp:15
tree_node_t * parent
Definition tree.hpp:14
void(* get_node_name)(const tree_node_t *node, char **name, size_t *name_len)
Definition tree.hpp:25
MOSAPI void tree_node_init(tree_node_t *node)
Definition tree.cpp:8
#define tree_node(element)
Definition tree.hpp:29
MOSAPI void tree_add_child(tree_node_t *parent, tree_node_t *child)
Definition tree.cpp:14