1 /* GTS - Library for the manipulation of triangulated surfaces
2 * Copyright (C) 1999 Stéphane Popinet
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
30 * Returns: a new #GtsFifo.
32 GtsFifo
* gts_fifo_new ()
34 GtsFifo
* fifo
= g_malloc (sizeof (GtsFifo
));
36 fifo
->head
= fifo
->tail
= NULL
;
43 * @fp: a file pointer.
45 * Writes the content of @fifo in @fp.
47 void gts_fifo_write (GtsFifo
* fifo
, FILE * fp
)
51 g_return_if_fail (fifo
!= NULL
);
52 g_return_if_fail (fp
!= NULL
);
57 fprintf (fp
, "%p ", i
->data
);
66 * @data: data to add to @fifo.
68 * Push @data into @fifo.
70 void gts_fifo_push (GtsFifo
* fifo
, gpointer data
)
72 g_return_if_fail (fifo
!= NULL
);
74 fifo
->head
= g_list_prepend (fifo
->head
, data
);
75 if (fifo
->tail
== NULL
)
76 fifo
->tail
= fifo
->head
;
83 * Removes the first element from @fifo.
85 * Returns: the first element in @fifo or %NULL if @fifo is empty.
87 gpointer
gts_fifo_pop (GtsFifo
* fifo
)
92 g_return_val_if_fail (fifo
!= NULL
, NULL
);
94 if (fifo
->tail
== NULL
)
96 tail
= fifo
->tail
->prev
;
97 data
= fifo
->tail
->data
;
98 fifo
->head
= g_list_remove_link (fifo
->head
, fifo
->tail
);
99 g_list_free_1 (fifo
->tail
);
108 * Returns: the first element in @fifo or %NULL if @fifo is empty.
110 gpointer
gts_fifo_top (GtsFifo
* fifo
)
112 g_return_val_if_fail (fifo
!= NULL
, NULL
);
114 if (fifo
->tail
== NULL
)
116 return fifo
->tail
->data
;
123 * Returns: the number of elements in @fifo.
125 guint
gts_fifo_size (GtsFifo
* fifo
)
127 g_return_val_if_fail (fifo
!= NULL
, 0);
129 return g_list_length (fifo
->head
);
136 * Frees all the memory allocated for @fifo.
138 void gts_fifo_destroy (GtsFifo
* fifo
)
140 g_return_if_fail (fifo
!= NULL
);
141 g_list_free (fifo
->head
);
149 * Returns: %TRUE if @fifo is empty, %FALSE otherwise.
151 gboolean
gts_fifo_is_empty (GtsFifo
* fifo
)
153 g_return_val_if_fail (fifo
!= NULL
, TRUE
);
155 return (fifo
->head
== NULL
);
162 * @data: user data to be passed to @func.
164 * Calls @func in order for each item in @fifo, passing @data.
166 void gts_fifo_foreach (GtsFifo
* fifo
, GtsFunc func
, gpointer data
)
170 g_return_if_fail (fifo
!= NULL
);
171 g_return_if_fail (func
!= NULL
);
175 (* func
) (i
->data
, data
);
184 * Reverses the order of elements in @fifo.
186 void gts_fifo_reverse (GtsFifo
* fifo
)
188 g_return_if_fail (fifo
!= NULL
);
190 fifo
->tail
= fifo
->head
;
191 fifo
->head
= g_list_reverse (fifo
->head
);