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

http://github.com/tybor/Liberty · Specman e · 78 lines · 63 code · 12 blank · 3 comment · 2 complexity · b2f2e812bbbe07bdfae018183bc4e2d1 MD5 · raw file

  1. indexing
  2. description: "."
  3. copyright: "(C) 2006 Paolo Redaelli "
  4. license: "LGPL v2 or later"
  5. date: "$Date:$"
  6. revision: "$Revision:$"
  7. class ITERATOR_ON_G_LIST [ITEM->WRAPPER]
  8. inherit
  9. ITERATOR [ITEM]
  10. WRAPPER_HANDLER
  11. insert
  12. GLIST_EXTERNALS
  13. GLIST_STRUCT
  14. GLOBAL_CACHE
  15. creation make
  16. feature {} -- Creation
  17. make (a_list: G_LIST_TRAVERSABLE[ITEM]) is
  18. require
  19. valid_list: a_list /= Void
  20. do
  21. list := a_list
  22. end
  23. feature {} -- Implementation
  24. list: G_LIST_TRAVERSABLE[ITEM]
  25. current_element: POINTER
  26. feature -- Iterator's features
  27. start is
  28. do
  29. current_element := list.handle
  30. end
  31. is_off: BOOLEAN is
  32. do
  33. Result := (current_element.is_null)
  34. end
  35. item: ITEM is
  36. local
  37. ptr: POINTER
  38. l: WRAPPER
  39. do
  40. ptr := glist_struct_get_data (current_element)
  41. if ptr.is_not_null then
  42. l := wrappers.reference_at(ptr)
  43. Result ?= l -- TODO: this tricks the compiler. Combining the line just above and this one seems to fail
  44. if Result=Void
  45. then Result:=list.wrapper(ptr)
  46. end
  47. end
  48. end
  49. next is
  50. do
  51. current_element := glist_struct_get_next (current_element)
  52. end
  53. feature -- Bi-directional iterator features.
  54. is_at_first: BOOLEAN is
  55. -- Is Current iterator at the beginning of the G_LIST?
  56. do
  57. Result := (current_element = list.handle)
  58. end
  59. prev is
  60. require past_start: not is_at_first
  61. do
  62. current_element := glist_struct_get_prev (current_element)
  63. end
  64. --feature dispose is do -- Note: disposing an interator is a
  65. --no-operation. end
  66. end