PageRenderTime 29ms CodeModel.GetById 21ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/glib/library/data_types/g_list_traversable.e

http://github.com/tybor/Liberty
Specman e | 387 lines | 170 code | 79 blank | 138 comment | 11 complexity | 72f03cef204acf73f1aa7f04821b9713 MD5 | raw file
  1indexing
  2	description: "The G_LIST_TRAVERSABLE provides a standard singly-linked list data structure. Objects of this class may be in a frozen state. Therefore it cannot conform to the standard class COLLECTION. See also classes G_LIST and G_SLIST."
  3	copyright: "(C) 2006, 2008 Paolo Redaelli, Raphael Mack "
  4	license: "LGPL v2 or later"
  5	date: "$Date: 2008-11-30 00:48:25 +0100 (dom, 30 nov 2008) $"
  6	revision: "$Revision: 1101 $"
  7
  8deferred class G_LIST_TRAVERSABLE [ITEM->WRAPPER]
  9	-- A standard singly-linked list which may be "frozen", refusing further
 10	-- any changes until "thawed".
 11	
 12	-- Because of this feature it cannot conform to COLLECTION since the latter
 13	-- allows to be changed anytime throught its features. See also G_LIST and
 14	-- G_SLIST.  
 15
 16inherit
 17	WRAPPER
 18   
 19   TRAVERSABLE[ITEM]
 20      undefine
 21         copy
 22      redefine
 23         is_equal
 24      end
 25   
 26   WRAPPER_FACTORY[ITEM]
 27
 28insert
 29	GLIST_EXTERNALS
 30		undefine
 31			fill_tagged_out_memory
 32		end
 33	GLIST_STRUCT
 34
 35feature {WRAPPER, WRAPPER_HANDLER} -- object creation
 36	make is
 37		do
 38			-- There is no function to create a GList. NULL is considered
 39			-- to be the empty list so you simply set a GList* to NULL.
 40
 41			-- Note: a NULL pointer is the actual *valid* empty
 42			-- G_LIST. Therefore any handle.is_not_null postcondition
 43			-- shall be circumvented. 
 44
 45			-- Note that most of the GList functions expect to be passed
 46			-- a pointer to the first element in the list. The functions
 47			-- which insert elements return the new start of the list,
 48			-- which may have changed.
 49			handle := default_pointer
 50		end
 51   
 52feature {ANY} -- data access
 53	first: ITEM is
 54		local
 55         p: POINTER -- Item Pointer
 56		do
 57			p:=glist_struct_get_data (handle)
 58			if p.is_not_null 
 59				then Result:=wrapper(p) 
 60			end
 61		end
 62
 63	last: like first is
 64		local p: POINTER -- Item Pointer
 65		do
 66			p := glist_struct_get_data (g_list_last (handle))
 67			if p.is_not_null 
 68				then Result := wrapper(p) 
 69			end
 70		end
 71
 72	item (i: INTEGER): like first is
 73		local p: POINTER -- Item Pointer
 74		do
 75			p := g_list_nth_data (handle, i.to_natural_32)
 76			if p.is_not_null then 
 77				Result := wrapper(p) 
 78			end
 79		end
 80
 81	has (x: like first): BOOLEAN is
 82			-- Look for `x' using is_equal for comparison. 
 83		local i: ITERATOR[ITEM]; p: POINTER
 84		do
 85			if x/=Void then
 86				from i:=new_iterator; i.start until Result=True or else i.is_off
 87				loop 
 88					Result := x.is_equal(i.item)
 89					i.next
 90				end
 91			else
 92				from p:=handle 
 93				until p.is_null or else glist_struct_get_data(p).is_null
 94				loop
 95					p:=glist_struct_get_next(p)
 96				end
 97			end
 98
 99		end
100	
101	fast_has (x: like first): BOOLEAN is
102			-- Look for x using basic = for comparison.
103		do
104			if (g_list_find(handle,x.handle).is_not_null)
105			then Result:=True
106			else check Result=False end
107			end
108		end
109	
110	first_index_of (element: like first): INTEGER is
111			-- Give the index of the first occurrence of element using
112			-- is_equal for comparison. Answer upper + 1 when element is
113			-- not inside.
114		do
115			Result:=g_list_index(handle,element.handle)
116		end
117
118	index_of (element: like first; start_index: INTEGER): INTEGER is
119		do
120			Result:=first_index_of(element)
121		end
122
123	reverse_index_of (element: like first; start_index: INTEGER): INTEGER is do not_yet_implemented end
124
125	fast_first_index_of (element: like first): INTEGER is
126			-- Give the index of the first occurrence of element using
127			-- basic = for comparison. Answer upper + 1 when element is
128			-- not inside.
129		do
130			not_yet_implemented -- TODO
131		end
132
133	fast_index_of (element: like first; start_index: INTEGER): INTEGER is do not_yet_implemented end
134
135	fast_reverse_index_of (element: like first; start_index: INTEGER): INTEGER  is
136			-- Using basic = comparison, gives the index of the first
137			-- occurrence of element at or before start_index. Search is
138			-- done in reverse direction, which means from the
139			-- start_index down to the lower index . Answer lower -1 when
140			-- the search fail.
141		do
142			not_yet_implemented -- TODO
143		end
144
145	is_equal_map (other: like Current): BOOLEAN is
146			-- Do both collections have the same lower, upper, and items?
147		do
148			Result := is_equal(other)
149		end
150
151	is_equal (other: like Current): BOOLEAN is
152			-- Do both collections have the same lower, upper, and items?
153      local
154		  ci, oi: ITERATOR[ITEM]
155         i, j: INTEGER
156		do
157			if count = other.count and then
158				lower = other.lower then
159				check
160					upper = other.upper 
161					-- shall be implied by the previous two checks
162				end
163				from 
164					ci:=new_iterator; ci.start
165					oi:=new_iterator; oi.start
166				until not Result or else ci.is_off 
167				loop
168					Result := (ci.item = oi.item)
169					ci.next; oi.next
170				end
171			end
172		end
173
174	all_default: BOOLEAN is
175			--	Do all items have their type s default value? Note: for
176			--	non Void items, the test is performed with the is_default
177			--	predicate.
178		do
179			not_yet_implemented -- TODO
180		end
181
182	copy (other: like Current) is
183		--  make `Current' a "shallow" copy of `other'
184	do
185		if handle.is_not_null then
186			g_list_free (handle)
187		end
188		from_external_pointer (g_list_copy (other.handle))
189	end
190
191	occurrences (element: like first): INTEGER is
192			-- Number of occurrences of element using is_equal for comparison.
193		do
194			not_yet_implemented -- TODO
195		end
196
197	fast_occurrences (element: like first): INTEGER is
198		do
199			not_yet_implemented -- TODO
200		end
201	
202
203	slice (min, max: INTEGER): like Current is 
204		do
205			not_yet_implemented -- TODO
206		end
207
208	lower: INTEGER is 0
209
210	upper: INTEGER is
211		do
212			Result := count
213		end
214	
215	count: INTEGER is
216		do
217			Result := g_list_length(handle).to_integer_32
218		end
219
220	is_empty: BOOLEAN is
221		do
222			Result:= (handle.is_null)
223		end
224
225	from_collection (model: COLLECTION[ITEM]) is do not_yet_implemented end
226
227	new_iterator: ITERATOR[ITEM] is
228		do
229			create {ITERATOR_ON_G_LIST[ITEM]} Result.make (Current)
230		end
231	dispose is
232			-- Frees all of the memory used by a GList. The freed
233			-- elements are added to the GAllocator free list.
234		do
235			g_list_free (handle)
236			handle:= default_pointer
237		end
238
239-- g_list_free_1 ()
240
241-- void        g_list_free_1                  (GList *list);
242
243-- Frees one GList element. It is usually used after g_list_remove_link().
244-- list : 	a GList element.
245-- g_list_length ()
246
247-- guint       g_list_length                  (GList *list);
248
249-- Gets the number of elements in a GList.
250-- list : 	a GList.
251-- Returns : 	the number of elements in the GList.
252-- g_list_copy ()
253
254-- GList*     g_list_copy                    (GList *list);
255
256-- Copies a GList.
257
258-- Note that this is a "shallow" copy. If the list elements consist of pointers to data, the pointers are copied but the actual data isn't.
259-- list : 	a GList.
260-- Returns : 	a copy of list.
261-- g_list_reverse ()
262
263-- GList*     g_list_reverse                 (GList *list);
264
265-- Reverses a GList.
266-- list : 	a GList.
267-- Returns : 	the start of the reversed GList.
268-- g_list_sort ()
269
270-- GList*     g_list_sort                    (GList *list, GCompareFunc compare_func);
271
272-- Sorts a GList using the given comparison function.
273-- list : 	a GList.
274-- compare_func : 	the comparison function used to sort the GList. This function is passed the data from 2 elements of the GList and should return 0 if they are equal, a negative value if the first element comes before the second, or a positive value if the first element comes after the second.
275-- Returns : 	the start of the sorted GList.
276-- g_list_sort_with_data ()
277
278-- GList*     g_list_sort_with_data          (GList *list, GCompareDataFunc compare_func, gpointer user_data);
279
280-- Like g_list_sort(), but the sort function accepts a user data argument.
281-- list : 	a GList
282-- compare_func : 	comparison function.
283-- user_data : 	data to pass to comparison function.
284-- Returns : 	new head of the list.
285-- g_list_concat ()
286
287-- GList*     g_list_concat                  (GList *list1, GList *list2);
288
289-- Adds the second GList onto the end of the first GList. Note that the elements of the second GList are not copied. They are used directly.
290-- list1 : 	a GList.
291-- list2 : 	the GList to add to the end of the first GList.
292-- Returns : 	the start of the new GList.
293-- g_list_foreach ()
294
295-- void        g_list_foreach                 (GList *list, GFunc func, gpointer user_data);
296
297-- Calls a function for each element of a GList.
298-- list : 	a GList.
299-- func : 	the function to call with each element's data.
300-- user_data : 	user data to pass to the function.
301-- g_list_last ()
302
303-- GList*     g_list_last                    (GList *list);
304
305-- Gets the last element in a GList.
306-- list : 	a GList.
307-- Returns : 	the last element in the GList, or NULL if the GList has no elements.
308-- g_list_next()
309
310-- #define     g_list_next(slist)
311
312-- A convenience macro to gets the next element in a GList.
313-- slist : 	an element in a GList.
314-- Returns : 	the next element, or NULL if there are no more elements.
315-- g_list_nth ()
316
317-- GList*     g_list_nth                     (GList *list, guint n);
318
319-- Gets the element at the given position in a GList.
320-- list : 	a GList.
321-- n : 	the position of the element, counting from 0.
322-- Returns : 	the element, or NULL if the position is off the end of the GList.
323-- g_list_nth_data ()
324
325-- gpointer    g_list_nth_data                (GList *list, guint n);
326
327-- Gets the data of the element at the given position.
328-- list : 	a GList.
329-- n : 	the position of the element.
330-- Returns : 	the element's data, or NULL if the position is off the end of the GList.
331-- g_list_find ()
332
333-- GList*     g_list_find                    (GList *list, gconstpointer data);
334
335-- Finds the element in a GList which contains the given data.
336-- list : 	a GList.
337-- data : 	the element data to find.
338-- Returns : 	the found GList element, or NULL if it is not found.
339-- g_list_find_custom ()
340
341-- GList*     g_list_find_custom             (GList *list, gconstpointer data, GCompareFunc func);
342
343-- Finds an element in a GList, using a supplied function to find the desired element. It iterates over the list, calling the given function which should return 0 when the desired element is found. The function takes two gconstpointer arguments, the GList element's data as the first argument and the given user data.
344-- list : 	a GList.
345-- data : 	user data passed to the function.
346-- func : 	the function to call for each element. It should return 0 when the desired element is found.
347-- Returns : 	the found GList element, or NULL if it is not found.
348-- g_list_position ()
349
350-- gint        g_list_position                (GList *list, GList *llink);
351
352-- Gets the position of the given element in the GList (starting from 0).
353-- list : 	a GList.
354-- llink : 	an element in the GList.
355-- Returns : 	the position of the element in the GList, or -1 if the element is not found.
356-- g_list_index ()
357
358-- gint        g_list_index                   (GList *list, gconstpointer data);
359
360-- Gets the position of the element containing the given data (starting from 0).
361-- list : 	a GList.
362-- data : 	the data to find.
363-- Returns : 	the index of the element containing the data, or -1 if the data is not found.
364-- g_list_push_allocator ()
365
366-- void        g_list_push_allocator          (GAllocator *allocator);
367
368-- Sets the allocator to use to allocate GList elements. Use g_list_pop_allocator() to restore the previous allocator.
369
370-- Note that this function is not available if GLib has been compiled with --disable-mem-pools
371-- allocator : 	the GAllocator to use when allocating GList elements.
372-- g_list_pop_allocator ()
373
374-- void        g_list_pop_allocator           (void);
375
376-- Restores the previous GAllocator, used when allocating GList elements.
377
378-- Note that this function is not available if GLib has been compiled with --disable-mem-pools
379
380
381	manifest_put (an_index: INTEGER; element: like item) is
382		do
383			not_yet_implemented
384		end
385
386
387end