/tutorial/backtracking/logigram/item_collector.e

http://github.com/tybor/Liberty · Specman e · 83 lines · 48 code · 9 blank · 26 comment · 1 complexity · 4138077cbc9769fdd3a7637d47100ae5 MD5 · raw file

  1. -- See the Copyright notice at the end of this file.
  2. --
  3. class ITEM_COLLECTOR
  4. --
  5. -- collector of items in the constraints
  6. --
  7. creation {ANY}
  8. make
  9. feature {ANY}
  10. item_set: HASHED_SET[ITEM_ITEM]
  11. -- the collected items
  12. var_set: HASHED_SET[ITEM_VAR]
  13. -- the collected vars
  14. make is
  15. do
  16. create item_set.with_capacity(10)
  17. create var_set.with_capacity(10)
  18. ensure
  19. not (has_item or has_var)
  20. end
  21. clear is
  22. do
  23. item_set.clear_count
  24. var_set.clear_count
  25. ensure
  26. not (has_item or has_var)
  27. end
  28. has_var: BOOLEAN is
  29. do
  30. Result := var_set.count > 0
  31. ensure
  32. Result = (var_set.count > 0)
  33. end
  34. has_item: BOOLEAN is
  35. do
  36. Result := item_set.count > 0
  37. ensure
  38. Result = (item_set.count > 0)
  39. end
  40. put (item: ITEM) is
  41. -- records the item in item_set or in var_set
  42. -- depending on the real type of item that can
  43. -- be ITEM_VAR or ITEM_ITEM
  44. local
  45. itm: ITEM_ITEM; var: ITEM_VAR
  46. do
  47. itm ?= item
  48. if itm /= Void then
  49. item_set.add(itm)
  50. else
  51. var ?= item
  52. check
  53. var /= Void
  54. end
  55. var_set.add(var)
  56. end
  57. end
  58. end -- class ITEM_COLLECTOR
  59. --
  60. -- ------------------------------------------------------------------------------------------------------------------------------
  61. -- Copyright notice below. Please read.
  62. --
  63. -- This file is free software, which comes along with SmartEiffel. This software is distributed in the hope that it will be
  64. -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  65. -- You can modify it as you want, provided this footer is kept unaltered, and a notification of the changes is added.
  66. -- You are allowed to redistribute it and sell it, alone or as a part of another product.
  67. --
  68. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  69. -- Copyright(C) 2003-2005: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  70. --
  71. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  72. --
  73. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  74. -- ------------------------------------------------------------------------------------------------------------------------------