/tutorial/backtracking/logigram/var.e

http://github.com/tybor/Liberty · Specman e · 87 lines · 57 code · 12 blank · 18 comment · 2 complexity · 047844d540d72829258910d0e5637ad7 MD5 · raw file

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