Bug 608196 - Overflow-safe g_new family
[platform/upstream/glib.git] / glib / gsequence.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3  * Soeren Sandmann (sandmann@daimi.au.dk)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
22 #error "Only <glib.h> can be included directly."
23 #endif
24
25 #ifndef __G_SEQUENCE_H__
26 #define __G_SEQUENCE_H__
27
28 #include <glib/gtypes.h>
29
30 G_BEGIN_DECLS
31
32 typedef struct _GSequence      GSequence;
33 typedef struct _GSequenceNode  GSequenceIter;
34
35 typedef gint (* GSequenceIterCompareFunc) (GSequenceIter *a,
36                                            GSequenceIter *b,
37                                            gpointer       data);
38
39
40 /* GSequence */
41 GSequence *    g_sequence_new                (GDestroyNotify            data_destroy);
42 void           g_sequence_free               (GSequence                *seq);
43 gint           g_sequence_get_length         (GSequence                *seq);
44 void           g_sequence_foreach            (GSequence                *seq,
45                                               GFunc                     func,
46                                               gpointer                  user_data);
47 void           g_sequence_foreach_range      (GSequenceIter            *begin,
48                                               GSequenceIter            *end,
49                                               GFunc                     func,
50                                               gpointer                  user_data);
51 void           g_sequence_sort               (GSequence                *seq,
52                                               GCompareDataFunc          cmp_func,
53                                               gpointer                  cmp_data);
54 void           g_sequence_sort_iter          (GSequence                *seq,
55                                               GSequenceIterCompareFunc  cmp_func,
56                                               gpointer                  cmp_data);
57
58
59 /* Getting iters */
60 GSequenceIter *g_sequence_get_begin_iter     (GSequence                *seq);
61 GSequenceIter *g_sequence_get_end_iter       (GSequence                *seq);
62 GSequenceIter *g_sequence_get_iter_at_pos    (GSequence                *seq,
63                                               gint                      pos);
64 GSequenceIter *g_sequence_append             (GSequence                *seq,
65                                               gpointer                  data);
66 GSequenceIter *g_sequence_prepend            (GSequence                *seq,
67                                               gpointer                  data);
68 GSequenceIter *g_sequence_insert_before      (GSequenceIter            *iter,
69                                               gpointer                  data);
70 void           g_sequence_move               (GSequenceIter            *src,
71                                               GSequenceIter            *dest);
72 void           g_sequence_swap               (GSequenceIter            *a,
73                                               GSequenceIter            *b);
74 GSequenceIter *g_sequence_insert_sorted      (GSequence                *seq,
75                                               gpointer                  data,
76                                               GCompareDataFunc          cmp_func,
77                                               gpointer                  cmp_data);
78 GSequenceIter *g_sequence_insert_sorted_iter (GSequence                *seq,
79                                               gpointer                  data,
80                                               GSequenceIterCompareFunc  iter_cmp,
81                                               gpointer                  cmp_data);
82 void           g_sequence_sort_changed       (GSequenceIter            *iter,
83                                               GCompareDataFunc          cmp_func,
84                                               gpointer                  cmp_data);
85 void           g_sequence_sort_changed_iter  (GSequenceIter            *iter,
86                                               GSequenceIterCompareFunc  iter_cmp,
87                                               gpointer                  cmp_data);
88 void           g_sequence_remove             (GSequenceIter            *iter);
89 void           g_sequence_remove_range       (GSequenceIter            *begin,
90                                               GSequenceIter            *end);
91 void           g_sequence_move_range         (GSequenceIter            *dest,
92                                               GSequenceIter            *begin,
93                                               GSequenceIter            *end);
94 GSequenceIter *g_sequence_search             (GSequence                *seq,
95                                               gpointer                  data,
96                                               GCompareDataFunc          cmp_func,
97                                               gpointer                  cmp_data);
98 GSequenceIter *g_sequence_search_iter        (GSequence                *seq,
99                                               gpointer                  data,
100                                               GSequenceIterCompareFunc  iter_cmp,
101                                               gpointer                  cmp_data);
102
103
104 /* Dereferencing */
105 gpointer       g_sequence_get                (GSequenceIter            *iter);
106 void           g_sequence_set                (GSequenceIter            *iter,
107                                               gpointer                  data);
108
109 /* Operations on GSequenceIter * */
110 gboolean       g_sequence_iter_is_begin      (GSequenceIter            *iter);
111 gboolean       g_sequence_iter_is_end        (GSequenceIter            *iter);
112 GSequenceIter *g_sequence_iter_next          (GSequenceIter            *iter);
113 GSequenceIter *g_sequence_iter_prev          (GSequenceIter            *iter);
114 gint           g_sequence_iter_get_position  (GSequenceIter            *iter);
115 GSequenceIter *g_sequence_iter_move          (GSequenceIter            *iter,
116                                               gint                      delta);
117 GSequence *    g_sequence_iter_get_sequence  (GSequenceIter            *iter);
118
119
120 /* Search */
121 gint           g_sequence_iter_compare       (GSequenceIter            *a,
122                                               GSequenceIter            *b);
123 GSequenceIter *g_sequence_range_get_midpoint (GSequenceIter            *begin,
124                                               GSequenceIter            *end);
125
126 G_END_DECLS
127
128 #endif /* __G_SEQUENCE_H__ */