/src/lib/iterator/internal/iterator_on_traversable.e

http://github.com/tybor/Liberty · Specman e · 80 lines · 42 code · 12 blank · 26 comment · 0 complexity · 34b38c3ada5fd4fbaf38674118cb6aed MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class ITERATOR_ON_TRAVERSABLE[E_]
  5. -- Please do not use this class directly. Look at `ITERATOR'.
  6. inherit
  7. ITERATOR[E_]
  8. create {ANY}
  9. make
  10. feature {}
  11. traversable: TRAVERSABLE[E_]
  12. -- The one to be traversed.
  13. item_index: INTEGER
  14. -- Memorize the current position.
  15. feature {ANY}
  16. make (t: like traversable)
  17. require
  18. t /= Void
  19. do
  20. traversable := t
  21. start
  22. ensure
  23. traversable = t
  24. end
  25. start
  26. do
  27. item_index := traversable.lower
  28. generation := iterable_generation
  29. end
  30. is_off: BOOLEAN
  31. do
  32. Result := not traversable.valid_index(item_index)
  33. end
  34. item: E_
  35. do
  36. Result := traversable.item(item_index)
  37. end
  38. next
  39. do
  40. item_index := item_index + 1
  41. end
  42. feature {ANY}
  43. iterable_generation: INTEGER
  44. do
  45. Result := traversable.generation
  46. end
  47. generation: INTEGER
  48. end -- class ITERATOR_ON_TRAVERSABLE
  49. --
  50. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  51. --
  52. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  53. -- of this software and associated documentation files (the "Software"), to deal
  54. -- in the Software without restriction, including without limitation the rights
  55. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  56. -- copies of the Software, and to permit persons to whom the Software is
  57. -- furnished to do so, subject to the following conditions:
  58. --
  59. -- The above copyright notice and this permission notice shall be included in
  60. -- all copies or substantial portions of the Software.
  61. --
  62. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  63. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  64. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  65. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  66. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  67. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  68. -- THE SOFTWARE.