PageRenderTime 20ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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