1 /* queue.c generated by valac 0.19.0.4-d6d4, the Vala compiler
2 * generated from queue.vala, do not modify */
3
4 /* queue.vala
5 *
6 * Copyright (C) 2009 Didier Villevalois
7 *
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.
12
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.
17
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
21 *
22 * Author:
23 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
24 */
25
26 #include <glib.h>
27 #include <glib-object.h>
28
29
30 #define GEE_TYPE_ITERABLE (gee_iterable_get_type ())
31 #define GEE_ITERABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ITERABLE, GeeIterable))
32 #define GEE_IS_ITERABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ITERABLE))
33 #define GEE_ITERABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_ITERABLE, GeeIterableIface))
34
35 typedef struct _GeeIterable GeeIterable;
36 typedef struct _GeeIterableIface GeeIterableIface;
37
38 #define GEE_TYPE_ITERATOR (gee_iterator_get_type ())
39 #define GEE_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ITERATOR, GeeIterator))
40 #define GEE_IS_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ITERATOR))
41 #define GEE_ITERATOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_ITERATOR, GeeIteratorIface))
42
43 typedef struct _GeeIterator GeeIterator;
44 typedef struct _GeeIteratorIface GeeIteratorIface;
45
46 #define GEE_TYPE_COLLECTION (gee_collection_get_type ())
47 #define GEE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_COLLECTION, GeeCollection))
48 #define GEE_IS_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_COLLECTION))
49 #define GEE_COLLECTION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_COLLECTION, GeeCollectionIface))
50
51 typedef struct _GeeCollection GeeCollection;
52 typedef struct _GeeCollectionIface GeeCollectionIface;
53
54 #define GEE_TYPE_QUEUE (gee_queue_get_type ())
55 #define GEE_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_QUEUE, GeeQueue))
56 #define GEE_IS_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_QUEUE))
57 #define GEE_QUEUE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_QUEUE, GeeQueueIface))
58
59 typedef struct _GeeQueue GeeQueue;
60 typedef struct _GeeQueueIface GeeQueueIface;
61
62 struct _GeeIteratorIface {
63 GTypeInterface parent_iface;
64 gboolean (*next) (GeeIterator* self);
65 gboolean (*has_next) (GeeIterator* self);
66 gboolean (*first) (GeeIterator* self);
67 gpointer (*get) (GeeIterator* self);
68 void (*remove) (GeeIterator* self);
69 };
70
71 struct _GeeIterableIface {
72 GTypeInterface parent_iface;
73 GeeIterator* (*iterator) (GeeIterable* self);
74 GType (*get_element_type) (GeeIterable* self);
75 };
76
77 struct _GeeCollectionIface {
78 GTypeInterface parent_iface;
79 gboolean (*contains) (GeeCollection* self, gconstpointer item);
80 gboolean (*add) (GeeCollection* self, gconstpointer item);
81 gboolean (*remove) (GeeCollection* self, gconstpointer item);
82 void (*clear) (GeeCollection* self);
83 gboolean (*add_all) (GeeCollection* self, GeeCollection* collection);
84 gboolean (*contains_all) (GeeCollection* self, GeeCollection* collection);
85 gboolean (*remove_all) (GeeCollection* self, GeeCollection* collection);
86 gboolean (*retain_all) (GeeCollection* self, GeeCollection* collection);
87 gpointer* (*to_array) (GeeCollection* self, int* result_length1);
88 gint (*get_size) (GeeCollection* self);
89 gboolean (*get_is_empty) (GeeCollection* self);
90 GeeCollection* (*get_read_only_view) (GeeCollection* self);
91 };
92
93 struct _GeeQueueIface {
94 GTypeInterface parent_iface;
95 gboolean (*offer) (GeeQueue* self, gconstpointer element);
96 gpointer (*peek) (GeeQueue* self);
97 gpointer (*poll) (GeeQueue* self);
98 gint (*drain) (GeeQueue* self, GeeCollection* recipient, gint amount);
99 gint (*get_capacity) (GeeQueue* self);
100 gint (*get_remaining_capacity) (GeeQueue* self);
101 gboolean (*get_is_full) (GeeQueue* self);
102 };
103
104
105
106 GType gee_iterator_get_type (void) G_GNUC_CONST;
107 GType gee_iterable_get_type (void) G_GNUC_CONST;
108 GType gee_collection_get_type (void) G_GNUC_CONST;
109 GType gee_queue_get_type (void) G_GNUC_CONST;
110 gboolean gee_queue_offer (GeeQueue* self, gconstpointer element);
111 gpointer gee_queue_peek (GeeQueue* self);
112 gpointer gee_queue_poll (GeeQueue* self);
113 gint gee_queue_drain (GeeQueue* self, GeeCollection* recipient, gint amount);
114 #define GEE_QUEUE_UNBOUNDED_CAPACITY (-1)
115 gint gee_queue_get_capacity (GeeQueue* self);
116 gint gee_queue_get_remaining_capacity (GeeQueue* self);
117 gboolean gee_queue_get_is_full (GeeQueue* self);
118
119
120 /**
121 * Offers the specified element to this queue.
122 *
123 * @param element the element to offer to the queue
124 *
125 * @return ``true`` if the element was added to the queue
126 */
gee_queue_offer(GeeQueue * self,gconstpointer element)127 gboolean gee_queue_offer (GeeQueue* self, gconstpointer element) {
128 g_return_val_if_fail (self != NULL, FALSE);
129 return GEE_QUEUE_GET_INTERFACE (self)->offer (self, element);
130 }
131
132
133 /**
134 * Peeks (retrieves, but not remove) an element from this queue.
135 *
136 * @return the element peeked from the queue (or ``null`` if none was
137 * available)
138 */
gee_queue_peek(GeeQueue * self)139 gpointer gee_queue_peek (GeeQueue* self) {
140 g_return_val_if_fail (self != NULL, NULL);
141 return GEE_QUEUE_GET_INTERFACE (self)->peek (self);
142 }
143
144
145 /**
146 * Polls (retrieves and remove) an element from this queue.
147 *
148 * @return the element polled from the queue (or ``null`` if none was
149 * available)
150 */
gee_queue_poll(GeeQueue * self)151 gpointer gee_queue_poll (GeeQueue* self) {
152 g_return_val_if_fail (self != NULL, NULL);
153 return GEE_QUEUE_GET_INTERFACE (self)->poll (self);
154 }
155
156
157 /**
158 * Drains the specified amount of elements from this queue in the specified
159 * recipient collection.
160 *
161 * @param recipient the recipient collection to drain the elements to
162 * @param amount the amount of elements to drain
163 *
164 * @return the amount of elements that were actually drained
165 */
gee_queue_drain(GeeQueue * self,GeeCollection * recipient,gint amount)166 gint gee_queue_drain (GeeQueue* self, GeeCollection* recipient, gint amount) {
167 g_return_val_if_fail (self != NULL, 0);
168 return GEE_QUEUE_GET_INTERFACE (self)->drain (self, recipient, amount);
169 }
170
171
gee_queue_get_capacity(GeeQueue * self)172 gint gee_queue_get_capacity (GeeQueue* self) {
173 g_return_val_if_fail (self != NULL, 0);
174 return GEE_QUEUE_GET_INTERFACE (self)->get_capacity (self);
175 }
176
177
gee_queue_get_remaining_capacity(GeeQueue * self)178 gint gee_queue_get_remaining_capacity (GeeQueue* self) {
179 g_return_val_if_fail (self != NULL, 0);
180 return GEE_QUEUE_GET_INTERFACE (self)->get_remaining_capacity (self);
181 }
182
183
gee_queue_get_is_full(GeeQueue * self)184 gboolean gee_queue_get_is_full (GeeQueue* self) {
185 g_return_val_if_fail (self != NULL, FALSE);
186 return GEE_QUEUE_GET_INTERFACE (self)->get_is_full (self);
187 }
188
189
gee_queue_base_init(GeeQueueIface * iface)190 static void gee_queue_base_init (GeeQueueIface * iface) {
191 static gboolean initialized = FALSE;
192 if (!initialized) {
193 initialized = TRUE;
194 /**
195 * The capacity of this queue (or ``null`` if capacity is not bound).
196 */
197 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));
198 /**
199 * The remaining capacity of this queue (or ``null`` if capacity is not
200 * bound).
201 */
202 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));
203 /**
204 * Specifies whether this queue is full.
205 */
206 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));
207 }
208 }
209
210
211 /**
212 * A collection designed for holding elements prior to processing.
213 *
214 * Although all Queue implementations do not limit the amount of elements they
215 * can contain, this interface supports for capacity-bounded queues. When
216 * capacity is not bound, then the {@link capacity} and
217 * {@link remaining_capacity} both return {@link UNBOUNDED_CAPACITY}.
218 *
219 * This interface defines methods that will never fail whatever the state of
220 * the queue is. For capacity-bounded queues, those methods will either return
221 * ``false`` or ``null`` to specify that the insert or retrieval did not occur
222 * because the queue was full or empty.
223 *
224 * Queue implementations are not limited to First-In-First-Out behavior and can
225 * propose different ordering of their elements. Each Queue implementation have
226 * to specify how it orders its elements.
227 *
228 * Queue implementations do not allow insertion of ``null`` elements, although
229 * some implementations, such as {@link LinkedList}, do not prohibit insertion
230 * of ``null``. Even in the implementations that permit it, ``null`` should not be
231 * inserted into a Queue, as ``null`` is also used as a special return value by
232 * the poll method to indicate that the queue contains no elements.
233 */
gee_queue_get_type(void)234 GType gee_queue_get_type (void) {
235 static volatile gsize gee_queue_type_id__volatile = 0;
236 if (g_once_init_enter (&gee_queue_type_id__volatile)) {
237 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 };
238 GType gee_queue_type_id;
239 gee_queue_type_id = g_type_register_static (G_TYPE_INTERFACE, "GeeQueue", &g_define_type_info, 0);
240 g_type_interface_add_prerequisite (gee_queue_type_id, GEE_TYPE_COLLECTION);
241 g_once_init_leave (&gee_queue_type_id__volatile, gee_queue_type_id);
242 }
243 return gee_queue_type_id__volatile;
244 }
245
246
247
248