PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/tybor/Liberty
Specman e | 183 lines | 129 code | 29 blank | 25 comment | 0 complexity | 8c14c4be4403e72233da37e08311dda6 MD5 | raw file
  1indexing
  2	description: "The GSList provides a standard singly-linked list data %
  3   %structure. See also G_SLIST_TRAVERSABLE."
  4	copyright: "2008 Raphael Mack, 2010 Paolo Redaelli"
  5	license: "LGPL v2 or later"
  6	date: "$Date:$"
  7	revision: "$Revision:$"
  8
  9deferred class G_SLIST [ITEM->WRAPPER]
 10 
 11	-- Some GLib-using libraries requires that some instances of
 12	-- GList shall be modified only by the library, making it
 13	-- effectively freezed for the developer. In those cases
 14	-- G_LIST_TRAVERSABLE shall be used in place of G_LIST.  If the
 15	-- library allows its clients to change the lists it returns it
 16	-- will return a G_LIST.
 17   
 18inherit
 19	G_SLIST_TRAVERSABLE[ITEM]
 20		undefine
 21	  		out_in_tagged_out_memory, 
 22			fill_tagged_out_memory
 23		end
 24   
 25	COLLECTION[ITEM]
 26		undefine 
 27			has,
 28			fast_has,
 29			swap
 30		redefine
 31			append_collection,
 32			clear_all
 33		end
 34
 35feature
 36	put (an_item: like first; i: INTEGER) is
 37		require
 38			valid_item: an_item /= Void 
 39		do
 40			gslist_struct_set_data (g_slist_nth(handle,i.to_natural_32), an_item.handle)
 41		end
 42	
 43	slice (min, max: INTEGER): like Current is do not_yet_implemented end
 44
 45	swap (i,j: INTEGER) is
 46		local ith,jth,tmp: POINTER;
 47			in,jn: NATURAL_32
 48		do
 49			in := i.to_natural_32
 50			jn := j.to_natural_32
 51			ith := g_slist_nth_data (handle,in)
 52			jth := g_slist_nth_data (handle,jn)
 53
 54			tmp := gslist_struct_get_data(ith)
 55			gslist_struct_set_data (ith, gslist_struct_get_data(jth))
 56			gslist_struct_set_data (jth, tmp)
 57		end
 58
 59	set_all_with (v: like first) is
 60		local ith: POINTER
 61		do
 62			from ith := handle
 63			until ith.is_null
 64			loop
 65				gslist_struct_set_data (ith, v.handle)
 66				ith := gslist_struct_get_next (ith)
 67			end
 68		end
 69
 70	clear_all is do not_yet_implemented end
 71
 72	add_first (an_item: like first) is
 73			-- Adds `an_item' on to the start of the list.
 74		require 
 75			valid_item: an_item/=Void
 76		do
 77			handle := g_slist_prepend (handle, an_item.handle)
 78			-- Note: The return value is the new start of the list, which
 79			-- may have changed, so make sure you store the new value.
 80
 81			-- /* Notice that it is initialized to the empty list. */
 82			-- GSList *list = NULL; list = g_slist_prepend (list,
 83			-- "last"); list = g_slist_prepend (list, "first");
 84		end
 85
 86	add_last (an_item: like first) is
 87			-- Adds `an_item' on to the end of the list.  Note: this
 88			-- feature has to traverse the entire list to find the end,
 89			-- which is inefficient when adding multiple elements. A
 90			-- common idiom to avoid the inefficiency is to prepend the
 91			-- elements and reverse the list when all elements have been
 92			-- added.
 93		require
 94			valid_item: an_item/=Void
 95		do
 96			handle := g_slist_append (handle, an_item.handle)
 97
 98			-- Note: The return value is the new start of the list, which
 99			-- may have changed, so make sure you store the new value.
100		end
101
102	add (element: like first; an_index: INTEGER) is
103			-- Add `element' at `an_index`
104		require
105			element /= Void
106		do
107			handle := g_slist_insert (handle, element.handle, an_index)
108		end
109	
110	append_collection (other: COLLECTION[ITEM]) is
111			--
112		do
113			not_yet_implemented -- TODO
114		end
115
116	force (element: like first; an_index: INTEGER) is do not_yet_implemented end
117
118	remove_first is
119		do
120			handle := g_slist_delete_link (handle, handle)
121		end
122
123	remove (an_index: INTEGER) is
124		do
125			handle := g_slist_delete_link (handle, g_slist_nth_data (handle, an_index.to_natural_32))
126		end
127
128	remove_head (n: INTEGER) is
129		do
130			n.times(agent remove_first)
131		end
132
133	remove_tail (n: INTEGER) is
134		do
135			reverse
136			remove_head(n)
137			reverse
138		end
139
140	remove_last is
141		do
142			handle:=g_slist_delete_link (handle,g_slist_last (handle))
143		end
144
145	clear_count, clear_count_and_capacity is
146			-- Discard all items (is_empty is True after that call). Frees
147			-- all of the memory used by a GSList. The freed elements are
148			-- added to the GAllocator free list.
149		do
150			g_slist_free (handle)
151			handle := default_pointer 
152		end
153
154
155	replace_all (old_value, new_value: like first) is 
156		do
157			not_yet_implemented -- TODO
158		end
159
160	fast_replace_all (old_value, new_value: like first) is 
161		do
162			not_yet_implemented -- TODO
163		end
164
165	reverse is
166		local old_handle: POINTER
167		do
168			old_handle := handle
169			handle:=g_slist_reverse (handle)
170			g_slist_free (handle) -- TODO is this call correct?
171		end
172
173	from_collection (model: COLLECTION[ITEM]) is
174		local i: ITERATOR[ITEM]
175		do
176			from i:=model.new_iterator; i.start
177			until not i.is_off
178			loop add_first(i.item); i.next
179			end
180			reverse
181		end
182	
183end