annotate libvisual/lv_list.c @ 23:0db4a1dc75c4 trunk

[svn] libvisual. P3 detection appears to be borked. I'll work on it later.
author nenolod
date Mon, 24 Oct 2005 23:13:56 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
1 /* Libvisual - The audio visualisation framework.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
2 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
3 * Copyright (C) 2004, 2005 Dennis Smit <ds@nerds-incorporated.org>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
4 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
5 * List implementation from RCL.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
6 * Copyright (C) 2002, 2003, 2004
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
7 * Dennis Smit <ds@nerds-incorporated.org>,
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
8 * Sepp Wijnands <mrrazz@nerds-incorporated.org>,
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
9 * Tom Wimmenhove <nohup@nerds-incorporated.org>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
10 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
11 * Authors: Dennis Smit <ds@nerds-incorporated.org>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
12 * Sepp Wijnands <mrrazz@nerds-incorporated.org>,
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
13 * Tom Wimmenhove <nohup@nerds-incorporated.org>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
14 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
15 * $Id:
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
16 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
17 * This program is free software; you can redistribute it and/or modify
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
18 * it under the terms of the GNU Lesser General Public License as
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
19 * published by the Free Software Foundation; either version 2.1
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
20 * of the License, or (at your option) any later version.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
21 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
22 * This program is distributed in the hope that it will be useful,
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
25 * GNU Lesser General Public License for more details.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
26 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
27 * You should have received a copy of the GNU Lesser General Public License
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
28 * along with this program; if not, write to the Free Software
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
30 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
31
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
32 #include <stdio.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
33 #include <stdlib.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
34 #include <unistd.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
35 #include <string.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
36 #include <fcntl.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
37
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
38 #include <lvconfig.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
39 #include "lv_list.h"
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
40 #include "lv_log.h"
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
41 #include "lv_mem.h"
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
42
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
43 static int list_dtor (VisObject *object);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
44
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
45 static int list_dtor (VisObject *object)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
46 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
47 VisList *list = VISUAL_LIST (object);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
48
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
49 visual_list_destroy_elements (list);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
50
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
51 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
52 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
53
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
54 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
55 * @defgroup VisList VisList
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
56 * @{
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
57 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
58
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
59 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
60 * Creates a new VisList structure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
61 * The VisList system is a double linked list implementation.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
62 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
63 * @return A newly allocated VisList.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
64 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
65 VisList *visual_list_new (VisListDestroyerFunc destroyer)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
66 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
67 VisList *list;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
68
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
69 list = visual_mem_new0 (VisList, 1);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
70
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
71 /* Do the VisObject initialization */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
72 visual_object_initialize (VISUAL_OBJECT (list), TRUE, list_dtor);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
73
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
74 list->destroyer = destroyer;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
75
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
76 return list;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
77 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
78
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
79 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
80 * Frees the VisList. This frees the VisList data structure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
81 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
82 * @param list Pointer to a VisList that needs to be freed.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
83 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
84 * @return VISUAL_OK on succes, -VISUAL_ERROR_LIST_NULL or error values returned by
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
85 * visual_mem_free () on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
86 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
87 int visual_list_free (VisList *list)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
88 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
89 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
90
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
91 return visual_mem_free (list);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
92 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
93
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
94 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
95 * Destroys the entries that are in a list, but not the list itself. It uses the element
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
96 * destroyer set at visual_list_new or visual_list_set_destroyer.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
97 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
98 * @param list Pointer to a VisList of which the elements need to be destroyed.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
99 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
100 * @return VISUAL_OK on succes, or -VISUAL_ERROR_LIST_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
101 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
102 int visual_list_destroy_elements (VisList *list)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
103 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
104 VisListEntry *le = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
105 void *elem;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
106
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
107 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
108
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
109 /* Walk through the given list, possibly calling the destroyer for it */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
110 if (list->destroyer == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
111 while ((elem = visual_list_next (list, &le)) != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
112 visual_list_delete (list, &le);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
113 } else {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
114 while ((elem = visual_list_next (list, &le)) != NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
115 list->destroyer (elem);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
116 visual_list_delete (list, &le);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
117 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
118 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
119
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
120 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
121 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
122
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
123 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
124 * Sets a VisListEntry destroyer function a VisList.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
125 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
126 * @param list Pointer to a VisList to which the VisListDestroyerFunc is set.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
127 * @param destroyer The VisListEntry destroyer function.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
128 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
129 * @return VISUAL_OK on succes, -VISUAL_ERROR_LIST_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
130 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
131 int visual_list_set_destroyer (VisList *list, VisListDestroyerFunc destroyer)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
132 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
133 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
134
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
135 list->destroyer = destroyer;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
136
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
137 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
138 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
139
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
140 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
141 * Go to the next entry in the list and return it's data element.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
142 * This function will load the next entry in le and return a pointer
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
143 * to the data element.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
144 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
145 * @see visual_list_prev
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
146 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
147 * @param list Pointer to the VisList we're traversing.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
148 * @param le Pointer to a VisListEntry to store the next entry within
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
149 * and also to use as a reference to determine at which entry we're
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
150 * currently. To begin traversing do: VisListEntry *le = NULL and pass
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
151 * it as &le in the argument.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
152 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
153 * @return The data element of the next entry, or NULL.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
154 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
155 void *visual_list_next (VisList *list, VisListEntry **le)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
156 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
157 visual_log_return_val_if_fail (list != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
158 visual_log_return_val_if_fail (le != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
159
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
160 if (*le == NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
161 *le = list->head;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
162 else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
163 *le = (*le)->next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
164
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
165 if (*le != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
166 return (*le)->data;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
167
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
168 return NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
169 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
170
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
171 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
172 * Go to the previous entry in the list and return it's data element.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
173 * This function will load the previous entry in le and return a pointer
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
174 * to the data element.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
175 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
176 * @see visual_list_next
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
177 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
178 * @param list Pointer to the VisList we're traversing.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
179 * @param le Pointer to a VisListEntry to store the previous entry within
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
180 * and also to use as a reference to determine at which entry we're
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
181 * currently. To begin traversing at the end of the list do:
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
182 * VisList *le = NULL and pass it as &le in the argument.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
183 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
184 * @return The data element of the previous entry, or NULL.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
185 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
186 void *visual_list_prev (VisList *list, VisListEntry **le)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
187 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
188 visual_log_return_val_if_fail (list != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
189 visual_log_return_val_if_fail (le != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
190
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
191 if (!*le)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
192 *le = list->tail;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
193 else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
194 *le = (*le)->prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
195
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
196 if (*le)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
197 return (*le)->data;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
198
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
199 return NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
200 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
201
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
202 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
203 * Get an data entry by index. This will give the pointer to an data
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
204 * element based on the index in the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
205 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
206 * @param list Pointer to the VisList of which we want an element.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
207 * @param index Index to determine which entry we want. The index starts at
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
208 * 1.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
209 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
210 * @return The data element of the requested entry, or NULL.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
211 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
212 void *visual_list_get (VisList *list, int index)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
213 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
214 VisListEntry *le = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
215 void *data = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
216 int i, lc;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
217
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
218 visual_log_return_val_if_fail (list != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
219 visual_log_return_val_if_fail (index >= 0, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
220
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
221 lc = visual_list_count (list);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
222
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
223 if (lc - 1 < index)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
224 return NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
225
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
226 for (i = 0; i <= index; i++) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
227 data = visual_list_next (list, &le);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
228
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
229 if (data == NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
230 return NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
231 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
232
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
233 return data;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
234 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
235
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
236 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
237 * Adds an entry at the beginning of the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
238 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
239 * @param list Pointer to the VisList to which an entry needs to be added
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
240 * at it's head.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
241 * @param data A pointer to the data that needs to be added to the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
242 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
243 * @return VISUAL_OK on succes, -VISUAL_ERROR_LIST_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
244 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
245 int visual_list_add_at_begin (VisList *list, void *data)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
246 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
247 VisListEntry *current, *next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
248
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
249 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
250
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
251 /* Allocate memory for new list entry */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
252 current = visual_mem_new0 (VisListEntry, 1);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
253
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
254 /* Assign data element */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
255 current->data = data;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
256
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
257 if (list->head == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
258 list->head = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
259 list->tail = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
260 } else {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
261 next = list->head;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
262
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
263 current->next = next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
264 list->head = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
265 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
266
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
267 /* Done */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
268 list->count++;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
269
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
270 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
271 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
272
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
273 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
274 * Adds an entry at the end of the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
275 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
276 * @param list Pointer to the VisList to which an entry needs to be added
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
277 * at it's tail.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
278 * @param data A pointer to the data that needs to be added to the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
279 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
280 * @return VISUAL_OK on succes, -VISUAL_ERROR_LIST_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
281 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
282 int visual_list_add (VisList *list, void *data)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
283 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
284 VisListEntry *current, *prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
285
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
286 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
287
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
288 current = visual_mem_new0 (VisListEntry, 1);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
289
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
290 /* Assign data element */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
291 current->data = data;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
292
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
293 /* Add list entry to list */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
294 /* Is this the first entry for this list ? */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
295 if (list->head == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
296 list->head = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
297 list->tail = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
298 } else {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
299 /* Nope, add to tail of this list */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
300 prev = list->tail;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
301
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
302 /* Exchange pointers */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
303 prev->next = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
304 current->prev = prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
305
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
306 /* Point tail to new entry */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
307 list->tail = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
308 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
309
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
310 /* Done */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
311 list->count++;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
312
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
313 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
314 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
315
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
316 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
317 * Insert an entry in the middle of a list. By adding it
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
318 * after the le entry.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
319 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
320 * @param list Pointer to the VisList in which an entry needs to be inserted.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
321 * @param le Pointer to a VisListEntry after which the entry needs to be inserted.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
322 * @param data Pointer to the data the new entry represents.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
323 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
324 * @return VISUAL_OK on succes, -VISUAL_ERROR_LIST_NULL, -VISUAL_ERROR_LIST_ENTRY_NULL or
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
325 * -VISUAL_ERROR_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
326 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
327 int visual_list_insert (VisList *list, VisListEntry **le, void *data)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
328 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
329 VisListEntry *prev, *next, *current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
330
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
331 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
332 visual_log_return_val_if_fail (le != NULL, -VISUAL_ERROR_LIST_ENTRY_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
333 visual_log_return_val_if_fail (data != NULL, -VISUAL_ERROR_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
334
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
335 current = visual_mem_new0 (VisListEntry, 1);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
336
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
337 /* Assign data element */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
338 current->data = data;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
339
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
340 /* Add entry to list */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
341 if (list->head == NULL && *le == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
342 /* First entry */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
343 list->head = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
344 list->tail = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
345 } else if (*le == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
346 /* Insert entry at first position */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
347 next = list->head;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
348 /* Exchange pointers */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
349 current->next = next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
350 next->prev = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
351 /* Point head to current pointer */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
352 list->head = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
353 } else {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
354 /* Insert entry at *le's position */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
355 prev = *le;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
356 next = prev->next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
357
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
358 current->prev = prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
359 current->next = next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
360
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
361 prev->next = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
362 if (next != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
363 next->prev = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
364 else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
365 list->tail = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
366 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
367
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
368 /* Hop to new entry */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
369 *le = current;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
370
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
371 /* Done */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
372 list->count++;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
373
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
374 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
375 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
376
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
377 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
378 * Removes an entry from the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
379 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
380 * @param list A pointer to the VisList in which an entry needs to be deleted.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
381 * @param le A pointer to the entry that needs to be deleted.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
382 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
383 * @return VISUAL_OK on succes, -VISUAL_ERROR_LIST_NULL or -VISUAL_ERROR_LIST_ENTRY_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
384 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
385 int visual_list_delete (VisList *list, VisListEntry **le)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
386 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
387 VisListEntry *prev, *current, *next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
388
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
389 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
390 visual_log_return_val_if_fail (le != NULL, -VISUAL_ERROR_LIST_ENTRY_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
391
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
392 prev = current = next = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
393
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
394 /* Valid list entry ? */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
395 if (*le == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
396 visual_log (VISUAL_LOG_CRITICAL, "There is no list entry to delete");
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
397
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
398 return -VISUAL_ERROR_LIST_ENTRY_INVALID; /* Nope */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
399 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
400
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
401 /* Point new to le's previous entry */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
402 current = *le;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
403 prev = current->prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
404 next = current->next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
405
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
406 /* Does it have a previous entry ? */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
407 if (prev != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
408 prev->next = next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
409 else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
410 list->head = next;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
411
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
412 if (next != NULL) /* It does have a next entry ? */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
413 next->prev = prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
414 else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
415 list->tail = prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
416
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
417 /* Point current entry to previous one */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
418 *le = prev;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
419
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
420 /* Free 'old' pointer */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
421 list->count--;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
422 visual_mem_free (current);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
423
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
424 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
425 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
426
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
427 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
428 * Counts the number of entries within the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
429 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
430 * @param list A pointer to the list from which an entry count is needed.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
431 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
432 * @return The number of elements or -VISUAL_ERROR_LIST_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
433 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
434 int visual_list_count (VisList *list)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
435 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
436 VisListEntry *le = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
437 int count = 0;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
438
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
439 visual_log_return_val_if_fail (list != NULL, -VISUAL_ERROR_LIST_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
440
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
441 /* Walk through list */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
442 while (visual_list_next (list, &le) != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
443 count++;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
444
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
445 list->count = count;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
446
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
447 return count;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
448 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
449
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
450 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
451 * @}
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
452 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
453