/src/lib/backtracking/low_level/abstract_backtracking_alternative.e

http://github.com/tybor/Liberty · Specman e · 93 lines · 31 code · 8 blank · 54 comment · 0 complexity · 1c796ac2ca0f48ea093fdc12baaca7ec MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class ABSTRACT_BACKTRACKING_ALTERNATIVE
  5. --
  6. -- Abstract realisation of an alternative iterator
  7. -- for the ABSTRACT_BACKTRACKING
  8. --
  9. -- The ABSTRACT_BACKTRACKING uses the fields
  10. -- continuation and top_sequence to record its
  11. -- exploration state and calls the feature
  12. -- 'next_alternative' to let the current object
  13. -- choose how to continue the exploration.
  14. --
  15. inherit
  16. ABSTRACT_BACKTRACKING_POOLABLE
  17. rename pool_link as previous,
  18. set_pool_link as set_previous
  19. export {ABSTRACT_BACKTRACKING_POOL, ABSTRACT_BACKTRACKING} set_previous
  20. redefine previous
  21. end
  22. feature {ABSTRACT_BACKTRACKING_POOL, ABSTRACT_BACKTRACKING}
  23. previous: ABSTRACT_BACKTRACKING_ALTERNATIVE
  24. -- For the linked stack of alternatives.
  25. -- Managed by ABSTRACT_BACKTRACKING.
  26. feature {ABSTRACT_BACKTRACKING}
  27. continuation: ABSTRACT_BACKTRACKING_SEQUENCE
  28. -- The sequence to continue after a success in
  29. -- exploration of the current alternative.
  30. -- Managed by ABSTRACT_BACKTRACKING.
  31. set_continuation (value: like continuation)
  32. do
  33. continuation := value
  34. ensure
  35. definition: continuation = value
  36. end
  37. top_sequence: like continuation
  38. -- Record of the top of the stack of sequence
  39. -- to restore the state of the exploration after
  40. -- that all alternatives were explored.
  41. -- Managed by ABSTRACT_BACKTRACKING.
  42. set_top_sequence (value: like top_sequence)
  43. do
  44. top_sequence := value
  45. ensure
  46. definition: top_sequence = value
  47. end
  48. next_alternative (explorer: ABSTRACT_BACKTRACKING)
  49. -- Called by ABSTRACT_BACKTRACKING to let
  50. -- the current object switch to the next alternative
  51. -- to explore.
  52. -- Two actions must be performed by that feature:
  53. -- - make iteration actions and then call
  54. -- 'continue_alternative' if iteration is not ended
  55. -- and that current object must be called again to
  56. -- switch to an other alternative or else call
  57. -- 'pop_alternative' if this is the last alternative
  58. -- to be explored.
  59. -- - select the state to be evaluated or
  60. -- call 'continue' or call 'backtrack'.
  61. require
  62. is_on_top: Current = explorer.top_alternative
  63. deferred
  64. end
  65. end -- class ABSTRACT_BACKTRACKING_ALTERNATIVE
  66. --
  67. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  68. --
  69. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  70. -- of this software and associated documentation files (the "Software"), to deal
  71. -- in the Software without restriction, including without limitation the rights
  72. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  73. -- copies of the Software, and to permit persons to whom the Software is
  74. -- furnished to do so, subject to the following conditions:
  75. --
  76. -- The above copyright notice and this permission notice shall be included in
  77. -- all copies or substantial portions of the Software.
  78. --
  79. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  80. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  81. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  82. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  83. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  84. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  85. -- THE SOFTWARE.