1 /* deque.c generated by valac 0.18.0, the Vala compiler
2 * generated from deque.vala, do not modify */
6 * Copyright (C) 2009 Didier Villevalois
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
27 #include <glib-object.h>
30 #define GEE_TYPE_TRAVERSABLE (gee_traversable_get_type ())
31 #define GEE_TRAVERSABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_TRAVERSABLE, GeeTraversable))
32 #define GEE_IS_TRAVERSABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_TRAVERSABLE))
33 #define GEE_TRAVERSABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_TRAVERSABLE, GeeTraversableIface))
35 typedef struct _GeeTraversable GeeTraversable;
36 typedef struct _GeeTraversableIface GeeTraversableIface;
38 #define GEE_TRAVERSABLE_TYPE_STREAM (gee_traversable_stream_get_type ())
40 #define GEE_TYPE_LAZY (gee_lazy_get_type ())
41 #define GEE_LAZY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_LAZY, GeeLazy))
42 #define GEE_LAZY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_LAZY, GeeLazyClass))
43 #define GEE_IS_LAZY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_LAZY))
44 #define GEE_IS_LAZY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_LAZY))
45 #define GEE_LAZY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_LAZY, GeeLazyClass))
47 typedef struct _GeeLazy GeeLazy;
48 typedef struct _GeeLazyClass GeeLazyClass;
50 #define GEE_TYPE_ITERATOR (gee_iterator_get_type ())
51 #define GEE_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ITERATOR, GeeIterator))
52 #define GEE_IS_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ITERATOR))
53 #define GEE_ITERATOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_ITERATOR, GeeIteratorIface))
55 typedef struct _GeeIterator GeeIterator;
56 typedef struct _GeeIteratorIface GeeIteratorIface;
58 #define GEE_TYPE_ITERABLE (gee_iterable_get_type ())
59 #define GEE_ITERABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ITERABLE, GeeIterable))
60 #define GEE_IS_ITERABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ITERABLE))
61 #define GEE_ITERABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_ITERABLE, GeeIterableIface))
63 typedef struct _GeeIterable GeeIterable;
64 typedef struct _GeeIterableIface GeeIterableIface;
66 #define GEE_TYPE_COLLECTION (gee_collection_get_type ())
67 #define GEE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_COLLECTION, GeeCollection))
68 #define GEE_IS_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_COLLECTION))
69 #define GEE_COLLECTION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_COLLECTION, GeeCollectionIface))
71 typedef struct _GeeCollection GeeCollection;
72 typedef struct _GeeCollectionIface GeeCollectionIface;
74 #define GEE_TYPE_QUEUE (gee_queue_get_type ())
75 #define GEE_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_QUEUE, GeeQueue))
76 #define GEE_IS_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_QUEUE))
77 #define GEE_QUEUE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_QUEUE, GeeQueueIface))
79 typedef struct _GeeQueue GeeQueue;
80 typedef struct _GeeQueueIface GeeQueueIface;
82 #define GEE_TYPE_DEQUE (gee_deque_get_type ())
83 #define GEE_DEQUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_DEQUE, GeeDeque))
84 #define GEE_IS_DEQUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_DEQUE))
85 #define GEE_DEQUE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_DEQUE, GeeDequeIface))
87 typedef struct _GeeDeque GeeDeque;
88 typedef struct _GeeDequeIface GeeDequeIface;
90 typedef gboolean (*GeeForallFunc) (gpointer g, void* user_data);
92 GEE_TRAVERSABLE_STREAM_YIELD,
93 GEE_TRAVERSABLE_STREAM_CONTINUE,
94 GEE_TRAVERSABLE_STREAM_END
95 } GeeTraversableStream;
97 typedef GeeTraversableStream (*GeeStreamFunc) (GeeTraversableStream state, GeeLazy* g, GeeLazy** lazy, void* user_data);
98 struct _GeeIteratorIface {
99 GTypeInterface parent_iface;
100 gboolean (*next) (GeeIterator* self);
101 gboolean (*has_next) (GeeIterator* self);
102 gpointer (*get) (GeeIterator* self);
103 void (*remove) (GeeIterator* self);
104 gboolean (*get_valid) (GeeIterator* self);
105 gboolean (*get_read_only) (GeeIterator* self);
108 typedef gpointer (*GeeFoldFunc) (gpointer g, gpointer a, void* user_data);
109 typedef gpointer (*GeeMapFunc) (gpointer g, void* user_data);
110 typedef gboolean (*GeePredicate) (gconstpointer g, void* user_data);
111 struct _GeeTraversableIface {
112 GTypeInterface parent_iface;
113 GType (*get_g_type) (GeeTraversable* self);
114 GBoxedCopyFunc (*get_g_dup_func) (GeeTraversable* self);
115 GDestroyNotify (*get_g_destroy_func) (GeeTraversable* self);
116 gboolean (*foreach) (GeeTraversable* self, GeeForallFunc f, void* f_target);
117 GeeIterator* (*stream) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeStreamFunc f, void* f_target, GDestroyNotify f_target_destroy_notify);
118 gpointer (*fold) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldFunc f, void* f_target, gpointer seed);
119 GeeIterator* (*map) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeMapFunc f, void* f_target);
120 GeeIterator* (*scan) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldFunc f, void* f_target, gpointer seed);
121 GeeIterator* (*filter) (GeeTraversable* self, GeePredicate pred, void* pred_target, GDestroyNotify pred_target_destroy_notify);
122 GeeIterator* (*chop) (GeeTraversable* self, gint offset, gint length);
123 GType (*get_element_type) (GeeTraversable* self);
126 struct _GeeIterableIface {
127 GTypeInterface parent_iface;
128 GType (*get_g_type) (GeeIterable* self);
129 GBoxedCopyFunc (*get_g_dup_func) (GeeIterable* self);
130 GDestroyNotify (*get_g_destroy_func) (GeeIterable* self);
131 GeeIterator* (*iterator) (GeeIterable* self);
134 struct _GeeCollectionIface {
135 GTypeInterface parent_iface;
136 GType (*get_g_type) (GeeCollection* self);
137 GBoxedCopyFunc (*get_g_dup_func) (GeeCollection* self);
138 GDestroyNotify (*get_g_destroy_func) (GeeCollection* self);
139 gboolean (*contains) (GeeCollection* self, gconstpointer item);
140 gboolean (*add) (GeeCollection* self, gconstpointer item);
141 gboolean (*remove) (GeeCollection* self, gconstpointer item);
142 void (*clear) (GeeCollection* self);
143 gboolean (*add_all) (GeeCollection* self, GeeCollection* collection);
144 gboolean (*contains_all) (GeeCollection* self, GeeCollection* collection);
145 gboolean (*remove_all) (GeeCollection* self, GeeCollection* collection);
146 gboolean (*retain_all) (GeeCollection* self, GeeCollection* collection);
147 gpointer* (*to_array) (GeeCollection* self, int* result_length1);
148 gint (*get_size) (GeeCollection* self);
149 gboolean (*get_is_empty) (GeeCollection* self);
150 gboolean (*get_read_only) (GeeCollection* self);
151 GeeCollection* (*get_read_only_view) (GeeCollection* self);
154 struct _GeeQueueIface {
155 GTypeInterface parent_iface;
156 GType (*get_g_type) (GeeQueue* self);
157 GBoxedCopyFunc (*get_g_dup_func) (GeeQueue* self);
158 GDestroyNotify (*get_g_destroy_func) (GeeQueue* self);
159 gboolean (*offer) (GeeQueue* self, gconstpointer element);
160 gpointer (*peek) (GeeQueue* self);
161 gpointer (*poll) (GeeQueue* self);
162 gint (*drain) (GeeQueue* self, GeeCollection* recipient, gint amount);
163 gint (*get_capacity) (GeeQueue* self);
164 gint (*get_remaining_capacity) (GeeQueue* self);
165 gboolean (*get_is_full) (GeeQueue* self);
168 struct _GeeDequeIface {
169 GTypeInterface parent_iface;
170 GType (*get_g_type) (GeeDeque* self);
171 GBoxedCopyFunc (*get_g_dup_func) (GeeDeque* self);
172 GDestroyNotify (*get_g_destroy_func) (GeeDeque* self);
173 gboolean (*offer_head) (GeeDeque* self, gconstpointer element);
174 gpointer (*peek_head) (GeeDeque* self);
175 gpointer (*poll_head) (GeeDeque* self);
176 gint (*drain_head) (GeeDeque* self, GeeCollection* recipient, gint amount);
177 gboolean (*offer_tail) (GeeDeque* self, gconstpointer element);
178 gpointer (*peek_tail) (GeeDeque* self);
179 gpointer (*poll_tail) (GeeDeque* self);
180 gint (*drain_tail) (GeeDeque* self, GeeCollection* recipient, gint amount);
185 GType gee_traversable_stream_get_type (void) G_GNUC_CONST;
186 gpointer gee_lazy_ref (gpointer instance);
187 void gee_lazy_unref (gpointer instance);
188 GParamSpec* gee_param_spec_lazy (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
189 void gee_value_set_lazy (GValue* value, gpointer v_object);
190 void gee_value_take_lazy (GValue* value, gpointer v_object);
191 gpointer gee_value_get_lazy (const GValue* value);
192 GType gee_lazy_get_type (void) G_GNUC_CONST;
193 GType gee_iterator_get_type (void) G_GNUC_CONST;
194 GType gee_traversable_get_type (void) G_GNUC_CONST;
195 GType gee_iterable_get_type (void) G_GNUC_CONST;
196 GType gee_collection_get_type (void) G_GNUC_CONST;
197 GType gee_queue_get_type (void) G_GNUC_CONST;
198 GType gee_deque_get_type (void) G_GNUC_CONST;
199 gboolean gee_deque_offer_head (GeeDeque* self, gconstpointer element);
200 gpointer gee_deque_peek_head (GeeDeque* self);
201 gpointer gee_deque_poll_head (GeeDeque* self);
202 gint gee_deque_drain_head (GeeDeque* self, GeeCollection* recipient, gint amount);
203 gboolean gee_deque_offer_tail (GeeDeque* self, gconstpointer element);
204 gpointer gee_deque_peek_tail (GeeDeque* self);
205 gpointer gee_deque_poll_tail (GeeDeque* self);
206 gint gee_deque_drain_tail (GeeDeque* self, GeeCollection* recipient, gint amount);
210 * Offers the specified element to the head of this deque.
212 * @param element the element to offer to the queue
214 * @return ``true`` if the element was added to the queue
216 gboolean gee_deque_offer_head (GeeDeque* self, gconstpointer element) {
217 g_return_val_if_fail (self != NULL, FALSE);
218 return GEE_DEQUE_GET_INTERFACE (self)->offer_head (self, element);
223 * Peeks (retrieves, but not remove) an element from this queue.
225 * @return the element peeked from the queue (or ``null`` if none was
228 gpointer gee_deque_peek_head (GeeDeque* self) {
229 g_return_val_if_fail (self != NULL, NULL);
230 return GEE_DEQUE_GET_INTERFACE (self)->peek_head (self);
235 * Polls (retrieves and remove) an element from the head of this queue.
237 * @return the element polled from the queue (or ``null`` if none was
240 gpointer gee_deque_poll_head (GeeDeque* self) {
241 g_return_val_if_fail (self != NULL, NULL);
242 return GEE_DEQUE_GET_INTERFACE (self)->poll_head (self);
247 * Drains the specified amount of elements from the head of this queue in
248 * the specified recipient collection.
250 * @param recipient the recipient collection to drain the elements to
251 * @param amount the amount of elements to drain
253 * @return the amount of elements that were actually drained
255 gint gee_deque_drain_head (GeeDeque* self, GeeCollection* recipient, gint amount) {
256 g_return_val_if_fail (self != NULL, 0);
257 return GEE_DEQUE_GET_INTERFACE (self)->drain_head (self, recipient, amount);
262 * Offers the specified element to the tail of this deque
264 * @param element the element to offer to the queue
266 * @return ``true`` if the element was added to the queue
268 gboolean gee_deque_offer_tail (GeeDeque* self, gconstpointer element) {
269 g_return_val_if_fail (self != NULL, FALSE);
270 return GEE_DEQUE_GET_INTERFACE (self)->offer_tail (self, element);
275 * Peeks (retrieves, but not remove) an element from the tail of this
278 * @return the element peeked from the queue (or ``null`` if none was
281 gpointer gee_deque_peek_tail (GeeDeque* self) {
282 g_return_val_if_fail (self != NULL, NULL);
283 return GEE_DEQUE_GET_INTERFACE (self)->peek_tail (self);
288 * Polls (retrieves and remove) an element from the tail of this queue.
290 * @return the element polled from the queue (or ``null`` if none was
293 gpointer gee_deque_poll_tail (GeeDeque* self) {
294 g_return_val_if_fail (self != NULL, NULL);
295 return GEE_DEQUE_GET_INTERFACE (self)->poll_tail (self);
300 * Drains the specified amount of elements from the tail of this queue in
301 * the specified recipient collection.
303 * @param recipient the recipient collection to drain the elements to
304 * @param amount the amount of elements to drain
306 * @return the amount of elements that were actually drained
308 gint gee_deque_drain_tail (GeeDeque* self, GeeCollection* recipient, gint amount) {
309 g_return_val_if_fail (self != NULL, 0);
310 return GEE_DEQUE_GET_INTERFACE (self)->drain_tail (self, recipient, amount);
314 static void gee_deque_base_init (GeeDequeIface * iface) {
315 static gboolean initialized = FALSE;
323 * A double-ended queue.
325 * A deque can be used either as a queue (First-In-First-Out behavior) or as a
326 * stack (Last-In-First-Out behavior).
328 * The methods defined by this interface behaves exactely in the same way as
329 * the {@link Queue} methods with respect to capacity bounds.
331 * The Deque interface inherits from the {@link Queue} interface. Thus, to use
332 * a deque as a queue, you can equivalently use the folowing method set:
334 * ||<)(> ''Queue method'' ||<)(> ''Deque method'' ||
335 * || {@link Queue.offer} || {@link offer_tail} ||
336 * || {@link Queue.peek} || {@link peek_head} ||
337 * || {@link Queue.poll} || {@link poll_head} ||
338 * || {@link Queue.drain} || {@link drain_head} ||
340 * To use a deque as a stack, just use the method set that acts at the head of
343 * ||<)(> ''Operation'' ||<)(> ''Deque method'' ||
344 * || push an element || {@link offer_head} ||
345 * || peek an element || {@link peek_head} ||
346 * || pop an element || {@link poll_head} ||
348 GType gee_deque_get_type (void) {
349 static volatile gsize gee_deque_type_id__volatile = 0;
350 if (g_once_init_enter (&gee_deque_type_id__volatile)) {
351 static const GTypeInfo g_define_type_info = { sizeof (GeeDequeIface), (GBaseInitFunc) gee_deque_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
352 GType gee_deque_type_id;
353 gee_deque_type_id = g_type_register_static (G_TYPE_INTERFACE, "GeeDeque", &g_define_type_info, 0);
354 g_type_interface_add_prerequisite (gee_deque_type_id, GEE_TYPE_QUEUE);
355 g_once_init_leave (&gee_deque_type_id__volatile, gee_deque_type_id);
357 return gee_deque_type_id__volatile;