/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

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