/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

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