00001 /* 00002 Copyright (C) 2006 Adam Charrett 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License 00006 as published by the Free Software Foundation; either version 2 00007 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 00018 list.h 00019 00020 Generic list management functions. 00021 00022 */ 00023 00024 #ifndef _DVBSTREAMER_LIST_H 00025 #define _DVBSTREAMER_LIST_H 00026 00027 #include "types.h" 00028 00037 typedef struct ListEntry_s 00038 { 00039 void *data; 00040 struct ListEntry_s *next; 00041 struct ListEntry_s *prev; 00042 }ListEntry_t; 00043 00047 typedef struct List_s 00048 { 00049 int count; 00050 ListEntry_t *head; 00051 ListEntry_t *tail; 00052 }List_t; 00053 00057 typedef struct ListIterator_s 00058 { 00059 List_t *list; 00060 ListEntry_t *current; 00061 }ListIterator_t; 00062 00067 typedef void (*ListDataDestructor_t)(void *); 00068 00083 #define ListIterator_Init(_iterator, _list) (_iterator).current = (_list)->head, (_iterator).list = _list 00084 00088 #define ListIterator_Next(_iterator) ((_iterator).current = ((_iterator).current?((_iterator).current->next):NULL)) 00089 00094 #define ListIterator_Current(_iterator) ((_iterator).current->data) 00095 00101 #define ListIterator_MoreEntries(_iterator) ((_iterator).current) 00102 00107 List_t *ListCreate(); 00108 00114 #define ObjectListCreate() ListCreate() 00115 00121 void ListFree(List_t *list, void (*destructor)(void *data)); 00122 00128 #define ObjectListFree(list) ListFree(list, ListFreeObject); 00129 00134 void ListFreeObject(void *ptr); 00135 00142 bool ListAdd(List_t *list, void *data); 00143 00150 bool ListRemove(List_t *list, void *data); 00151 00158 bool ListInsertBeforeCurrent(ListIterator_t *iterator, void *data); 00165 bool ListInsertAfterCurrent(ListIterator_t *iterator, void *data); 00172 void ListRemoveCurrent(ListIterator_t *iterator); 00173 00179 #define ListCount(_list) (_list)->count 00180 00185 void ListDump(List_t *list); 00186 00188 #endif