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 CHAIN_INDEXABLE_ITERATOR [G] inherit READABLE_INDEXABLE [G] rename item as i_th alias "[]" end BILINEAR [G] FINITE [G] create make feature {NONE} -- Initialization make (a_target: CHAIN [G]) -- Initialization of Current using a_target as the data container. require a_target_not_void: a_target /= Void do target := a_target ensure target_not_void: target /= Void end feature {NONE} -- Implementation target: CHAIN [G] -- The CHAIN object containing the data feature -- Access item: G -- Item at current position do Result := target.item end i_th alias "[]" (i: INTEGER_32): G -- Entry at position i. do Result := target.at (i) end at alias "@" (i: INTEGER_32): G -- Entry at position i require i_valid: valid_index (i) do Result := i_th (i) end index: INTEGER_32 -- Index of current position do Result := target.index end feature -- Measurement lower: INTEGER_32 -- Minimum index. do Result := 1 end upper: INTEGER_32 -- Maximum index. do Result := count end count: INTEGER_32 -- Number of items do Result := target.count end feature -- Status report readable: BOOLEAN -- Is there a current item that may be read? do Result := target.readable end valid_index (i: INTEGER_32): BOOLEAN -- Is i a valid index? do Result := (i >= 1) and (i <= count) end after: BOOLEAN -- Is there no valid position to the right of current one? do Result := target.after end before: BOOLEAN -- Is there no valid position to the left of current one? do Result := target.before end full: BOOLEAN -- Is structure filled to capacity? do Result := target.full end valid_cursor_index (i: INTEGER_32): BOOLEAN -- Is i correctly bounded for cursor movement? do Result := target.valid_cursor_index (i) ensure valid_cursor_index_definition: Result = ((i >= 0) and (i <= count + 1)) end feature -- Cursor movement start -- Move to first position if any. do target.start end finish -- Move to last position. do target.finish end forth -- Move to next position; if no next position, -- ensure that exhausted will be true. do target.forth end back -- Move to previous position. do target.back end move (i: INTEGER_32) -- Move cursor i positions. The cursor -- may end up off if the absolute value of i -- is too big. do target.move (i) 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) end go_i_th (i: INTEGER_32) -- Move cursor to i-th position. require valid_cursor_index: valid_cursor_index (i) do target.go_i_th (i) ensure position_expected: target.index = i end 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