indexing
description: "Objects that are able to iterate over linear structures"
names: iterators, iteration, linear_iterators, linear_iteration
class interface
LINEAR_ITERATOR [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
continue_for (n, k: INTEGER)
-- Apply action to every k-th item,
-- n times if possible.
require
traversable_exists: target /= void;
valid_repetition: n >= 0;
valid_skip: k >= 1
continue_search (b: BOOLEAN)
-- Search the first item of target
-- satisfying: test equals to b
-- (from the current position of target).
require
traversable_exists: target /= void
ensure then
found: not exhausted = (b = test)
continue_until
-- Apply action to every item of target up to
-- and including first one satisfying test.
-- (from the current position of target).
require
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure then
achieved: not exhausted implies 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).
require else
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure then
finished: not exhausted implies not test
do_all
-- Apply action to every item of target.
-- (from the start of target)
require -- from ITERATOR
traversable_exists: target /= void
ensure then
exhausted
do_for (i, n, k: INTEGER)
-- Apply action to every k-th item,
-- n times if possible, starting from i-th.
require
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.
require -- from ITERATOR
traversable_exists: target /= void
do_until
-- Apply action to every item of target up to
-- and including first one satisfying test.
require -- from ITERATOR
traversable_exists: target /= void
ensure then
achieved: not exhausted implies test
do_while
-- Apply action to every item of target up to
-- and including first one not satisfying test.
-- (from the start of target)
ensure then
finished: not exhausted implies not test
exhausted: BOOLEAN
-- Is target exhausted?
require
traversable_exists: target /= void
exists: BOOLEAN
-- Does test return true for
-- at least one item of target?
require -- from ITERATOR
traversable_exists: target /= void
forall: BOOLEAN
-- Does test return true for
-- all items of target?
require -- from ITERATOR
traversable_exists: target /= void
forth
-- Move to next position of target.
require
traversable_exists: target /= void
off: BOOLEAN
-- Is position of target off?
require
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).
require
traversable_exists: target /= void
start
-- Move to first position of target.
require
traversable_exists: target /= void
target: LINEAR [G]
-- The structure to which iteration features will apply.
until_continue
-- Apply action to every item of target from current
-- position, up to but excluding first one satisfying test.
require
traversable_exists: target /= void;
invariant_satisfied: invariant_value
ensure
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.)
require -- from ITERATOR
traversable_exists: target /= void
ensure then
achieved: not exhausted implies test
while_continue
-- Apply action to every item of target up to
-- but excluding first one not satisfying test.
ensure
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.)
require -- from ITERATOR
traversable_exists: target /= void
ensure then
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 LINEAR_ITERATOR