note
	description: "External forward one-step iteration cursor for structures that use SPECIAL for storage."
	library: "EiffelBase: Library of reusable components for Eiffel."
	date: "$Date: 2016-04-13 13:29:38 +0000 (Wed, 13 Apr 2016) $"
	revision: "$Revision: 98619 $"

deferred class 
	GENERAL_SPECIAL_ITERATION_CURSOR [G, H -> READABLE_INDEXABLE [G]]

inherit
	TYPED_INDEXABLE_ITERATION_CURSOR [G, H]
		redefine
			item
		end

feature -- Access

	item: G
			-- Item at current cursor position.
		do
			Result := area [area_index]
		end

	cursor_index: INTEGER_32
			-- Index position of cursor in the iteration.
		do
			Result := area_index + 1 - area_first_index
		end

	target_index: INTEGER_32
			-- Index position of target structure for current iteration.
		do
			Result := area_index + first_index - area_first_index
		end

	last_index: INTEGER_32
			-- Last valid index of target structure for current iteration.
			-- Note that if Is_reversed, first_index might be greater than last_index.
		do
			Result := area_last_index + first_index - area_first_index
		end

	Step: INTEGER_32 = 1
			-- Distance between successive iteration elements.

	reversed alias "-": READABLE_INDEXABLE_ITERATION_CURSOR [G]
			-- Reversed cursor of the iteration.
		do
			create Result.make (target)
			Result.reverse
			Result.start
		end

	incremented alias "+" (n: like Step): READABLE_INDEXABLE_ITERATION_CURSOR [G]
			-- Cursor for the iteration with step increased by n.
		do
			create Result.make (target)
			Result.set_step (Step + n)
			Result.start
		end

	decremented alias "-" (n: like Step): READABLE_INDEXABLE_ITERATION_CURSOR [G]
			-- Cursor for the iteration with step decreased by n.
		do
			create Result.make (target)
			Result.set_step (Step - n)
			Result.start
		end

	with_step (n: like Step): READABLE_INDEXABLE_ITERATION_CURSOR [G]
			-- Cursor for the iteration with step set to n.
		do
			create Result.make (target)
			Result.set_step (n)
			Result.start
		end
	
feature -- Status report	

	after: BOOLEAN
			-- Are there no more items to iterate over?
		do
			Result := area_index > area_last_index
		end

	Is_reversed: BOOLEAN = False
			-- Are we traversing target structure backwards?

	is_valid: BOOLEAN
			-- Is the cursor still compatible with the associated underlying object?
		do
			Result := target.upper = last_index
		end

	is_first: BOOLEAN
			-- Is cursor at first position?
		do
			Result := area_index = area_first_index
		end

	is_last: BOOLEAN
			-- Is cursor at last position?
		do
			Result := area_index = area_last_index
		end
	
feature -- Cursor movement

	start
			-- Move to first position.
		do
			area_index := area_first_index
		end

	forth
			-- Move to next position.
		do
			area_index := area_index + 1
		end
	
feature {TYPED_INDEXABLE_ITERATION_CURSOR} -- Access

	area: SPECIAL [G]
			-- Associated storage used for iteration.
	
feature {NONE} -- Access

	area_index: INTEGER_32
			-- Index position in area for current iteration.

	area_first_index: INTEGER_32
			-- First valid index of area.
		deferred
		end

	area_last_index: INTEGER_32
			-- Last valid index of area.
	
note
	copyright: "Copyright (c) 1984-2016, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class GENERAL_SPECIAL_ITERATION_CURSOR

Generated by ISE EiffelStudio