PageRenderTime 79ms CodeModel.GetById 70ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/glib/partially-implemented/g_queue.e

http://github.com/tybor/Liberty
Specman e | 611 lines | 239 code | 155 blank | 217 comment | 5 complexity | 9583aa927a942b4a37191169384f7676 MD5 | raw file
  1indexing
  2	description: "Double-ended Queue data structure."
  3	copyright: "[
  4					Copyright (C) 2005 eiffel-libraries team, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20			]"
 21
 22class G_QUEUE [ITEM->WRAPPER]
 23	-- The GQueue structure and its associated functions provide a
 24	-- standard queue data structure. Internally, GQueue uses the same
 25	-- data structure as GList to store elements.
 26
 27inherit 
 28	-- TODO: QUEUE
 29	WRAPPER_COLLECTION
 30		redefine
 31			copy,
 32			dispose
 33		end
 34
 35creation  make, copy, from_external_pointer
 36
 37feature -- Copying
 38
 39	copy (another: like Current) is
 40			-- Copies a queue. Note that is a shallow copy. If the elements in the
 41			-- queue consist of pointers to data, the pointers are copied, but the
 42			-- actual data is not.
 43		do
 44			handle := g_queue_copy (handle)
 45		end
 46
 47feature {} -- Creation
 48	make is
 49			-- Creates a new GQueue.
 50		do
 51			handle:=g_queue_new
 52		end
 53
 54	-- TODO: 	with_capacity (needed_capacity: INTEGER) is
 55
 56feature
 57	dispose is
 58			-- Frees the memory allocated for the GQueue.
 59		do
 60			g_queue_free (handle)
 61		end
 62
 63	is_empty: BOOLEAN is
 64			-- Is the queue empty.
 65		do
 66			Result := (g_queue_is_empty(handle)).to_boolean
 67		end
 68
 69	count: INTEGER is
 70			-- the number of items in queue.
 71			-- TODO: should be NATURAL
 72		do
 73			Result := g_queue_get_length (handle)
 74		ensure positive: Result >= 0
 75		end
 76
 77	reverse is
 78			-- Reverses the order of the items in queue.
 79		do
 80			g_queue_reverse (handle)
 81		end
 82
 83
 84	foreach (a_procedure: PROCEDURE [TUPLE [like first]]) is
 85			-- Calls `a_procedure' for each element in the queue passing user_data
 86			-- to the function.
 87		do
 88			--g_queue_foreach (handle, (GQueue *queue, GFunc func, gpointer
 89			--user_data);
 90		end
 91
 92	-- GList* g_queue_find (GQueue *queue, gconstpointer data);
 93
 94	-- Finds the first link in queue which contains data.
 95	
 96	-- queue : 	a GQueue
 97	-- data : 	data to find
 98	-- Returns : 	The first link in queue which contains data.
 99
100	-- Since 2.4
101	-- g_queue_find_custom ()
102
103	-- GList* g_queue_find_custom (GQueue *queue, gconstpointer data,
104	-- GCompareFunc func);
105
106	-- Finds an element in a GQueue, using a supplied function to find the
107	-- desired element. It iterates over the queue, calling the given function
108	-- which should return 0 when the desired element is found. The function
109	-- takes two gconstpointer arguments, the GQueue element's data as the first
110	-- argument and the given user data as the second argument.
111
112	-- queue : 	a GQueue
113	-- data : 	user data passed to func
114	-- func : 	a GCompareFunc to call for each element. It should return 0 when the desired element is found
115	-- Returns : 	The found link, or NULL if it wasn't found
116
117	-- Since 2.4
118	-- g_queue_sort ()
119
120	-- void g_queue_sort (GQueue *queue, GCompareDataFunc compare_func, gpointer
121	-- user_data);
122	
123	-- Sorts queue using compare_func.
124
125	-- queue : 	a GQueue
126
127	-- compare_func : the GCompareDataFunc used to sort queue. This function is
128	-- passed two elements of the queue and should return 0 if they are equal, a
129	-- negative value if the first comes before the second, and a positive value
130	-- if the second comes before the first.  -- user_data : user data passed to
131	-- compare_func
132
133	-- Since 2.4
134	add (an_item: like first) is
135			-- Adds `an_item' at the head of the queue.
136		require item_not_void: an_item /= Void
137		do
138			g_queue_push_head (handle, an_item.handle)
139		end
140	
141	add_last, push_tail (an_item: like first) is
142			-- Adds `an_item' at the tail of the queue.
143		require item_not_void: an_item /= Void
144		do
145			g_queue_push_tail (handle, an_item.handle)
146		end
147
148	put (an_item: like first; an_index: INTEGER) is
149			-- Inserts `an_item' into queue at `an_index' position. If `an_index'
150			-- is negative or larger than the number of elements in the queue, the
151			-- element is added to the end of the queue.
152		require item_not_void: an_item /= Void
153		do
154			g_queue_push_nth (handle, an_item.handle, an_index)
155		end
156
157
158	remove is
159			-- Removes the first element of the queue.
160		local ptr: POINTER
161		do
162			ptr := g_queue_pop_head (handle)
163			-- g_queue_pop_head returns the data of the first element in the queue,
164			-- or NULL if the queue is empty.
165		end
166
167	remove_tail is
168			-- Removes the last element of the queue.
169		local ptr: POINTER
170		do
171			ptr := g_queue_pop_tail (handle)
172			-- g_queue_pop_tail returns the data of the last element in the queue,
173			-- or NULL if the queue is empty.
174		end
175
176feature -- Other features
177	pop_nth (an_index: INTEGER): ITEM is
178			-- Removes the element of queue at `an_index'. Void if is_empty
179		require 
180			unsigned_index: an_index >= 0
181			valid_index: an_index.in_range (0, count)
182		local ptr: POINTER
183		do
184			ptr := g_queue_pop_nth (handle, an_index)
185			--  g_queue_pop_nth returns the element's data, or NULL if n
186			--  is off the end of queue.			
187			if ptr.is_not_null then
188				Result := new_item
189					Result.from_external_pointer (ptr)
190			end	
191		ensure is_empty implies Result = Void
192		end
193
194	first, head: ITEM is
195			-- the first element of the queue.
196		local ptr: POINTER
197		do
198			ptr := g_queue_peek_head (handle)				
199			-- g_queue_peek_head returns the data of the first element in the
200			-- queue, or NULL if the queue is empty.
201			if ptr.is_not_null then
202				Result := new_item
203				Result.from_external_pointer (ptr)
204			end	
205		ensure is_empty implies Result = Void
206		end
207	
208	last, tail: like first is
209		local ptr: POINTER
210		do
211			ptr := g_queue_peek_tail (handle) 
212			-- g_queue_peek_tail returns the last element of the
213			-- queue. NULL if the queue is empty.
214			if ptr.is_not_null then
215				Result := new_item
216				Result.from_external_pointer (ptr)
217			end	
218		ensure is_empty implies Result = Void
219		end
220
221	get_new_iterator: ITERATOR[ITEM] is
222		obsolete "get_new_iterator is not implemented"
223		do
224			check implemented: False end
225		end
226
227feature {} -- Unwrapped API
228
229-- g_queue_index ()
230
231-- gint        g_queue_index                   (GQueue *queue,
232--                                              gconstpointer data);
233
234-- Returns the position of the first element in queue which contains data.
235
236-- queue : 	a GQueue
237-- data : 	the data to find.
238-- Returns : 	The position of the first element in queue which contains data, or -1 if no element in queue contains data.
239
240-- Since 2.4
241-- g_queue_remove ()
242
243-- void        g_queue_remove                  (GQueue *queue,
244--                                              gconstpointer data);
245
246-- Removes the first element in queue that contains data.
247
248-- queue : 	a GQueue
249-- data : 	data to remove.
250
251-- Since 2.4
252-- g_queue_remove_all ()
253
254-- void        g_queue_remove_all              (GQueue *queue,
255--                                              gconstpointer data);
256
257-- Remove all elemeents in queue which contains data.
258
259-- queue : 	a GQueue
260-- data : 	data to remove
261
262-- Since 2.4
263-- g_queue_insert_before ()
264
265-- void        g_queue_insert_before           (GQueue *queue,
266--                                              GList *sibling,
267--                                              gpointer data);
268
269-- Inserts data into queue before sibling.
270
271-- sibling must be part of queue.
272
273-- queue : 	a GQueue
274-- sibling : 	a GList link that must be part of queue
275-- data : 	the data to insert
276
277-- Since 2.4
278-- g_queue_insert_after ()
279
280-- void        g_queue_insert_after            (GQueue *queue,
281--                                              GList *sibling,
282--                                              gpointer data);
283
284-- Inserts data into queue after sibling
285
286-- sibling must be part of queue
287
288-- queue : 	a GQueue
289-- sibling : 	a GList link that must be part of queue
290-- data : 	the data to insert
291
292-- Since 2.4
293-- g_queue_insert_sorted ()
294
295-- void        g_queue_insert_sorted           (GQueue *queue,
296--                                              gpointer data,
297--                                              GCompareDataFunc func,
298--                                              gpointer user_data);
299
300-- Inserts data into queue using func to determine the new position.
301
302-- queue : 	a GQueue
303-- data : 	the data to insert
304-- func : 	the GCompareDataFunc used to compare elements in the queue. It is called with two elements of the queue and user_data. It should return 0 if the elements are equal, a negative value if the first element comes before the second, and a positive value if the second element comes before the first.
305-- user_data : 	user data passed to func.
306
307-- Since 2.4
308-- g_queue_push_head_link ()
309
310-- void        g_queue_push_head_link          (GQueue *queue,
311--                                              GList *link_);
312
313-- Adds a new element at the head of the queue.
314
315-- queue : 	a GQueue.
316-- link_ : 	a single GList element, not a list with more than one element.
317-- g_queue_push_tail_link ()
318
319-- void        g_queue_push_tail_link          (GQueue *queue,
320--                                              GList *link_);
321
322-- Adds a new element at the tail of the queue.
323
324-- queue : 	a GQueue.
325-- link_ : 	a single GList element, not a list with more than one element.
326-- g_queue_push_nth_link ()
327
328-- void        g_queue_push_nth_link           (GQueue *queue,
329--                                              gint n,
330--                                              GList *link_);
331
332-- Inserts link into queue at the given position.
333
334-- queue : 	a GQueue
335-- n : 	the position to insert the link. If this is negative or larger than the number of elements in queue, the link is added to the end of queue.
336-- link_ : 	the link to add to queue
337
338-- Since 2.4
339-- g_queue_pop_head_link ()
340
341-- GList*      g_queue_pop_head_link           (GQueue *queue);
342
343-- Removes the first element of the queue.
344
345-- queue : 	a GQueue.
346-- Returns : 	the GList element at the head of the queue, or NULL if the queue is empty.
347-- g_queue_pop_tail_link ()
348
349-- GList*      g_queue_pop_tail_link           (GQueue *queue);
350
351-- Removes the last element of the queue.
352
353-- queue : 	a GQueue.
354-- Returns : 	the GList element at the tail of the queue, or NULL if the queue is empty.
355-- g_queue_pop_nth_link ()
356
357-- GList*      g_queue_pop_nth_link            (GQueue *queue,
358--                                              guint n);
359
360-- Removes and returns the link at the given position.
361
362-- queue : 	a GQueue
363-- n : 	the link's position
364-- Returns : 	The n'th link, or NULL if n is off the end of queue.
365
366-- Since 2.4
367-- g_queue_peek_head_link ()
368
369-- GList*      g_queue_peek_head_link          (GQueue *queue);
370
371-- Returns the first link in queue
372
373-- queue : 	a GQueue
374-- Returns : 	the first link in queue, or NULL if queue is empty
375
376-- Since 2.4
377-- g_queue_peek_tail_link ()
378
379-- GList*      g_queue_peek_tail_link          (GQueue *queue);
380
381-- Returns the last link queue.
382
383-- queue : 	a GQueue
384-- Returns : 	the last link in queue, or NULL if queue is empty
385
386-- Since 2.4
387-- g_queue_peek_nth_link ()
388
389-- GList*      g_queue_peek_nth_link           (GQueue *queue,
390--                                              guint n);
391
392-- Returns the link at the given position
393
394-- queue : 	a GQueue
395-- n : 	the position of the link
396-- Returns : 	The link at the n'th position, or NULL if n is off the end of the list
397
398-- Since 2.4
399-- g_queue_link_index ()
400
401-- gint        g_queue_link_index              (GQueue *queue,
402--                                              GList *link_);
403
404-- Returns the position of link_ in queue.
405
406-- queue : 	a Gqueue
407-- link_ : 	A GList link
408-- Returns : 	The position of link_, or -1 if the link is not part of queue
409
410-- Since 2.4
411-- g_queue_unlink ()
412
413-- void        g_queue_unlink                  (GQueue *queue,
414--                                              GList *link_);
415
416-- Unlinks link_ so that it will no longer be part of queue. The link is not freed.
417
418-- link_ must be part of queue,
419
420-- queue : 	a GQueue
421-- link_ : 	a GList link that must be part of queue
422
423-- Since 2.4
424-- g_queue_delete_link ()
425
426-- void        g_queue_delete_link             (GQueue *queue,
427--                                              GList *link_);
428
429-- Removes link_ from queue and frees it.
430
431-- link_ must be part of queue.
432
433-- queue : 	a GQueue
434-- link_ : 	a GList link that must be part of queue
435
436-- Since 2.4
437
438	
439feature {} -- struct GQueue
440
441-- typedef struct {
442--   GList *head;
443--   GList *tail;
444--   guint  length;
445-- } GQueue;
446
447-- Contains the public fields of a Queue.
448-- GList *head; 	a pointer to the first element of the queue.
449-- GList *tail; 	a pointer to the last element of the queue.
450-- guint length; 	the number of elements in the queue.
451
452	struct_size: INTEGER is
453		external "C inline use <glib.h>"
454		alias "sizeof(GQueue)"
455		end
456
457feature {} -- External calls
458
459	g_queue_new: POINTER is -- GQueue*
460		external "C use <glib.h>"
461		end
462
463	g_queue_free (a_queue: POINTER) is
464		external "C use <glib.h>"
465		end
466	
467	g_queue_is_empty (a_queue: POINTER): INTEGER is -- gboolean
468		external "C use <glib.h>"
469		end
470
471	g_queue_get_length (a_queue: POINTER): INTEGER is -- guint
472			-- TODO: Result is guint, should be NATURAL
473		external "C use <glib.h>"
474		end
475	
476	g_queue_reverse (a_queue: POINTER) is
477		external "C use <glib.h>"
478		end
479	
480	g_queue_copy (a_queue: POINTER): POINTER is -- GQueue*
481		external "C use <glib.h>"
482		end
483	
484	g_queue_foreach (a_queue, a_func, user_data: POINTER) is
485		external "C use <glib.h>"
486		end
487	
488	g_queue_find (a_queue, const_data: POINTER): POINTER is -- GList*
489		external "C use <glib.h>"
490		end
491	
492	g_queue_find_custom (a_queue, const_data, a_g_compare_func: POINTER): POINTER is -- GList*
493		external "C use <glib.h>"
494		end
495	
496	g_queue_sort (a_queue, a_g_compare_data_func, user_data: POINTER) is
497		external "C use <glib.h>"
498		end
499
500	g_queue_push_head (a_queue, data: POINTER) is
501		external "C use <glib.h>"
502		end
503	
504	g_queue_push_tail (a_queue, data: POINTER) is
505		external "C use <glib.h>"
506		end
507	
508	g_queue_push_nth (a_queue, data: POINTER; an_index: INTEGER) is
509		external "C use <glib.h>"
510		end
511	
512	g_queue_pop_head (a_queue: POINTER): POINTER is -- gpointer
513		external "C use <glib.h>"
514		end
515	
516	g_queue_pop_tail (a_queue: POINTER): POINTER is -- gpointer
517		external "C use <glib.h>"
518		end
519	
520	g_queue_pop_nth (a_queue: POINTER; a_guint_n: INTEGER): POINTER is -- gpointer
521			-- TODO: a_guint_n should be NATURAL
522		external "C use <glib.h>"
523		end
524	
525	g_queue_peek_head (a_queue: POINTER): POINTER is -- gpointer
526		external "C use <glib.h>"
527		end
528	
529	g_queue_peek_tail (a_queue: POINTER): POINTER is -- gpointer
530		external "C use <glib.h>"
531		end
532
533	g_queue_peek_nth (a_queue: POINTER; a_guint_n: INTEGER): POINTER is -- gpointer
534				-- TODO: a_guint_n should be NATURAL
535		external "C use <glib.h>"
536		end
537
538	g_queue_index (a_queue, const_data: POINTER): INTEGER is -- gint
539		external "C use <glib.h>"
540		end
541	
542	g_queue_remove (a_queue, const_data: POINTER) is
543		external "C use <glib.h>"
544		end
545	
546	g_queue_remove_all (a_queue, const_data: POINTER) is
547		external "C use <glib.h>"
548		end
549	
550	g_queue_insert_before (a_queue, a_glist_sibling, some_data: POINTER) is
551		external "C use <glib.h>"
552		end
553	
554	g_queue_insert_after (a_queue, a_glist_sibling, some_data: POINTER) is
555		external "C use <glib.h>"
556		end
557	
558	g_queue_insert_sorted (a_queue, data, a_g_compare_data_func, user_data: POINTER) is
559		external "C use <glib.h>"
560		end
561	
562	g_queue_push_head_link (a_queue, glist_link: POINTER) is
563		external "C use <glib.h>"
564		end
565	
566	g_queue_push_tail_link (a_queue, glist_link: POINTER) is
567		external "C use <glib.h>"
568		end
569	
570	g_queue_push_nth_link (a_queue: POINTER; an_index: INTEGER; glist_link: POINTER) is
571		external "C use <glib.h>"
572		end
573	
574	g_queue_pop_head_link (a_queue: POINTER): POINTER is -- GList*
575		external "C use <glib.h>"
576		end
577	
578	g_queue_pop_tail_link (a_queue: POINTER): POINTER is -- GList*
579		external "C use <glib.h>"
580		end
581	
582	g_queue_pop_nth_link (a_queue: POINTER; a_guint_n: INTEGER): POINTER is -- GList*
583			-- TODO: a_guint_n should be NATURAL
584		external "C use <glib.h>"
585		end
586
587	g_queue_peek_head_link (a_queue: POINTER): POINTER is -- GList*
588		external "C use <glib.h>"
589		end
590	
591	g_queue_peek_tail_link (a_queue: POINTER): POINTER is -- GList*
592		external "C use <glib.h>"
593		end
594	
595	g_queue_peek_nth_link (a_queue: POINTER; a_guint_n: INTEGER): POINTER is -- GList*
596			-- TODO: a_guint_n should be NATURAL
597		external "C use <glib.h>"
598		end
599	
600	g_queue_link_index (a_queue, glist_link: POINTER): INTEGER is -- gint
601		external "C use <glib.h>"
602		end
603
604	g_queue_unlink (a_queue, glist_link: POINTER) is
605		external "C use <glib.h>"
606		end
607	
608	g_queue_delete_link (a_queue, glist_link: POINTER) is
609		external "C use <glib.h>"
610		end
611end