/src/wrappers/common/library/iterator_on_c_array.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 57 code · 16 blank · 4 comment · 2 complexity · ec9dedb6ad77689ccb50118bafde6ba6 MD5 · raw file

  1. note
  2. description:
  3. "Iterator over a C_ARRAY."
  4. copyright:
  5. "[
  6. Copyright (C) 2007-2017: Paolo Redaelli
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public License
  9. as published by the Free Software Foundation; either version 2.1 of
  10. the License, or (at your option) any later version.
  11. This library is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. 02110-1301 USA
  19. ]"
  20. class ITERATOR_ON_C_ARRAY[ITEM_ -> C_STRUCT]
  21. -- TODO: this class is conceptually obsolete as it actually duplicates
  22. -- ITERATOR_ON_COLLECTION, or more precisely ITERATOR_ON_TRAVERSABLE. It
  23. -- could and should be easily removed
  24. inherit
  25. ITERATOR[ITEM_]
  26. create {ANY}
  27. from_array
  28. feature {} -- Creation and implementation
  29. from_array (an_array: C_ARRAY[ITEM_])
  30. require
  31. array_not_void: an_array /= Void
  32. do
  33. array := an_array
  34. end
  35. i: INTEGER -- Iterator index
  36. array: C_ARRAY[ITEM_]
  37. feature {ANY} --
  38. start
  39. do
  40. i := array.lower
  41. end
  42. is_off: BOOLEAN
  43. do
  44. Result := i > array.upper
  45. -- Result:=array.valid_index(i)
  46. end
  47. item: ITEM_
  48. do
  49. Result := array.item(i)
  50. end
  51. next
  52. do
  53. i := i + 1
  54. end
  55. feature {ANY}
  56. iterable_generation: INTEGER
  57. do
  58. Result := array.generation
  59. end
  60. generation: INTEGER
  61. end -- class ITERATOR_ON_C_ARRAY