MOS Source Code
Loading...
Searching...
No Matches
tree.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
6#include <mos/moslib_global.h>
7#include <mos/types.h>
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((node), type, tree_node.list_node)
34#define tree_child_node(node) (&((node)->tree_node.list_node))
35
36#define tree_foreach_child(t, v, h) \
37 for (__typeof(tree_child_entry(tree_child_node(h), t)) v = tree_child_entry(tree_children_list(h)->next, t); tree_child_node(v) != tree_children_list(h); \
38 v = tree_child_entry(tree_child_node(v)->next, t))
39
41MOSAPI 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.h:23
#define MOSAPI
Definition mos_global.h:102
const char * name
Definition slab.c:31
as_linked_list
Definition tree.h:13
list_head children
Definition tree.h:15
tree_node_t * parent
Definition tree.h:14
struct tree_node tree_node_t
Definition tree.h:9
MOSAPI void tree_node_init(tree_node_t *node)
Definition tree.c:8
#define tree_node(element)
Definition tree.h:29
MOSAPI void tree_add_child(tree_node_t *parent, tree_node_t *child)
Definition tree.c:14