Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Objects that are able to iterate over linear structures" status: "See notice at end of class" names: iterators, iteration, linear_iterators, linear_iteration date: "$Date: 2001-11-16 20:32:23 +0000 (Fri, 16 Nov 2001) $" revision: "$Revision: 51435 $" class LINEAR_ITERATOR [G] create set feature -- Initialization set (s: like target) is -- Make s the new target of iterations. require -- from ITERATOR target_exists: s /= void do Precursor (s) create internal_item_tuple.make ensure -- from ITERATOR target = s target /= void end feature -- Access item: G is -- The item at cursor position in target require traversable_exists: target /= void do Result := target.item end item_tuple: TUPLE [G] is -- Tuple containing a single element, -- the item at cursor position in target'' do internal_item_tuple.put (target.item, 1) Result := internal_item_tuple end target: LINEAR [G] -- The structure to which iteration features will apply. feature -- Status report invariant_value: BOOLEAN is -- 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) do Result := True end feature -- Cursor movement exhausted: BOOLEAN is -- Is target exhausted? do Result := target.exhausted end forth is -- Move to next position of target. do target.forth end off: BOOLEAN is -- Is position of target off? do Result := target.off end start is -- Move to first position of target. do target.start end feature -- Implementation internal_item_tuple: TUPLE [G] -- Field holding the last item of target feature -- Iteration continue_for (action: PROCEDURE [ANY, TUPLE [G]]; n, k: INTEGER) is -- Apply action to every k-th item, -- n times if possible. require valid_repetition: n >= 0 valid_skip: k >= 1 local i, j: INTEGER do from invariant i >= 0 and i <= n variant n - i until exhausted or else i = n loop action.call (item_tuple) i := i + 1 from j := 0 invariant j >= 0 and j <= k variant k - j until exhausted or else j = k loop forth j := j + 1 end end end continue_search (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]; b: BOOLEAN) is -- Search the first item of target -- satisfying: test equals to b -- (from the current position of target). do from invariant invariant_value until exhausted or else (b = test.item (item_tuple)) loop forth end ensure then found: not exhausted = (b = test.item (item_tuple)) end continue_until (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target up to -- and including first one satisfying test. -- (from the current position of target). require invariant_satisfied: invariant_value do from if not exhausted then action.call (item_tuple) end invariant invariant_value until exhausted or else test.item (item_tuple) loop forth if not exhausted then action.call (item_tuple) end end ensure then achieved: not exhausted implies test.item (item_tuple) end continue_while (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target up to -- and including first one not satisfying test -- (from the current position of target). require else invariant_satisfied: invariant_value do from if not exhausted then action.call (item_tuple) end invariant invariant_value until exhausted or else not test.item (item_tuple) loop forth if not exhausted then action.call (item_tuple) end end ensure then finished: not exhausted implies not test.item (item_tuple) end do_all (action: PROCEDURE [ANY, TUPLE [G]]) is -- Apply action to every item of target. -- (from ITERATOR) require -- from ITERATOR action_exists: action /= void do target.do_all (action) end do_for (action: PROCEDURE [ANY, TUPLE [G]]; i, n, k: INTEGER) is -- Apply action to every k-th item, -- n times if possible, starting from i-th. require valid_start: i >= 1 valid_repetition: n >= 0 valid_skip: k >= 1 local j: INTEGER do from start j := 1 invariant j >= 1 and j <= i variant i - j until exhausted or else j = i loop forth j := j + 1 end continue_for (action, n, k) end do_if (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target satisfying test. -- (from ITERATOR) require -- from ITERATOR action_exists: action /= void test_exists: test /= void do target.do_if (action, test) end do_until (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target up to -- and including first one satisfying test. require -- from ITERATOR action_exists: action /= void test_exists: test /= void do start continue_until (action, test) ensure then achieved: not exhausted implies test.item (item_tuple) end do_while (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target up to -- and including first one not satisfying test. -- (from the start of target) require -- from ITERATOR action_exists: action /= void test_exists: test /= void do start continue_while (action, test) ensure then finished: not exhausted implies not test.item (item_tuple) end for_all (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN is -- Does test return true for -- all items of target? require -- from ITERATOR test_exists: test /= void do search (test, False) Result := exhausted end search (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]; b: BOOLEAN) is -- Search the first item of target for which test -- has the same value as b (both true or both false). do start continue_search (test, b) end there_exists (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN is -- Does test return true for -- at least one item of target? require -- from ITERATOR test_exists: test /= void do search (test, True) Result := not exhausted end until_continue (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target from current -- position, up to but excluding first one satisfying test. require invariant_satisfied: invariant_value do from invariant invariant_value until exhausted or else test.item (item_tuple) loop action.call ([item]) forth end ensure achieved: exhausted or else test.item (item_tuple) invariant_satisfied: invariant_value end until_do (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- 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 action_exists: action /= void test_exists: test /= void do start until_continue (action, test) ensure then achieved: not exhausted implies test.item (item_tuple) end while_continue (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item of target up to -- but excluding first one not satisfying test. do from invariant invariant_value until exhausted or else not test.item (item_tuple) loop action.call (item_tuple) forth end ensure finished: not exhausted implies not test.item (item_tuple) end while_do (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- 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 action_exists: action /= void test_exists: test /= void do start while_continue (action, test) ensure then finished: not exhausted implies not test.item (item_tuple) end invariant target_exists: target /= void item_tuple_exists: item_tuple /= void internal_item_tuple_exists: internal_item_tuple /= void -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) -- from ITERATOR traversable_exists: target /= void end -- class LINEAR_ITERATOR
Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:

-- Generated by ISE Eiffel --
For more details: www.eiffel.com