indexing
description: "Objects that are able to iterate over two-way chains, on which they can perform repeated actions and tests according to a number of predefined control structures such as ``if%'%', ``until%'%' and others."
names: iterators, iteration, two_way_chain_iterators, two_way_chain_iteration
traversal: sequential
exploration: forward, backward
class interface
TWO_WAY_CHAIN_ITERATOR [G]
feature -- Access
target: CHAIN [G]
feature -- Status report
invariant_value: BOOLEAN
-- Is the invariant satisfied?
-- (Redefinitions of this feature will usually involve
-- target; if so, make sure that the result is defined
-- when target = Void.)
-- (from ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
item_test (v: G): BOOLEAN
-- Test to be applied to item v
-- (default: false)
-- (from ITERATOR)
test: BOOLEAN
-- Test to be applied to item at current position in target
-- (default: value of item_test on item)
-- (from ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void;
not_off: not target.off
ensure -- from ITERATOR
not_off: not target.off
feature -- Status setting
set (s: like target)
-- Make s the new target of iterations.
-- (from ITERATOR)
require -- from ITERATOR
s /= void
ensure -- from ITERATOR
target = s;
target /= void
feature -- Cursor movement
back
-- Move cursor of target backward one position.
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
continue_for_back (n, k: INTEGER)
-- Apply action to every k-th item,
-- n times if possible.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
valid_repetition: n >= 0;
valid_skip: k >= 1
continue_for (n, k: INTEGER)
-- Apply action to every k-th item,
-- n times if possible.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
valid_repetition: n >= 0;
valid_skip: k >= 1
continue_search_back (b: BOOLEAN)
-- Search the first item of target
-- satisfying: test equals to b
-- (from the current position of target).
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
found: not exhausted = (b = test)
continue_search (b: BOOLEAN)
-- Search the first item of target
-- satisfying: test equals to b
-- (from the current position of target).
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
found: not exhausted = (b = test)
continue_until_back
-- Apply action to every item of target up to
-- and including first one satisfying test.
-- (from the current position of target).
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure then -- from LINEAR_ITERATOR
achieved: not exhausted implies test
continue_until
-- Apply action to every item of target up to
-- and including first one satisfying test.
-- (from the current position of target).
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure then -- from LINEAR_ITERATOR
achieved: not exhausted implies test
continue_while_back
-- Apply action to every item of target up to
-- and including first one not satisfying test
-- (from the current position of target).
-- (from LINEAR_ITERATOR)
require else -- from LINEAR_ITERATOR
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure then -- from LINEAR_ITERATOR
finished: not exhausted implies not test
continue_while
-- Apply action to every item of target up to
-- and including first one not satisfying test
-- (from the current position of target).
-- (from LINEAR_ITERATOR)
require else -- from LINEAR_ITERATOR
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure then -- from LINEAR_ITERATOR
finished: not exhausted implies not test
do_all_back
-- Apply action to every item of target.
-- (from the start of target)
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
exhausted
do_all
-- Apply action to every item of target.
-- (from the start of target)
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
exhausted
do_for_back (i, n, k: INTEGER)
-- Apply action to every k-th item,
-- n times if possible, starting from i-th.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
valid_start: i >= 1;
valid_repetition: n >= 0;
valid_skip: k >= 1
do_for (i, n, k: INTEGER)
-- Apply action to every k-th item,
-- n times if possible, starting from i-th.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
valid_start: i >= 1;
valid_repetition: n >= 0;
valid_skip: k >= 1
do_if
-- Apply action to every item of target
-- satisfying test.
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
do_if_back
-- Apply action to every item of target
-- satisfying test.
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
do_until_back
-- Apply action to every item of target up to
-- and including first one satisfying test.
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
achieved: not exhausted implies test
do_until
-- Apply action to every item of target up to
-- and including first one satisfying test.
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
achieved: not exhausted implies test
do_while_back
-- Apply action to every item of target up to
-- and including first one not satisfying test.
-- (from the start of target)
-- (from LINEAR_ITERATOR)
ensure then -- from LINEAR_ITERATOR
finished: not exhausted implies not test
do_while
-- Apply action to every item of target up to
-- and including first one not satisfying test.
-- (from the start of target)
-- (from LINEAR_ITERATOR)
ensure then -- from LINEAR_ITERATOR
finished: not exhausted implies not test
exhausted: BOOLEAN
-- Is target exhausted?
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
exists_back: BOOLEAN
-- Does test return true for
-- at least one item of target?
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
exists: BOOLEAN
-- Does test return true for
-- at least one item of target?
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
finish
-- Move cursor of target to last position.
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
forall: BOOLEAN
-- Does test return true for
-- all items of target?
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
forall_back: BOOLEAN
-- Does test return true for
-- all items of target?
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
forth
-- Move to next position of target.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
off: BOOLEAN
-- Is position of target off?
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
search (b: BOOLEAN)
-- Search the first item of target for which test
-- has the same value as b (both true or both false).
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
search_back (b: BOOLEAN)
-- Search the first item of target for which test
-- has the same value as b (both true or both false).
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
start
-- Move to first position of target.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void
until_continue
-- Apply action to every item of target from current
-- position, up to but excluding first one satisfying test.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure -- from LINEAR_ITERATOR
achieved: exhausted or else test;
invariant_satisfied: invariant_value
until_continue_back
-- Apply action to every item of target from current
-- position, up to but excluding first one satisfying test.
-- (from LINEAR_ITERATOR)
require -- from LINEAR_ITERATOR
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure -- from LINEAR_ITERATOR
achieved: exhausted or else test;
invariant_satisfied: invariant_value
until_do
-- Apply action to every item of target up to
-- but excluding first one satisfying test.
-- (Apply to full list if no item satisfies test.)
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
achieved: not exhausted implies test
until_do_back
-- Apply action to every item of target up to
-- but excluding first one satisfying test.
-- (Apply to full list if no item satisfies test.)
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
achieved: not exhausted implies test
while_continue
-- Apply action to every item of target up to
-- but excluding first one not satisfying test.
-- (from LINEAR_ITERATOR)
ensure -- from LINEAR_ITERATOR
finished: not exhausted implies not test
while_continue_back
-- Apply action to every item of target up to
-- but excluding first one not satisfying test.
-- (from LINEAR_ITERATOR)
ensure -- from LINEAR_ITERATOR
finished: not exhausted implies not test
while_do
-- Apply action to every item of target up to
-- but excluding first one not satisfying test.
-- (Apply to full list if all items satisfy test.)
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
finished: not exhausted implies not test
while_do_back
-- Apply action to every item of target up to
-- but excluding first one not satisfying test.
-- (Apply to full list if all items satisfy test.)
-- (from LINEAR_ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void
ensure then -- from LINEAR_ITERATOR
finished: not exhausted implies not test
feature -- Element change
action
-- Action to be applied to item at current position
-- in target (default: item_action on that item).
-- For iterators to work properly, redefined versions of
-- this feature should not change the traversable's
-- structure.
-- (from ITERATOR)
require -- from ITERATOR
traversable_exists: target /= void;
not_off: not target.off;
invariant_satisfied: invariant_value
ensure -- from ITERATOR
not_off: not target.off;
invariant_satisfied: invariant_value
item_action (v: G)
-- Action to be applied to item v
-- (Default: do nothing.)
-- (from ITERATOR)
invariant
-- from GENERAL
reflexive_equality: standard_is_equal (Current);
reflexive_conformance: conforms_to (Current);
end -- class TWO_WAY_CHAIN_ITERATOR