/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

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