1 /* GLIB - Library of useful routines for C programming 2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library 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 GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 /* 19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS 20 * file for a list of people on the GLib Team. See the ChangeLog 21 * files for a list of changes. These files are distributed with 22 * GLib at ftp://ftp.gtk.org/pub/gtk/. 23 */ 24 25 #ifndef __G_LIST_H__ 26 #define __G_LIST_H__ 27 28 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) 29 #error "Only <glib.h> can be included directly." 30 #endif 31 32 #include <glib/gmem.h> 33 #include <glib/gnode.h> 34 35 G_BEGIN_DECLS 36 37 typedef struct _GList GList; 38 39 struct _GList 40 { 41 gpointer data; 42 GList *next; 43 GList *prev; 44 }; 45 46 /* Doubly linked lists 47 */ 48 GLIB_AVAILABLE_IN_ALL 49 GList* g_list_alloc (void) G_GNUC_WARN_UNUSED_RESULT; 50 GLIB_AVAILABLE_IN_ALL 51 void g_list_free (GList *list); 52 GLIB_AVAILABLE_IN_ALL 53 void g_list_free_1 (GList *list); 54 #define g_list_free1 g_list_free_1 55 GLIB_AVAILABLE_IN_ALL 56 void g_list_free_full (GList *list, 57 GDestroyNotify free_func); 58 GLIB_AVAILABLE_IN_ALL 59 GList* g_list_append (GList *list, 60 gpointer data) G_GNUC_WARN_UNUSED_RESULT; 61 GLIB_AVAILABLE_IN_ALL 62 GList* g_list_prepend (GList *list, 63 gpointer data) G_GNUC_WARN_UNUSED_RESULT; 64 GLIB_AVAILABLE_IN_ALL 65 GList* g_list_insert (GList *list, 66 gpointer data, 67 gint position) G_GNUC_WARN_UNUSED_RESULT; 68 GLIB_AVAILABLE_IN_ALL 69 GList* g_list_insert_sorted (GList *list, 70 gpointer data, 71 GCompareFunc func) G_GNUC_WARN_UNUSED_RESULT; 72 GLIB_AVAILABLE_IN_ALL 73 GList* g_list_insert_sorted_with_data (GList *list, 74 gpointer data, 75 GCompareDataFunc func, 76 gpointer user_data) G_GNUC_WARN_UNUSED_RESULT; 77 GLIB_AVAILABLE_IN_ALL 78 GList* g_list_insert_before (GList *list, 79 GList *sibling, 80 gpointer data) G_GNUC_WARN_UNUSED_RESULT; 81 GLIB_AVAILABLE_IN_2_62 82 GList* g_list_insert_before_link (GList *list, 83 GList *sibling, 84 GList *link_) G_GNUC_WARN_UNUSED_RESULT; 85 GLIB_AVAILABLE_IN_ALL 86 GList* g_list_concat (GList *list1, 87 GList *list2) G_GNUC_WARN_UNUSED_RESULT; 88 GLIB_AVAILABLE_IN_ALL 89 GList* g_list_remove (GList *list, 90 gconstpointer data) G_GNUC_WARN_UNUSED_RESULT; 91 GLIB_AVAILABLE_IN_ALL 92 GList* g_list_remove_all (GList *list, 93 gconstpointer data) G_GNUC_WARN_UNUSED_RESULT; 94 GLIB_AVAILABLE_IN_ALL 95 GList* g_list_remove_link (GList *list, 96 GList *llink) G_GNUC_WARN_UNUSED_RESULT; 97 GLIB_AVAILABLE_IN_ALL 98 GList* g_list_delete_link (GList *list, 99 GList *link_) G_GNUC_WARN_UNUSED_RESULT; 100 GLIB_AVAILABLE_IN_ALL 101 GList* g_list_reverse (GList *list) G_GNUC_WARN_UNUSED_RESULT; 102 GLIB_AVAILABLE_IN_ALL 103 GList* g_list_copy (GList *list) G_GNUC_WARN_UNUSED_RESULT; 104 105 GLIB_AVAILABLE_IN_2_34 106 GList* g_list_copy_deep (GList *list, 107 GCopyFunc func, 108 gpointer user_data) G_GNUC_WARN_UNUSED_RESULT; 109 110 GLIB_AVAILABLE_IN_ALL 111 GList* g_list_nth (GList *list, 112 guint n); 113 GLIB_AVAILABLE_IN_ALL 114 GList* g_list_nth_prev (GList *list, 115 guint n); 116 GLIB_AVAILABLE_IN_ALL 117 GList* g_list_find (GList *list, 118 gconstpointer data); 119 GLIB_AVAILABLE_IN_ALL 120 GList* g_list_find_custom (GList *list, 121 gconstpointer data, 122 GCompareFunc func); 123 GLIB_AVAILABLE_IN_ALL 124 gint g_list_position (GList *list, 125 GList *llink); 126 GLIB_AVAILABLE_IN_ALL 127 gint g_list_index (GList *list, 128 gconstpointer data); 129 GLIB_AVAILABLE_IN_ALL 130 GList* g_list_last (GList *list); 131 GLIB_AVAILABLE_IN_ALL 132 GList* g_list_first (GList *list); 133 GLIB_AVAILABLE_IN_ALL 134 guint g_list_length (GList *list); 135 GLIB_AVAILABLE_IN_ALL 136 void g_list_foreach (GList *list, 137 GFunc func, 138 gpointer user_data); 139 GLIB_AVAILABLE_IN_ALL 140 GList* g_list_sort (GList *list, 141 GCompareFunc compare_func) G_GNUC_WARN_UNUSED_RESULT; 142 GLIB_AVAILABLE_IN_ALL 143 GList* g_list_sort_with_data (GList *list, 144 GCompareDataFunc compare_func, 145 gpointer user_data) G_GNUC_WARN_UNUSED_RESULT; 146 GLIB_AVAILABLE_IN_ALL 147 gpointer g_list_nth_data (GList *list, 148 guint n); 149 150 GLIB_AVAILABLE_IN_2_64 151 void g_clear_list (GList **list_ptr, 152 GDestroyNotify destroy); 153 154 #define g_clear_list(list_ptr, destroy) \ 155 G_STMT_START { \ 156 GList *_list; \ 157 \ 158 _list = *(list_ptr); \ 159 if (_list) \ 160 { \ 161 *list_ptr = NULL; \ 162 \ 163 if ((destroy) != NULL) \ 164 g_list_free_full (_list, (destroy)); \ 165 else \ 166 g_list_free (_list); \ 167 } \ 168 } G_STMT_END \ 169 GLIB_AVAILABLE_MACRO_IN_2_64 170 171 172 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL) 173 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL) 174 175 G_END_DECLS 176 177 #endif /* __G_LIST_H__ */ 178