|
1 /* Copyright (c) 2009 The Khronos Group Inc. |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and/or associated documentation files (the |
|
5 * "Materials"), to deal in the Materials without restriction, including |
|
6 * without limitation the rights to use, copy, modify, merge, publish, |
|
7 * distribute, sublicense, and/or sell copies of the Materials, and to |
|
8 * permit persons to whom the Materials are furnished to do so, subject to |
|
9 * the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 */ |
|
22 |
|
23 #ifndef OWFLLIST_H_ |
|
24 #define OWFLLIST_H_ |
|
25 |
|
26 #include "owfpool.h" |
|
27 #include "owftypes.h" |
|
28 |
|
29 |
|
30 #ifdef __cplusplus |
|
31 extern "C" |
|
32 { |
|
33 #endif |
|
34 |
|
35 /*! |
|
36 * Allocates new node from the node pool |
|
37 * |
|
38 * \param pool Node pool |
|
39 * \param data Data to store in the node |
|
40 * |
|
41 * \return New node containing data or NULL |
|
42 */ |
|
43 OWF_API_CALL OWF_NODE* |
|
44 OWF_Node_Create(OWF_POOL* pool, void* data); |
|
45 |
|
46 /*! |
|
47 * Returns node to pool it was allocated from. |
|
48 * |
|
49 * \param node Node to "destroy" |
|
50 */ |
|
51 OWF_API_CALL void |
|
52 OWF_Node_Destroy(OWF_NODE* node); |
|
53 |
|
54 /*! |
|
55 * Returns list's tail node. |
|
56 * |
|
57 * \param root List root |
|
58 * |
|
59 * \return List's tail (last) node |
|
60 */ |
|
61 OWF_API_CALL OWF_NODE* |
|
62 OWF_List_Tail(OWF_NODE* root); |
|
63 |
|
64 /*! |
|
65 * Append node to list. |
|
66 * |
|
67 * \param root List root |
|
68 * |
|
69 * \return New list root node |
|
70 */ |
|
71 OWF_API_CALL OWF_NODE* |
|
72 OWF_List_Append(OWF_NODE* root, OWF_NODE* node); |
|
73 |
|
74 /*! |
|
75 * Insert node to list front. I.e. current root becomes |
|
76 * 2nd in the list and so on. |
|
77 * |
|
78 * \param root List root |
|
79 * \param node Node to insert |
|
80 * |
|
81 * \return New list root (inserted node) |
|
82 */ |
|
83 OWF_API_CALL OWF_NODE* |
|
84 OWF_List_Insert(OWF_NODE* root, OWF_NODE* node); |
|
85 |
|
86 /*! |
|
87 * Inserts node into list, immediately after node "pred". |
|
88 * |
|
89 * \param pred Node after which the newcomer should be placed. |
|
90 * \param node Node to add. |
|
91 */ |
|
92 OWF_API_CALL void |
|
93 OWF_List_InsertAfter(OWF_NODE* pred, OWF_NODE* node); |
|
94 |
|
95 /*! |
|
96 * Searches the list for data ptr. Returns the node |
|
97 * that contains pointer to data, or NULL if no such node |
|
98 * can be found from the list. |
|
99 * |
|
100 * \param root List root |
|
101 * \param data Data pointer |
|
102 * |
|
103 * \return Node containing the data ptr or NULL. |
|
104 */ |
|
105 OWF_API_CALL OWF_NODE* |
|
106 OWF_List_Contains(OWF_NODE* root, void* data); |
|
107 |
|
108 /*! |
|
109 * Remove node from list. Obs! The node isn't freed, |
|
110 * but only removed from the list. It's up to caller |
|
111 * to take care of destroying the node i.e. returning |
|
112 * it to pool or releasing the memory otherwise allocated |
|
113 * to it. |
|
114 * |
|
115 * \param root List root |
|
116 * \param node Node to remove from list |
|
117 * |
|
118 * \return New list root after removal |
|
119 */ |
|
120 OWF_API_CALL OWF_NODE* |
|
121 OWF_List_Remove(OWF_NODE* root, OWF_NODE* node); |
|
122 |
|
123 /*! |
|
124 * Remove all nodes from the list. Equals to |
|
125 * while (list) list = OWF_List_Remove(list, list); |
|
126 * |
|
127 * \param root List root |
|
128 * |
|
129 * \return NULL. |
|
130 */ |
|
131 OWF_API_CALL OWF_NODE* |
|
132 OWF_List_Clear(OWF_NODE* root); |
|
133 |
|
134 /*! |
|
135 * Calls given callback function for each node in the list |
|
136 * as long as the callback function returns a non-zero value. |
|
137 * Useful for performing some action on list until some condition |
|
138 * is met. |
|
139 * |
|
140 * \param root List root |
|
141 * \param func Callback function |
|
142 * \param data Data to be passed to callback function |
|
143 */ |
|
144 OWF_API_CALL void |
|
145 OWF_List_ForEach(OWF_NODE* root, NODEITERFUNC func, void* data); |
|
146 |
|
147 /* |
|
148 * Returns first node for which given comparison function |
|
149 * returns a non-zero value. Useful for searching the list |
|
150 * for something of intrest. To find all matching nodes |
|
151 * from the list, use the following pattern: |
|
152 * |
|
153 * node = OWF_List_Find(list, compareFunc, dada); |
|
154 * while (node) { |
|
155 * processFoundNode(node); |
|
156 * node = OWF_List_Find(node->next, compareFunc, dada); |
|
157 * } |
|
158 * |
|
159 * \param root List root |
|
160 * \param func Node equality comparison function |
|
161 * \param data Data to pass to node comparison function. |
|
162 * |
|
163 * \return Node that matches in comparison. |
|
164 */ |
|
165 OWF_API_CALL OWF_NODE* |
|
166 OWF_List_Find(OWF_NODE* root, NODECMPFUNC func, void* data); |
|
167 |
|
168 |
|
169 #ifdef __cplusplus |
|
170 } |
|
171 #endif |
|
172 |
|
173 |
|
174 #endif |