2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2008 Liam Girdwood
21 #include <libastrodb/astrodb.h>
23 /*! \defgroup list Lists
25 * Single and double linked lists
29 /*! \fn astrodb_slist* astrodb_slist_prepend(astrodb_slist* slist, void* object)
31 * \param object object
34 * Prepends an object to the list head
36 struct astrodb_slist
*astrodb_slist_prepend(struct astrodb_slist
*slist
,
39 struct astrodb_slist
*list
= malloc(sizeof(struct astrodb_slist
));
49 /*! \fn astrodb_slist* astrodb_slist_append(astrodb_slist* slist, void* object)
51 * \param object object
54 * Appends an object to the list tail
56 struct astrodb_slist
*astrodb_slist_append(struct astrodb_slist
*slist
,
59 struct astrodb_slist
*list
= malloc(sizeof(struct astrodb_slist
));
77 /*! \fn void astrodb_slist_foreach(astrodb_slist* slist, astrodb_func func, void* user)
79 * \param func Function to be called
80 * \param user User data
82 * Calls a function for every object in slist.
84 void astrodb_slist_foreach(struct astrodb_slist
*slist
, astrodb_func func
,
91 func(slist
->data
, user_data
);
96 /*! \fn void astrodb_slist_foreach_free(astrodb_slist* slist, astrodb_func func, void* user)
98 * \param func Function to be called
99 * \param user User data
101 * Calls a function for every object in slist and then frees object.
103 void astrodb_slist_foreach_free(struct astrodb_slist
*slist
,
104 astrodb_func func
, void *user_data
)
106 struct astrodb_slist
*slist_
;
110 func(slist
->data
, user_data
);
125 /*! \fn astrodb_dlist* astrodb_dlist_prepend(astrodb_dlist* dlist, void* object)
127 * \param object object
130 * Prepends an object to the list head
132 struct astrodb_dlist
*astrodb_dlist_prepend(struct astrodb_dlist
*dlist
,
135 struct astrodb_dlist
*list
= malloc(sizeof(struct astrodb_dlist
));
146 /*! \fn astrodb_dlist* astrodb_dlist_prepend(astrodb_dlist* dlist, void* object)
148 * \param object object
151 * Appends an object to the list head
153 struct astrodb_dlist
*astrodb_dlist_append(struct astrodb_dlist
*dlist
,
156 struct astrodb_dlist
*list
= malloc(sizeof(struct astrodb_dlist
));
174 /*! \fn astrodb_dlist* astrodb_dlist_head(astrodb_dlist* dlist)
178 * Get the head of a dlist
180 struct astrodb_dlist
*astrodb_dlist_head(struct astrodb_dlist
*dlist
)
187 /*! \fn astrodb_dlist* astrodb_dlist_free_object(astrodb_dlist* dlist, void* object)
189 * \param object object
190 * \return dlist object before object
192 * Free a single object in dlist
194 struct astrodb_dlist
*astrodb_dlist_free_object(struct astrodb_dlist
*dlist
,
197 struct astrodb_dlist
*head
, *tail
;
200 dlist
= astrodb_dlist_head(dlist
);
201 while (dlist
->data
!= object
&& dlist
)
220 if (tail
) /* LIAM - remove */
225 /*! \fn void astrodb_dlist_foreach(astrodb_dlist* dlist , astrodb_func func, void* user)
227 * \param func Function to be called
228 * \param user User data
230 * Call function for every object in dlist
232 void astrodb_dlist_foreach(struct astrodb_dlist
*dlist
, astrodb_func func
,
235 dlist
= astrodb_dlist_head(dlist
);
238 func(dlist
->data
, user_data
);
243 /*! \fn void astrodb_dlist_foreach_free(astrodb_dlist* dlist, astrodb_func func, void* user)
245 * \param func Function to be called
246 * \param user User data
248 * Call function for every object in dlist and free object
250 void astrodb_dlist_foreach_free(struct astrodb_dlist
*dlist
,
251 astrodb_func func
, void *user_data
)
253 struct astrodb_dlist
*dlist_
;
255 dlist
= astrodb_dlist_head(dlist
);
259 func(dlist
->data
, user_data
);