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

http://github.com/tybor/Liberty · Specman e · 458 lines · 145 code · 108 blank · 205 comment · 7 complexity · 39d68193e998ae4d0e099cf48a618845 MD5 · raw file

  1. indexing
  2. description: "The GSList provides a standard singly-linked list data structure. See also G_SLIST, G_LIST"
  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_SLIST_TRAVERSABLE [ITEM->WRAPPER]
  8. -- A singly-linked list data structure.
  9. -- To add elements, use `add_last', `append', `add_first', `prepend',
  10. -- `add' and (TODO `insert_sorted').
  11. -- To remove elements, use `remove', `remove_first' and `remove_last'.
  12. -- To find elements in the list use `last', (TODO: `next'),
  13. -- `item', `fast_has' (PS: `has' calls `fast_has' in turn), `first_index_of'.
  14. -- To find the index of an element use TODO: g_slist_position() and
  15. -- g_slist_index().
  16. -- TODO: To call a function for each element in the list use
  17. -- g_slist_foreach().
  18. -- To free the entire list, use g_slist_free().
  19. inherit
  20. WRAPPER
  21. TRAVERSABLE[ITEM]
  22. undefine
  23. copy
  24. redefine
  25. is_equal
  26. end
  27. WRAPPER_FACTORY[ITEM]
  28. insert
  29. GSLIST_EXTERNALS
  30. undefine
  31. fill_tagged_out_memory
  32. end
  33. GSLIST_STRUCT
  34. feature
  35. -- At C level a NULL pointer is considered to be the empty list so
  36. -- you simply set a GSList* to NULL.
  37. -- Note that most of the low-level C GSList functions expect to be
  38. -- passed a pointer to the first element in the list. The functions
  39. -- which insert elements return the new start of the list, which
  40. -- may have changed.
  41. make, make_empty is
  42. do
  43. handle := default_pointer
  44. end
  45. first: ITEM is
  46. local p: POINTER -- Item Pointer
  47. do
  48. p:=gslist_struct_get_data (handle)
  49. if p.is_not_null then Result := wrapper(p) end
  50. end
  51. last: like first is
  52. local
  53. p: POINTER -- Item Pointer
  54. do
  55. p := gslist_struct_get_data (g_slist_last (handle))
  56. if p.is_not_null then
  57. 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_slist_nth_data (handle, i.to_natural_32)
  64. if p.is_not_null then Result:=wrapper(p) end
  65. end
  66. has (x: like first): BOOLEAN is
  67. -- Look for x using is_equal for comparison. Note: current
  68. -- implementation is just a copy of `fast_has'; try using
  69. -- `fast_has' whenever possible since an implementation of
  70. -- `has' that really uses `is_equal' will be quite slow.
  71. do
  72. Result:=fast_has(x)
  73. end
  74. fast_has (x: like first): BOOLEAN is
  75. -- Look for x using basic = for comparison.
  76. do
  77. if (g_slist_find(handle,x.handle).is_not_null)
  78. then Result:=True
  79. else check Result=False end
  80. end
  81. end
  82. first_index_of (element: like first): INTEGER is
  83. -- Give the an_index of the first occurrence of element using
  84. -- is_equal for comparison. Answer upper + 1 when element is
  85. -- not inside.
  86. do
  87. Result:=g_slist_index(handle,element.handle)
  88. end
  89. an_index_of (element: like first; start_index: INTEGER ): INTEGER is
  90. do
  91. Result:= g_slist_index(g_slist_nth(handle,start_index.to_natural_32),element.handle)
  92. end
  93. reverse_index_of (element: like first; start_index: INTEGER): INTEGER is do not_yet_implemented end
  94. fast_first_index_of (element: like first): INTEGER is
  95. -- Give the an_index of the first occurrence of element using
  96. -- basic = for comparison. Answer upper + 1 when element is
  97. -- not inside.
  98. do
  99. not_yet_implemented -- TODO
  100. end
  101. fast_index_of (element: like first; start_index: INTEGER): INTEGER is do not_yet_implemented end
  102. fast_reverse_index_of (element: like first; start_index: INTEGER): INTEGER is
  103. -- Using basic = comparison, gives the an_index of the first
  104. -- occurrence of element at or before start_index. Search is
  105. -- done in reverse direction, which means from the
  106. -- start_index down to the lower an_index . Answer lower -1 when
  107. -- the search fail.
  108. do
  109. not_yet_implemented -- TODO
  110. end
  111. is_equal_map (other: like Current): BOOLEAN is
  112. -- Do both collections have the same lower, upper, and items?
  113. do
  114. Result := is_equal(other)
  115. end
  116. is_equal (other: like Current): BOOLEAN is
  117. -- Do both collections have the same lower, upper, and items?
  118. local
  119. ci, oi: ITERATOR[ITEM]
  120. i, j: INTEGER
  121. do
  122. if count = other.count and then
  123. lower = other.lower then
  124. check
  125. upper = other.upper
  126. -- shall be implied by the previous two checks
  127. end
  128. from
  129. ci:=new_iterator; ci.start
  130. oi:=new_iterator; oi.start
  131. until not Result or else ci.is_off
  132. loop
  133. Result := (ci.item = oi.item)
  134. ci.next; oi.next
  135. end
  136. end
  137. end
  138. all_default: BOOLEAN is
  139. -- Do all items have their type s default value? Note: for
  140. -- non Void items, the test is performed with the is_default
  141. -- predicate.
  142. do
  143. not_yet_implemented -- TODO
  144. end
  145. copy (other: like Current) is
  146. do
  147. not_yet_implemented -- TODO
  148. end
  149. occurrences (element: like first): INTEGER is
  150. -- Number of occurrences of element using is_equal for comparison.
  151. do
  152. not_yet_implemented -- TODO
  153. end
  154. fast_occurrences (element: like first): INTEGER is
  155. do
  156. not_yet_implemented -- TODO
  157. end
  158. lower: INTEGER is 0
  159. upper: INTEGER is
  160. do
  161. Result:=count-1
  162. end
  163. count: INTEGER_32 is
  164. do
  165. Result:=g_slist_length(handle).to_integer_32
  166. -- ensure positive: Result >= 0
  167. end
  168. is_empty: BOOLEAN is
  169. do
  170. Result:= (handle.is_null)
  171. end
  172. new_iterator: ITERATOR[ITEM] is
  173. do
  174. create {ITERATOR_ON_G_SLIST[ITEM]} Result.make (Current)
  175. end
  176. feature {} -- Memory management
  177. dispose is
  178. do
  179. -- We override the default dispose routine; list nodes are not
  180. -- allocated with malloc() so we should not use free()
  181. g_slist_free (handle)
  182. handle:= default_pointer
  183. end
  184. -- Glib's doc, useful for implementing unimplemented
  185. -- typedef struct {
  186. -- gpointer data;
  187. -- GSList *next;
  188. -- } GSList;
  189. -- The GSList struct is used for each element in the singly-linked list.
  190. -- gpointer data; holds the element's data, which can be a pointer to any kind of data, or any integer value using the Type Conversion Macros.
  191. -- GSList *next; contains the link to the next element in the list.
  192. -- g_slist_alloc ()
  193. -- GSList* g_slist_alloc (void);
  194. -- Allocates space for one GSList element. It is called by the g_slist_append(), g_slist_prepend(), g_slist_insert() and g_slist_insert_sorted() functions and so is rarely used on its own.
  195. -- Returns : a pointer to the newly-allocated GSList element.
  196. -- g_slist_insert ()
  197. -- GSList* g_slist_insert (GSList *list, gpointer data, gint position);
  198. -- Inserts a new element into the list at the given position.
  199. -- list : a GSList.
  200. -- data : the data for the new element.
  201. -- position : the position to insert the element. If this is negative, or is larger than the number of elements in the list, the new element is added on to the end of the list.
  202. -- Returns : the new start of the GSList.
  203. -- g_slist_insert_before ()
  204. -- GSList* g_slist_insert_before (GSList *slist, GSList *sibling, gpointer data);
  205. -- Inserts a node before sibling containing data. Returns the new head of the list.
  206. -- slist : a GSList.
  207. -- sibling : node to insert data before.
  208. -- data : data to put in the newly-inserted node.
  209. -- Returns : new head of the list.
  210. -- g_slist_insert_sorted ()
  211. -- GSList* g_slist_insert_sorted (GSList *list, gpointer data, GCompareFunc func);
  212. -- Inserts a new element into the list, using the given comparison function to determine its position.
  213. -- list : a GSList.
  214. -- data : the data for the new element.
  215. -- func : the function to compare elements in the list. It should return a number > 0 if the first parameter comes after the second parameter in the sort order.
  216. -- Returns : the new start of the GSList.
  217. -- g_slist_remove ()
  218. -- GSList* g_slist_remove (GSList *list, gconstpointer data);
  219. -- Removes an element from a GSList. If two elements contain the same data, only the first is removed. If none of the elements contain the data, the GSList is unchanged.
  220. -- list : a GSList.
  221. -- data : the data of the element to remove.
  222. -- Returns : the new start of the GSList.
  223. -- g_slist_remove_link ()
  224. -- GSList* g_slist_remove_link (GSList *list, GSList *link_);
  225. -- Removes an element from a GSList, without freeing the element. The removed element's next link is set to NULL, so that it becomes a self-contained list with one element.
  226. -- list : a GSList.
  227. -- link_ : an element in the GSList.
  228. -- Returns : the new start of the GSList, without the element.
  229. -- g_slist_delete_link ()
  230. -- GSList* g_slist_delete_link (GSList *list, GSList *link_);
  231. -- Deletes a node of list. Returns the new list head.
  232. -- list : a GSList.
  233. -- link_ : node to delete.
  234. -- Returns : new head of list.
  235. -- g_slist_remove_all ()
  236. -- GSList* g_slist_remove_all (GSList *list, gconstpointer data);
  237. -- Removes all list nodes with data equal to data. Returns the new head of the list. Contrast with g_slist_remove() which removes only the first node matching the given data.
  238. -- list : a GSList.
  239. -- data : data to remove.
  240. -- Returns : new head of list.
  241. -- g_slist_free ()
  242. -- void g_slist_free (GSList *list);
  243. -- Frees all of the memory used by a GSList. The freed elements are added to the GAllocator free list.
  244. -- list : a GSList.
  245. -- g_slist_free_1 ()
  246. -- void g_slist_free_1 (GSList *list);
  247. -- Frees one GSList element. It is usually used after g_slist_remove_link().
  248. -- list : a GSList element.
  249. -- g_slist_length ()
  250. -- guint g_slist_length (GSList *list);
  251. -- Gets the number of elements in a GSList.
  252. -- list : a GSList.
  253. -- Returns : the number of elements in the GSList.
  254. -- g_slist_copy ()
  255. -- GSList* g_slist_copy (GSList *list);
  256. -- Copies a GSList.
  257. -- 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.
  258. -- list : a GSList.
  259. -- Returns : a copy of list.
  260. -- g_slist_reverse ()
  261. -- GSList* g_slist_reverse (GSList *list);
  262. -- Reverses a GSList.
  263. -- list : a GSList.
  264. -- Returns : the start of the reversed GSList.
  265. -- g_slist_sort ()
  266. -- GSList* g_slist_sort (GSList *list, GCompareFunc compare_func);
  267. -- Sorts a GSList using the given comparison function.
  268. -- list : a GSList.
  269. -- compare_func : the comparison function used to sort the GSList. This function is passed the data from 2 elements of the GSList 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.
  270. -- Returns : the start of the sorted GSList.
  271. -- g_slist_sort_with_data ()
  272. -- GSList* g_slist_sort_with_data (GSList *list, GCompareDataFunc compare_func, gpointer user_data);
  273. -- Like g_slist_sort(), but the sort function accepts a user data argument.
  274. -- list : a GSList
  275. -- compare_func : comparison function.
  276. -- user_data : data to pass to comparison function.
  277. -- Returns : new head of the list.
  278. -- g_slist_concat ()
  279. -- GSList* g_slist_concat (GSList *list1, GSList *list2);
  280. -- Adds the second GSList onto the end of the first GSList. Note that the elements of the second GSList are not copied. They are used directly.
  281. -- list1 : a GSList.
  282. -- list2 : the GSList to add to the end of the first GSList.
  283. -- Returns : the start of the new GSList.
  284. -- g_slist_foreach ()
  285. -- void g_slist_foreach (GSList *list, GFunc func, gpointer user_data);
  286. -- Calls a function for each element of a GSList.
  287. -- list : a GSList.
  288. -- func : the function to call with each element's data.
  289. -- user_data : user data to pass to the function.
  290. -- g_slist_last ()
  291. -- GSList* g_slist_last (GSList *list);
  292. -- Gets the last element in a GSList.
  293. -- list : a GSList.
  294. -- Returns : the last element in the GSList, or NULL if the GSList has no elements.
  295. -- g_slist_next()
  296. -- #define g_slist_next(slist)
  297. -- A convenience macro to gets the next element in a GSList.
  298. -- slist : an element in a GSList.
  299. -- Returns : the next element, or NULL if there are no more elements.
  300. -- g_slist_nth ()
  301. -- GSList* g_slist_nth (GSList *list, guint n);
  302. -- Gets the element at the given position in a GSList.
  303. -- list : a GSList.
  304. -- n : the position of the element, counting from 0.
  305. -- Returns : the element, or NULL if the position is off the end of the GSList.
  306. -- g_slist_nth_data ()
  307. -- gpointer g_slist_nth_data (GSList *list, guint n);
  308. -- Gets the data of the element at the given position.
  309. -- list : a GSList.
  310. -- n : the position of the element.
  311. -- Returns : the element's data, or NULL if the position is off the end of the GSList.
  312. -- g_slist_find ()
  313. -- GSList* g_slist_find (GSList *list, gconstpointer data);
  314. -- Finds the element in a GSList which contains the given data.
  315. -- list : a GSList.
  316. -- data : the element data to find.
  317. -- Returns : the found GSList element, or NULL if it is not found.
  318. -- g_slist_find_custom ()
  319. -- GSList* g_slist_find_custom (GSList *list, gconstpointer data, GCompareFunc func);
  320. -- Finds an element in a GSList, 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 GSList element's data as the first argument and the given user data.
  321. -- list : a GSList.
  322. -- data : user data passed to the function.
  323. -- func : the function to call for each element. It should return 0 when the desired element is found.
  324. -- Returns : the found GSList element, or NULL if it is not found.
  325. -- g_slist_position ()
  326. -- gint g_slist_position (GSList *list, GSList *llink);
  327. -- Gets the position of the given element in the GSList (starting from 0).
  328. -- list : a GSList.
  329. -- llink : an element in the GSList.
  330. -- Returns : the position of the element in the GSList, or -1 if the element is not found.
  331. -- g_slist_index ()
  332. -- gint g_slist_index (GSList *list, gconstpointer data);
  333. -- Gets the position of the element containing the given data (starting from 0).
  334. -- list : a GSList.
  335. -- data : the data to find.
  336. -- Returns : the an_index of the element containing the data, or -1 if the data is not found.
  337. -- g_slist_push_allocator ()
  338. -- void g_slist_push_allocator (GAllocator *allocator);
  339. -- Sets the allocator to use to allocate GSList elements. Use g_slist_pop_allocator() to restore the previous allocator.
  340. -- Note that this function is not available if GLib has been compiled with --disable-mem-pools
  341. -- allocator : the GAllocator to use when allocating GSList elements.
  342. -- g_slist_pop_allocator ()
  343. -- void g_slist_pop_allocator (void);
  344. -- Restores the previous GAllocator, used when allocating GSList elements.
  345. -- Note that this function is not available if GLib has been compiled with --disable-mem-pools
  346. manifest_put (an_index: INTEGER; element: like item) is
  347. do
  348. not_yet_implemented
  349. end
  350. end