note
	description: "[
		Objects that are able to iterate over a CHAIN structures (forward and backward) 
		and the content can be addressed with integers key.
		Can be use to access a CHAIN in read only.
	]"
	author: "Louis Marchand"
	date: "July 23, 2014"
	revision: "1.0.1.1"

class interface
	CHAIN_INDEXABLE_ITERATOR [G]

create 
	make

feature -- Access

	item: G
			-- Item at current position

	i_th alias "[]" (i: INTEGER_32): G
			-- Entry at position i.

	at alias "@" (i: INTEGER_32): G
			-- Entry at position i
		require
			i_valid: valid_index (i)

	index: INTEGER_32
			-- Index of current position
	
feature -- Measurement

	lower: INTEGER_32
			-- Minimum index.

	upper: INTEGER_32
			-- Maximum index.

	count: INTEGER_32
			-- Number of items
	
feature -- Status report

	readable: BOOLEAN
			-- Is there a current item that may be read?

	valid_index (i: INTEGER_32): BOOLEAN
			-- Is i a valid index?

	after: BOOLEAN
			-- Is there no valid position to the right of current one?

	before: BOOLEAN
			-- Is there no valid position to the left of current one?

	full: BOOLEAN
			-- Is structure filled to capacity?

	valid_cursor_index (i: INTEGER_32): BOOLEAN
			-- Is i correctly bounded for cursor movement?
		ensure
			valid_cursor_index_definition: Result = ((i >= 0) and (i <= count + 1))
	
feature -- Cursor movement

	start
			-- Move to first position if any.

	finish
			-- Move to last position.

	forth
			-- Move to next position; if no next position,
			-- ensure that exhausted will be true.

	back
			-- Move to previous position.

	move (i: INTEGER_32)
			-- Move cursor i positions. The cursor
			-- may end up off if the absolute value of i
			-- is too big.
		ensure
			too_far_right: (old index + i > count) implies exhausted
			too_far_left: (old index + i < 1) implies exhausted
			expected_index: (not exhausted) implies (index = old index + i)

	go_i_th (i: INTEGER_32)
			-- Move cursor to i-th position.
		require
			valid_cursor_index: valid_cursor_index (i)
		ensure
			position_expected: target.index = i
	
invariant
	target_not_void: target /= Void

note
	copyright: "Copyright (c) 2014, Louis Marchand"
	license: "MIT License (see http://opensource.org/licenses/MIT)"

end -- class CHAIN_INDEXABLE_ITERATOR

Generated by ISE EiffelStudio