The source code moved from the SPIN with license changed to Flora 1.1
[apps/native/home/homescreen-efl.git] / inc / tree.h
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #ifndef _TREE_H_
18 #define _TREE_H_
19
20 #include <stdbool.h>
21 #include "app_item.h"
22
23 #define TREE_NODE_FOREACH(parent, node) \
24 for (node = parent->first; node != NULL; node = node->next)
25
26 /*
27  * data         - data bind to node
28  * parent       - parent node
29  * next         - next sibling
30  * prev         - previous sibling
31  * first        - first child
32  * last         - last child
33  */
34 typedef struct _tree_node {
35         app_item_t *data;
36         struct _tree_node *parent;
37
38         unsigned int count;
39         struct _tree_node *next;
40         struct _tree_node *prev;
41
42         struct _tree_node *first;
43         struct _tree_node *last;
44 } Tree_node_t;
45
46
47 /*
48  * @brief signature of callback function for tree_in_depth_browse() function
49  */
50 typedef bool(*tree_browse_cb_t)(Tree_node_t*, Tree_node_t*, void*);
51
52
53 /*
54  * @brief Creates new tree node
55  * @details All node fields are initialized with \0
56  */
57 bool tree_node_new(Tree_node_t **node);
58
59 /*
60  * @brief Detatch node
61  */
62 bool tree_node_detatch(Tree_node_t *node);
63
64 /*
65  * @brief Append child node to parent node
66  */
67 bool tree_node_append(Tree_node_t *parent, Tree_node_t *node);
68
69 /*
70  * @brief Append node to tree after relative node
71  */
72 bool tree_node_append_relative(Tree_node_t *node, Tree_node_t *relative);
73
74 /*
75  * @brief Prepend child node to parent node
76  */
77 bool tree_node_prepend(Tree_node_t *parent, Tree_node_t *node);
78
79 /*
80  * @brief Prepend node to tree before relative node
81  */
82 bool tree_node_prepend_relative(Tree_node_t *node, Tree_node_t *relative);
83
84 /*
85  * @brief Browse the tree in-depth
86  */
87 bool tree_in_depth_browse(Tree_node_t *node, tree_browse_cb_t func_cb,
88         void *data);
89
90 /*
91  * Updates a node with new values
92  */
93 void tree_node_update(Tree_node_t *node);
94
95 /*
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
104  */
105 void tree_node_free(Tree_node_t *node, Tree_node_t **first_child,
106         Tree_node_t **last_child, int *child_count);
107
108 #endif