/tutorial/backtracking/logigram/item_var.e

http://github.com/tybor/Liberty · Specman e · 81 lines · 52 code · 11 blank · 18 comment · 2 complexity · a27222df5e20d36ac0dfdf89d946f0ae MD5 · raw file

  1. -- See the Copyright notice at the end of this file.
  2. --
  3. class ITEM_VAR
  4. inherit
  5. ITEM
  6. creation {ANY}
  7. make
  8. feature {ANY}
  9. item: ITEM
  10. index: INTEGER is
  11. do
  12. Result := item.index
  13. end
  14. to_integer: INTEGER is
  15. do
  16. Result := item.to_integer
  17. end
  18. make (the_group: like group; the_name: like name) is
  19. do
  20. group := the_group
  21. name := the_name
  22. end
  23. start is
  24. do
  25. if group.item_count = 0 then
  26. item := Void
  27. else
  28. goto_index(0)
  29. end
  30. end
  31. is_off: BOOLEAN is
  32. do
  33. Result := item = Void
  34. ensure
  35. Result = (item = Void)
  36. end
  37. next is
  38. do
  39. if item.index + 1 < group.item_count then
  40. goto_index(item.index + 1)
  41. else
  42. item := Void
  43. end
  44. end
  45. goto_index (idx: INTEGER) is
  46. require
  47. idx.in_range(0, group.item_count - 1)
  48. do
  49. group.goto_index(idx)
  50. item := group.item
  51. ensure
  52. not is_off
  53. end
  54. end -- class ITEM_VAR
  55. --
  56. -- ------------------------------------------------------------------------------------------------------------------------------
  57. -- Copyright notice below. Please read.
  58. --
  59. -- This file is free software, which comes along with SmartEiffel. This software is distributed in the hope that it will be
  60. -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  61. -- You can modify it as you want, provided this footer is kept unaltered, and a notification of the changes is added.
  62. -- You are allowed to redistribute it and sell it, alone or as a part of another product.
  63. --
  64. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  65. -- Copyright(C) 2003-2005: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  66. --
  67. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  68. --
  69. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  70. -- ------------------------------------------------------------------------------------------------------------------------------