1 /* 2 * Copyright (C) 2003-2009 the oxine project 3 * 4 * xine is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * xine is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 17 * 18 * doubly linked lists with builtin iterator, 19 * based upon xine_list functions of the xine project 20 */ 21 22 23 #ifndef HAVE_LIST_H 24 #define HAVE_LIST_H 25 26 #include <inttypes.h> 27 28 typedef struct list_s list_t; 29 30 /* 31 * create a new, empty list 32 */ 33 34 #ifdef DEBUG 35 list_t *_list_new_tagged(const char *file, int line); 36 #define list_new() (_list_new_tagged(__FILE__, __LINE__)) 37 #define xine_list_new() (_list_new_tagged(__FILE__, __LINE__)) 38 #else 39 list_t *list_new (void) ; 40 #define xine_list_new list_new 41 #endif 42 43 /* 44 * dispose a list (and only the list, contents have to be managed separately) 45 */ 46 47 void list_free (list_t *l) ; 48 49 /* 50 * set cursor to the first element in list, return contents of first entry 51 */ 52 53 void *list_first_content (list_t *l) ; 54 55 /* 56 * set cursor to the next element, returns its contents 57 */ 58 59 void *list_next_content (list_t *l) ; 60 61 /* 62 * returns contents of the current element 63 */ 64 65 void *list_current_content (list_t *l) ; 66 67 /* 68 * returns 1, if list is empty 69 */ 70 71 int list_is_empty (list_t *l) ; 72 73 /* 74 * set cursor to the last element, returns its contents 75 */ 76 77 void *list_last_content (list_t *l) ; 78 79 /* 80 * set cursor to the previous element, return its contents 81 */ 82 83 void *list_prev_content (list_t *l) ; 84 85 /* 86 * sort element into list by priority. list_first_content returns then 87 * the element with the highest priority. 88 */ 89 90 void list_append_priority_content (list_t *l, void *content, int priority) ; 91 92 /* 93 * append element at the end of the list 94 */ 95 96 #ifdef DEBUG 97 void _list_append_content (list_t *l, void *content, const char *file, int line); 98 #define list_append_content(list,cont) (_list_append_content(list, cont, __FILE__, __LINE__)) 99 #define xine_list_append_content(list,cont) (_list_append_content(list, cont, __FILE__, __LINE__)) 100 #else 101 void list_append_content (list_t *l, void *content) ; 102 #define xine_list_append_content list_append_content 103 #endif 104 105 /* 106 * insert content just before cursor position 107 */ 108 109 void list_insert_content (list_t *l, void *content) ; 110 111 /* 112 * delete current element (its contents have to be freen seperately!) 113 */ 114 115 void list_delete_current (list_t *l) ; 116 117 /* 118 * compatibility macros 119 */ 120 121 #define xine_list_t list_t 122 #define xine_list_free list_free 123 #define xine_list_first_content list_first_content 124 #define xine_list_next_content list_next_content 125 #define xine_list_current_content list_current_content 126 #define xine_list_is_empty list_is_empty 127 #define xine_list_last_content list_last_content 128 #define xine_list_prev_content list_prev_content 129 #define xine_list_append_priority_content list_append_priority_content 130 #define xine_list_insert_content list_insert_content 131 #define xine_list_delete_current list_delete_current 132 133 /* 134 * yet another list implementation 135 * thanks to glib project. 136 */ 137 138 typedef struct _g_list_t g_list_t; 139 140 struct _g_list_t 141 { 142 void* data; 143 g_list_t *next; 144 g_list_t *prev; 145 }; 146 147 typedef int(*list_compare)(const void*, const void*); 148 typedef int(*list_compare_data)(const void*, const void*, void*); 149 typedef int(*list_func)(void*,void*); 150 151 /* Doubly linked lists 152 */ 153 //void g_list_push_allocator (GAllocator *allocator); 154 //void g_list_pop_allocator (void); 155 g_list_t* g_list_new (void); 156 void g_list_free (g_list_t *list); 157 void g_list_free_1 (g_list_t *list); 158 g_list_t* g_list_append (g_list_t *list, void *data); 159 g_list_t* g_list_prepend (g_list_t *list, void *data); 160 g_list_t* g_list_insert (g_list_t *list, void *data, int position); 161 g_list_t* g_list_insert_sorted (g_list_t *list, void* data, list_compare func); 162 g_list_t* g_list_insert_before (g_list_t *list, g_list_t *sibling, void* data); 163 g_list_t* g_list_concat (g_list_t *list1, g_list_t *list2); 164 g_list_t* g_list_remove (g_list_t *list, const void *data); 165 g_list_t* g_list_remove_all (g_list_t *list, const void *data); 166 g_list_t* g_list_remove_link (g_list_t *list, g_list_t *llink); 167 g_list_t* g_list_delete_link (g_list_t *list, g_list_t *link_); 168 g_list_t* g_list_reverse (g_list_t *list); 169 g_list_t* g_list_copy (g_list_t *list); 170 g_list_t* g_list_nth (g_list_t *list, unsigned int n); 171 g_list_t* g_list_nth_prev (g_list_t *list, unsigned int n); 172 g_list_t* g_list_find (g_list_t *list, const void *data); 173 g_list_t* g_list_find_custom (g_list_t *list, const void *data, list_compare func); 174 int g_list_position (g_list_t *list, g_list_t *llink); 175 int g_list_index (g_list_t *list, const void * data); 176 g_list_t* g_list_last (g_list_t *list); 177 g_list_t* g_list_first (g_list_t *list); 178 unsigned int g_list_length (g_list_t *list); 179 void g_list_foreach (g_list_t *list, list_func func, void* user_data); 180 g_list_t* g_list_sort (g_list_t *list, list_compare compare_func); 181 g_list_t* g_list_sort_with_data (g_list_t *list, list_compare compare_func, void* user_data); 182 void* g_list_nth_data (g_list_t *list, unsigned int n); 183 184 #define g_list_previous(list) ((list) ? (((g_list_t *)(list))->prev) : NULL) 185 #define g_list_next(list) ((list) ? (((g_list_t *)(list))->next) : NULL) 186 187 #endif 188