2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #define TREE_NODE_FOREACH(parent, node) \
24 for (node = parent->first; node != NULL; node = node->next)
27 * data - data bind to node
28 * parent - parent node
30 * prev - previous sibling
34 typedef struct _tree_node {
36 struct _tree_node *parent;
39 struct _tree_node *next;
40 struct _tree_node *prev;
42 struct _tree_node *first;
43 struct _tree_node *last;
48 * @brief signature of callback function for tree_in_depth_browse() function
50 typedef bool(*tree_browse_cb_t)(Tree_node_t*, Tree_node_t*, void*);
54 * @brief Creates new tree node
55 * @details All node fields are initialized with \0
57 bool tree_node_new(Tree_node_t **node);
62 bool tree_node_detatch(Tree_node_t *node);
65 * @brief Append child node to parent node
67 bool tree_node_append(Tree_node_t *parent, Tree_node_t *node);
70 * @brief Append node to tree after relative node
72 bool tree_node_append_relative(Tree_node_t *node, Tree_node_t *relative);
75 * @brief Prepend child node to parent node
77 bool tree_node_prepend(Tree_node_t *parent, Tree_node_t *node);
80 * @brief Prepend node to tree before relative node
82 bool tree_node_prepend_relative(Tree_node_t *node, Tree_node_t *relative);
85 * @brief Browse the tree in-depth
87 bool tree_in_depth_browse(Tree_node_t *node, tree_browse_cb_t func_cb,
91 * Updates a node with new values
93 void tree_node_update(Tree_node_t *node);
96 * @brief frees memory of a single node in a safe manner. Returns count and
97 * pointers to children of the node.
98 * Updates nodes parent and siblings. Nodes children become
99 * detached from the tree.
100 * @param node[IN] - node to free
101 * @param first_child - nodes first child
102 * @param last_child - nodes last child
103 * @param child_count - nodes children count
105 void tree_node_free(Tree_node_t *node, Tree_node_t **first_child,
106 Tree_node_t **last_child, int *child_count);