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_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))
35 typedef struct _GeeIterable GeeIterable;
36 typedef struct _GeeIterableIface GeeIterableIface;
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))
43 typedef struct _GeeIterator GeeIterator;
44 typedef struct _GeeIteratorIface GeeIteratorIface;
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))
51 typedef struct _GeeCollection GeeCollection;
52 typedef struct _GeeCollectionIface GeeCollectionIface;
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))
59 typedef struct _GeeQueue GeeQueue;
60 typedef struct _GeeQueueIface GeeQueueIface;
62 #define GEE_TYPE_DEQUE (gee_deque_get_type ())
63 #define GEE_DEQUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_DEQUE, GeeDeque))
64 #define GEE_IS_DEQUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_DEQUE))
65 #define GEE_DEQUE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_DEQUE, GeeDequeIface))
67 typedef struct _GeeDeque GeeDeque;
68 typedef struct _GeeDequeIface GeeDequeIface;
70 struct _GeeIteratorIface {
71 GTypeInterface parent_iface;
72 gboolean (*next) (GeeIterator* self);
73 gboolean (*has_next) (GeeIterator* self);
74 gboolean (*first) (GeeIterator* self);
75 gpointer (*get) (GeeIterator* self);
76 void (*remove) (GeeIterator* self);
79 struct _GeeIterableIface {
80 GTypeInterface parent_iface;
81 GeeIterator* (*iterator) (GeeIterable* self);
82 GType (*get_element_type) (GeeIterable* self);
85 struct _GeeCollectionIface {
86 GTypeInterface parent_iface;
87 gboolean (*contains) (GeeCollection* self, gconstpointer item);
88 gboolean (*add) (GeeCollection* self, gconstpointer item);
89 gboolean (*remove) (GeeCollection* self, gconstpointer item);
90 void (*clear) (GeeCollection* self);
91 gboolean (*add_all) (GeeCollection* self, GeeCollection* collection);
92 gboolean (*contains_all) (GeeCollection* self, GeeCollection* collection);
93 gboolean (*remove_all) (GeeCollection* self, GeeCollection* collection);
94 gboolean (*retain_all) (GeeCollection* self, GeeCollection* collection);
95 gpointer* (*to_array) (GeeCollection* self, int* result_length1);
96 gint (*get_size) (GeeCollection* self);
97 gboolean (*get_is_empty) (GeeCollection* self);
98 GeeCollection* (*get_read_only_view) (GeeCollection* self);
101 struct _GeeQueueIface {
102 GTypeInterface parent_iface;
103 gboolean (*offer) (GeeQueue* self, gconstpointer element);
104 gpointer (*peek) (GeeQueue* self);
105 gpointer (*poll) (GeeQueue* self);
106 gint (*drain) (GeeQueue* self, GeeCollection* recipient, gint amount);
107 gint (*get_capacity) (GeeQueue* self);
108 gint (*get_remaining_capacity) (GeeQueue* self);
109 gboolean (*get_is_full) (GeeQueue* self);
112 struct _GeeDequeIface {
113 GTypeInterface parent_iface;
114 gboolean (*offer_head) (GeeDeque* self, gconstpointer element);
115 gpointer (*peek_head) (GeeDeque* self);
116 gpointer (*poll_head) (GeeDeque* self);
117 gint (*drain_head) (GeeDeque* self, GeeCollection* recipient, gint amount);
118 gboolean (*offer_tail) (GeeDeque* self, gconstpointer element);
119 gpointer (*peek_tail) (GeeDeque* self);
120 gpointer (*poll_tail) (GeeDeque* self);
121 gint (*drain_tail) (GeeDeque* self, GeeCollection* recipient, gint amount);
126 GType gee_iterator_get_type (void) G_GNUC_CONST;
127 GType gee_iterable_get_type (void) G_GNUC_CONST;
128 GType gee_collection_get_type (void) G_GNUC_CONST;
129 GType gee_queue_get_type (void) G_GNUC_CONST;
130 GType gee_deque_get_type (void) G_GNUC_CONST;
131 gboolean gee_deque_offer_head (GeeDeque* self, gconstpointer element);
132 gpointer gee_deque_peek_head (GeeDeque* self);
133 gpointer gee_deque_poll_head (GeeDeque* self);
134 gint gee_deque_drain_head (GeeDeque* self, GeeCollection* recipient, gint amount);
135 gboolean gee_deque_offer_tail (GeeDeque* self, gconstpointer element);
136 gpointer gee_deque_peek_tail (GeeDeque* self);
137 gpointer gee_deque_poll_tail (GeeDeque* self);
138 gint gee_deque_drain_tail (GeeDeque* self, GeeCollection* recipient, gint amount);
142 * Offers the specified element to the head of this deque.
144 * @param element the element to offer to the queue
146 * @return ``true`` if the element was added to the queue
148 gboolean gee_deque_offer_head (GeeDeque* self, gconstpointer element) {
149 g_return_val_if_fail (self != NULL, FALSE);
150 return GEE_DEQUE_GET_INTERFACE (self)->offer_head (self, element);
155 * Peeks (retrieves, but not remove) an element from this queue.
157 * @return the element peeked from the queue (or ``null`` if none was
160 gpointer gee_deque_peek_head (GeeDeque* self) {
161 g_return_val_if_fail (self != NULL, NULL);
162 return GEE_DEQUE_GET_INTERFACE (self)->peek_head (self);
167 * Polls (retrieves and remove) an element from the head of this queue.
169 * @return the element polled from the queue (or ``null`` if none was
172 gpointer gee_deque_poll_head (GeeDeque* self) {
173 g_return_val_if_fail (self != NULL, NULL);
174 return GEE_DEQUE_GET_INTERFACE (self)->poll_head (self);
179 * Drains the specified amount of elements from the head of this queue in
180 * the specified recipient collection.
182 * @param recipient the recipient collection to drain the elements to
183 * @param amount the amount of elements to drain
185 * @return the amount of elements that were actually drained
187 gint gee_deque_drain_head (GeeDeque* self, GeeCollection* recipient, gint amount) {
188 g_return_val_if_fail (self != NULL, 0);
189 return GEE_DEQUE_GET_INTERFACE (self)->drain_head (self, recipient, amount);
194 * Offers the specified element to the tail of this deque
196 * @param element the element to offer to the queue
198 * @return ``true`` if the element was added to the queue
200 gboolean gee_deque_offer_tail (GeeDeque* self, gconstpointer element) {
201 g_return_val_if_fail (self != NULL, FALSE);
202 return GEE_DEQUE_GET_INTERFACE (self)->offer_tail (self, element);
207 * Peeks (retrieves, but not remove) an element from the tail of this
210 * @return the element peeked from the queue (or ``null`` if none was
213 gpointer gee_deque_peek_tail (GeeDeque* self) {
214 g_return_val_if_fail (self != NULL, NULL);
215 return GEE_DEQUE_GET_INTERFACE (self)->peek_tail (self);
220 * Polls (retrieves and remove) an element from the tail of this queue.
222 * @return the element polled from the queue (or ``null`` if none was
225 gpointer gee_deque_poll_tail (GeeDeque* self) {
226 g_return_val_if_fail (self != NULL, NULL);
227 return GEE_DEQUE_GET_INTERFACE (self)->poll_tail (self);
232 * Drains the specified amount of elements from the tail of this queue in
233 * the specified recipient collection.
235 * @param recipient the recipient collection to drain the elements to
236 * @param amount the amount of elements to drain
238 * @return the amount of elements that were actually drained
240 gint gee_deque_drain_tail (GeeDeque* self, GeeCollection* recipient, gint amount) {
241 g_return_val_if_fail (self != NULL, 0);
242 return GEE_DEQUE_GET_INTERFACE (self)->drain_tail (self, recipient, amount);
246 static void gee_deque_base_init (GeeDequeIface * iface) {
247 static gboolean initialized = FALSE;
255 * A double-ended queue.
257 * A deque can be used either as a queue (First-In-First-Out behavior) or as a
258 * stack (Last-In-First-Out behavior).
260 * The methods defined by this interface behaves exactely in the same way as
261 * the {@link Queue} methods with respect to capacity bounds.
263 * The Deque interface inherits from the {@link Queue} interface. Thus, to use
264 * a deque as a queue, you can equivalently use the folowing method set:
266 * ||<)(> ''Queue method'' ||<)(> ''Deque method'' ||
267 * || {@link Queue.offer} || {@link offer_tail} ||
268 * || {@link Queue.peek} || {@link peek_head} ||
269 * || {@link Queue.poll} || {@link poll_head} ||
270 * || {@link Queue.drain} || {@link drain_head} ||
272 * To use a deque as a stack, just use the method set that acts at the head of
275 * ||<)(> ''Operation'' ||<)(> ''Deque method'' ||
276 * || push an element || {@link offer_head} ||
277 * || peek an element || {@link peek_head} ||
278 * || pop an element || {@link poll_head} ||
280 GType gee_deque_get_type (void) {
281 static volatile gsize gee_deque_type_id__volatile = 0;
282 if (g_once_init_enter (&gee_deque_type_id__volatile)) {
283 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 };
284 GType gee_deque_type_id;
285 gee_deque_type_id = g_type_register_static (G_TYPE_INTERFACE, "GeeDeque", &g_define_type_info, 0);
286 g_type_interface_add_prerequisite (gee_deque_type_id, GEE_TYPE_QUEUE);
287 g_once_init_leave (&gee_deque_type_id__volatile, gee_deque_type_id);
289 return gee_deque_type_id__volatile;