1 /* queue.c generated by valac 0.18.0, the Vala compiler
2 * generated from queue.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 typedef gboolean (*GeeForallFunc) (gpointer g, void* user_data);
84 GEE_TRAVERSABLE_STREAM_YIELD,
85 GEE_TRAVERSABLE_STREAM_CONTINUE,
86 GEE_TRAVERSABLE_STREAM_END
87 } GeeTraversableStream;
89 typedef GeeTraversableStream (*GeeStreamFunc) (GeeTraversableStream state, GeeLazy* g, GeeLazy** lazy, void* user_data);
90 struct _GeeIteratorIface {
91 GTypeInterface parent_iface;
92 gboolean (*next) (GeeIterator* self);
93 gboolean (*has_next) (GeeIterator* self);
94 gpointer (*get) (GeeIterator* self);
95 void (*remove) (GeeIterator* self);
96 gboolean (*get_valid) (GeeIterator* self);
97 gboolean (*get_read_only) (GeeIterator* self);
100 typedef gpointer (*GeeFoldFunc) (gpointer g, gpointer a, void* user_data);
101 typedef gpointer (*GeeMapFunc) (gpointer g, void* user_data);
102 typedef gboolean (*GeePredicate) (gconstpointer g, void* user_data);
103 struct _GeeTraversableIface {
104 GTypeInterface parent_iface;
105 GType (*get_g_type) (GeeTraversable* self);
106 GBoxedCopyFunc (*get_g_dup_func) (GeeTraversable* self);
107 GDestroyNotify (*get_g_destroy_func) (GeeTraversable* self);
108 gboolean (*foreach) (GeeTraversable* self, GeeForallFunc f, void* f_target);
109 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);
110 gpointer (*fold) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldFunc f, void* f_target, gpointer seed);
111 GeeIterator* (*map) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeMapFunc f, void* f_target);
112 GeeIterator* (*scan) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldFunc f, void* f_target, gpointer seed);
113 GeeIterator* (*filter) (GeeTraversable* self, GeePredicate pred, void* pred_target, GDestroyNotify pred_target_destroy_notify);
114 GeeIterator* (*chop) (GeeTraversable* self, gint offset, gint length);
115 GType (*get_element_type) (GeeTraversable* self);
118 struct _GeeIterableIface {
119 GTypeInterface parent_iface;
120 GType (*get_g_type) (GeeIterable* self);
121 GBoxedCopyFunc (*get_g_dup_func) (GeeIterable* self);
122 GDestroyNotify (*get_g_destroy_func) (GeeIterable* self);
123 GeeIterator* (*iterator) (GeeIterable* self);
126 struct _GeeCollectionIface {
127 GTypeInterface parent_iface;
128 GType (*get_g_type) (GeeCollection* self);
129 GBoxedCopyFunc (*get_g_dup_func) (GeeCollection* self);
130 GDestroyNotify (*get_g_destroy_func) (GeeCollection* self);
131 gboolean (*contains) (GeeCollection* self, gconstpointer item);
132 gboolean (*add) (GeeCollection* self, gconstpointer item);
133 gboolean (*remove) (GeeCollection* self, gconstpointer item);
134 void (*clear) (GeeCollection* self);
135 gboolean (*add_all) (GeeCollection* self, GeeCollection* collection);
136 gboolean (*contains_all) (GeeCollection* self, GeeCollection* collection);
137 gboolean (*remove_all) (GeeCollection* self, GeeCollection* collection);
138 gboolean (*retain_all) (GeeCollection* self, GeeCollection* collection);
139 gpointer* (*to_array) (GeeCollection* self, int* result_length1);
140 gint (*get_size) (GeeCollection* self);
141 gboolean (*get_is_empty) (GeeCollection* self);
142 gboolean (*get_read_only) (GeeCollection* self);
143 GeeCollection* (*get_read_only_view) (GeeCollection* self);
146 struct _GeeQueueIface {
147 GTypeInterface parent_iface;
148 GType (*get_g_type) (GeeQueue* self);
149 GBoxedCopyFunc (*get_g_dup_func) (GeeQueue* self);
150 GDestroyNotify (*get_g_destroy_func) (GeeQueue* self);
151 gboolean (*offer) (GeeQueue* self, gconstpointer element);
152 gpointer (*peek) (GeeQueue* self);
153 gpointer (*poll) (GeeQueue* self);
154 gint (*drain) (GeeQueue* self, GeeCollection* recipient, gint amount);
155 gint (*get_capacity) (GeeQueue* self);
156 gint (*get_remaining_capacity) (GeeQueue* self);
157 gboolean (*get_is_full) (GeeQueue* self);
162 GType gee_traversable_stream_get_type (void) G_GNUC_CONST;
163 gpointer gee_lazy_ref (gpointer instance);
164 void gee_lazy_unref (gpointer instance);
165 GParamSpec* gee_param_spec_lazy (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
166 void gee_value_set_lazy (GValue* value, gpointer v_object);
167 void gee_value_take_lazy (GValue* value, gpointer v_object);
168 gpointer gee_value_get_lazy (const GValue* value);
169 GType gee_lazy_get_type (void) G_GNUC_CONST;
170 GType gee_iterator_get_type (void) G_GNUC_CONST;
171 GType gee_traversable_get_type (void) G_GNUC_CONST;
172 GType gee_iterable_get_type (void) G_GNUC_CONST;
173 GType gee_collection_get_type (void) G_GNUC_CONST;
174 GType gee_queue_get_type (void) G_GNUC_CONST;
175 gboolean gee_queue_offer (GeeQueue* self, gconstpointer element);
176 static gboolean gee_queue_real_offer (GeeQueue* self, gconstpointer element);
177 gboolean gee_collection_add (GeeCollection* self, gconstpointer item);
178 gpointer gee_queue_peek (GeeQueue* self);
179 gpointer gee_queue_poll (GeeQueue* self);
180 gint gee_queue_drain (GeeQueue* self, GeeCollection* recipient, gint amount);
181 static gint gee_queue_real_drain (GeeQueue* self, GeeCollection* recipient, gint amount);
182 #define GEE_QUEUE_UNBOUNDED_CAPACITY (-1)
183 gint gee_queue_get_capacity (GeeQueue* self);
184 gint gee_queue_get_remaining_capacity (GeeQueue* self);
185 gboolean gee_queue_get_is_full (GeeQueue* self);
189 * Offers the specified element to this queue.
191 * @param element the element to offer to the queue
193 * @return ``true`` if the element was added to the queue
195 static gboolean gee_queue_real_offer (GeeQueue* self, gconstpointer element) {
196 gboolean result = FALSE;
197 gconstpointer _tmp0_;
198 gboolean _tmp1_ = FALSE;
200 _tmp1_ = gee_collection_add ((GeeCollection*) self, _tmp0_);
206 gboolean gee_queue_offer (GeeQueue* self, gconstpointer element) {
207 g_return_val_if_fail (self != NULL, FALSE);
208 return GEE_QUEUE_GET_INTERFACE (self)->offer (self, element);
213 * Peeks (retrieves, but not remove) an element from this queue.
215 * @return the element peeked from the queue (or ``null`` if none was
218 gpointer gee_queue_peek (GeeQueue* self) {
219 g_return_val_if_fail (self != NULL, NULL);
220 return GEE_QUEUE_GET_INTERFACE (self)->peek (self);
225 * Polls (retrieves and remove) an element from this queue.
227 * @return the element polled from the queue (or ``null`` if none was
230 gpointer gee_queue_poll (GeeQueue* self) {
231 g_return_val_if_fail (self != NULL, NULL);
232 return GEE_QUEUE_GET_INTERFACE (self)->poll (self);
237 * Drains the specified amount of elements from this queue in the specified
238 * recipient collection.
240 * @param recipient the recipient collection to drain the elements to
241 * @param amount the amount of elements to drain
243 * @return the amount of elements that were actually drained
245 static gint gee_queue_real_drain (GeeQueue* self, GeeCollection* recipient, gint amount) {
249 g_return_val_if_fail (recipient != NULL, 0);
253 gboolean _tmp0_ = FALSE;
254 gboolean _tmp1_ = FALSE;
258 GeeCollection* _tmp9_;
259 gconstpointer _tmp10_;
262 if (_tmp2_ == (-1)) {
270 _tmp1_ = _tmp4_ >= 0;
274 gpointer _tmp6_ = NULL;
275 gconstpointer _tmp7_;
276 _tmp6_ = gee_queue_poll (self);
277 ((item == NULL) || (GEE_QUEUE_GET_INTERFACE (self)->get_g_destroy_func (self) == NULL)) ? NULL : (item = (GEE_QUEUE_GET_INTERFACE (self)->get_g_destroy_func (self) (item), NULL));
280 _tmp0_ = _tmp7_ != NULL;
290 gee_collection_add (_tmp9_, _tmp10_);
292 drained = _tmp11_ + 1;
295 ((item == NULL) || (GEE_QUEUE_GET_INTERFACE (self)->get_g_destroy_func (self) == NULL)) ? NULL : (item = (GEE_QUEUE_GET_INTERFACE (self)->get_g_destroy_func (self) (item), NULL));
300 gint gee_queue_drain (GeeQueue* self, GeeCollection* recipient, gint amount) {
301 g_return_val_if_fail (self != NULL, 0);
302 return GEE_QUEUE_GET_INTERFACE (self)->drain (self, recipient, amount);
306 gint gee_queue_get_capacity (GeeQueue* self) {
307 g_return_val_if_fail (self != NULL, 0);
308 return GEE_QUEUE_GET_INTERFACE (self)->get_capacity (self);
312 gint gee_queue_get_remaining_capacity (GeeQueue* self) {
313 g_return_val_if_fail (self != NULL, 0);
314 return GEE_QUEUE_GET_INTERFACE (self)->get_remaining_capacity (self);
318 gboolean gee_queue_get_is_full (GeeQueue* self) {
319 g_return_val_if_fail (self != NULL, FALSE);
320 return GEE_QUEUE_GET_INTERFACE (self)->get_is_full (self);
324 static void gee_queue_base_init (GeeQueueIface * iface) {
325 static gboolean initialized = FALSE;
329 * The capacity of this queue (or ``null`` if capacity is not bound).
331 g_object_interface_install_property (iface, g_param_spec_int ("capacity", "capacity", "capacity", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
333 * The remaining capacity of this queue (or ``null`` if capacity is not
336 g_object_interface_install_property (iface, g_param_spec_int ("remaining-capacity", "remaining-capacity", "remaining-capacity", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
338 * Specifies whether this queue is full.
340 g_object_interface_install_property (iface, g_param_spec_boolean ("is-full", "is-full", "is-full", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
341 iface->offer = gee_queue_real_offer;
342 iface->drain = gee_queue_real_drain;
348 * A collection designed for holding elements prior to processing.
350 * Although all Queue implementations do not limit the amount of elements they
351 * can contain, this interface supports for capacity-bounded queues. When
352 * capacity is not bound, then the {@link capacity} and
353 * {@link remaining_capacity} both return {@link UNBOUNDED_CAPACITY}.
355 * This interface defines methods that will never fail whatever the state of
356 * the queue is. For capacity-bounded queues, those methods will either return
357 * ``false`` or ``null`` to specify that the insert or retrieval did not occur
358 * because the queue was full or empty.
360 * Queue implementations are not limited to First-In-First-Out behavior and can
361 * propose different ordering of their elements. Each Queue implementation have
362 * to specify how it orders its elements.
364 * Queue implementations do not allow insertion of ``null`` elements, although
365 * some implementations, such as {@link LinkedList}, do not prohibit insertion
366 * of ``null``. Even in the implementations that permit it, ``null`` should not be
367 * inserted into a Queue, as ``null`` is also used as a special return value by
368 * the poll method to indicate that the queue contains no elements.
370 GType gee_queue_get_type (void) {
371 static volatile gsize gee_queue_type_id__volatile = 0;
372 if (g_once_init_enter (&gee_queue_type_id__volatile)) {
373 static const GTypeInfo g_define_type_info = { sizeof (GeeQueueIface), (GBaseInitFunc) gee_queue_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
374 GType gee_queue_type_id;
375 gee_queue_type_id = g_type_register_static (G_TYPE_INTERFACE, "GeeQueue", &g_define_type_info, 0);
376 g_type_interface_add_prerequisite (gee_queue_type_id, GEE_TYPE_COLLECTION);
377 g_once_init_leave (&gee_queue_type_id__volatile, gee_queue_type_id);
379 return gee_queue_type_id__volatile;