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