    indexing
    	description: "Multi-dimensional array"
    	legal: "See notice at end of class."
    	status: "See notice at end of class."
    	representation: array
    	access: multi_dimensional_index
    	size: resizable
    	contents: generic
    	date: "$Date: 2006-01-22 18:25:44 -0800 (Sun, 22 Jan 2006) $"
    	revision: "$Revision: 56675 $"

    class interface
    	ECOM_ARRAY [G]

    create
    	make (a_dimension_count: INTEGER_32; some_lower_indices, some_element_counts: ARRAY [INTEGER_32])
    			-- Create `a_dimensional_count' dimensional array
    			-- with lower indices in each dimension as described by `some_lower_indices'
    			-- and element count in each dimension as described by `some_element_counts'.
    		require
    			valid_dimension_count: a_dimension_count >= 0
    			valid_lower_indices: some_lower_indices /= Void and then some_lower_indices.count = a_dimension_count and (a_dimension_count > 0 implies some_lower_indices.lower = 1)
    			valid_element_count: some_element_counts /= Void and then some_element_counts.count = a_dimension_count and (a_dimension_count > 0 implies some_element_counts.lower = 1) and then are_element_counts_valid (some_element_counts)
    		ensure
    			valid_dimension_count: dimension_count >= 0
    			valid_element_counts: element_counts /= Void and then element_counts.count = dimension_count
    			valid_lower_indices: lower_indices /= Void and then lower_indices.count = dimension_count
    			valid_upper_indices: upper_indices /= Void and then upper_indices.count = dimension_count

    	make_from_array (a: ARRAY [G]; a_dimension_count: INTEGER_32; some_lower_indices, some_element_counts: ARRAY [INTEGER_32])
    			-- Create `a_dimensional_count' dimensional array
    			-- with lower indices in each dimension as described by `some_lower_indices'
    			-- and element count in each dimension as described by `some_element_counts'.
    		require
    			valid_dimension_count: a_dimension_count >= 0
    			valid_lower_indices: some_lower_indices /= Void and then some_lower_indices.count = a_dimension_count and (a_dimension_count > 0 implies some_lower_indices.lower = 1)
    			valid_element_count: some_element_counts /= Void and then some_element_counts.count = a_dimension_count and (a_dimension_count > 0 implies some_element_counts.lower = 1) and then are_element_counts_valid (some_element_counts)
    			valid_array_size: a.count >= total_count (some_element_counts)
    		ensure
    			valid_dimension_count: dimension_count >= 0
    			valid_element_counts: element_counts /= Void and then element_counts.count = dimension_count
    			valid_lower_indices: lower_indices /= Void and then lower_indices.count = dimension_count
    			valid_upper_indices: upper_indices /= Void and then upper_indices.count = dimension_count

    	make_empty
    			-- Create empty array.

    feature -- Initialization

    	initialize (v: G)
    			-- Make each entry have value `v'

    feature -- Access

    	generating_type: STRING_8
    			-- Name of current object's generating type
    			-- (type of which it is a direct instance)
    			-- (from ANY)

    	generator: STRING_8
    			-- Name of current object's generating class
    			-- (base class of the type of which it is a direct instance)
    			-- (from ANY)

    	item (some_indices: ARRAY [INTEGER_32]): G
    			-- Entry at `some_indices'
    		require
    			valid_indices: are_indices_valid (some_indices)

    feature {ANY} -- Access

    	area: SPECIAL [G]
    			-- Special data zone
    			-- (from TO_SPECIAL)

    	item alias "[]" (i: INTEGER_32): G assign put
    			-- Entry at index `i', if in index interval
    			-- Was declared in ARRAY as synonym of infix "@".
    			-- (from ARRAY)
    		require -- from TABLE
    			valid_key: valid_index (i)
    		require -- from TO_SPECIAL
    			valid_index: valid_index (i)

    feature -- Measurement

    	dimension_count: INTEGER_32
    			-- Number of dimensions

    	element_counts: ARRAY [INTEGER_32]
    			-- Element count in each dimension

    	lower_indices: ARRAY [INTEGER_32]
    			-- Lower indedeces in each dimension

    	upper_indices: ARRAY [INTEGER_32]
    			-- Upper indices in each dimension

    feature {ANY} -- Measurement

    	count: INTEGER_32
    			-- Number of available indices
    			-- Was declared in ARRAY as synonym of capacity.
    			-- (from ARRAY)
    		require -- from  FINITE
    			True
    		ensure then -- from ARRAY
    			consistent_with_bounds: Result = upper - lower + 1

    feature -- Comparison

    	frozen deep_equal (some: ANY; other: like arg #1): BOOLEAN
    			-- Are `some' and `other' either both void
    			-- or attached to isomorphic object structures?
    			-- (from ANY)
    		ensure -- from ANY
    			shallow_implies_deep: standard_equal (some, other) implies Result
    			both_or_none_void: (some = Void) implies (Result = (other = Void))
    			same_type: (Result and (some /= Void)) implies some.same_type (other)
    			symmetric: Result implies deep_equal (other, some)

    	frozen equal (some: ANY; other: like arg #1): BOOLEAN
    			-- Are `some' and `other' either both void or attached
    			-- to objects considered equal?
    			-- (from ANY)
    		ensure -- from ANY
    			definition: Result = (some = Void and other = Void) or else ((some /= Void and other /= Void) and then some.is_equal (other))

    	is_equal (other: like Current): BOOLEAN
    			-- Is array made of the same items as `other'?
    			-- (from ARRAY)
    		require -- from ANY
    			other_not_void: other /= Void
    		ensure -- from ANY
    			symmetric: Result implies other.is_equal (Current)
    			consistent: standard_is_equal (other) implies Result

    	frozen standard_equal (some: ANY; other: like arg #1): BOOLEAN
    			-- Are `some' and `other' either both void or attached to
    			-- field-by-field identical objects of the same type?
    			-- Always uses default object comparison criterion.
    			-- (from ANY)
    		ensure -- from ANY
    			definition: Result = (some = Void and other = Void) or else ((some /= Void and other /= Void) and then some.standard_is_equal (other))

    	frozen standard_is_equal (other: like Current): BOOLEAN
    			-- Is `other' attached to an object of the same type
    			-- as current object, and field-by-field identical to it?
    			-- (from ANY)
    		require -- from ANY
    			other_not_void: other /= Void
    		ensure -- from ANY
    			same_type: Result implies same_type (other)
    			symmetric: Result implies other.standard_is_equal (Current)

    feature -- Status report

    	are_element_counts_consistent: BOOLEAN
    			-- Are element_counts consistent?

    	are_element_counts_valid (some_element_counts: ARRAY [INTEGER_32]): BOOLEAN
    			-- Are `some_element_counts' valid element counts?
    		require
    			non_void_element_counts: some_element_counts /= Void
    			valid_element_counts: (some_element_counts.count > 0 implies some_element_counts.lower = 1)

    	are_indices_large_enough (some_indices: ARRAY [INTEGER_32]): BOOLEAN
    			-- Are `some_indices' large enough?

    	are_indices_valid (some_indices: ARRAY [INTEGER_32]): BOOLEAN
    			-- Are `some_indices' valid indices?

    	conforms_to (other: ANY): BOOLEAN
    			-- Does type of current object conform to type
    			-- of `other' (as per Eiffel: The Language, chapter 13)?
    			-- (from ANY)
    		require -- from ANY
    			other_not_void: other /= Void

    	same_type (other: ANY): BOOLEAN
    			-- Is type of current object identical to type of `other'?
    			-- (from ANY)
    		require -- from ANY
    			other_not_void: other /= Void
    		ensure -- from ANY
    			definition: Result = (conforms_to (other) and other.conforms_to (Current))

    	total_count (some_element_counts: ARRAY [INTEGER_32]): INTEGER_32
    			-- Total number of elements
    		require
    			valid_counts: are_element_counts_valid (some_element_counts)
    		ensure
    			valid_count: Result >= 0

    feature {ANY} -- Status report

    	changeable_comparison_criterion: BOOLEAN
    			-- May object_comparison be changed?
    			-- (Answer: yes by default.)
    			-- (from CONTAINER)

    	object_comparison: BOOLEAN
    			-- Must search operations use equal rather than `='
    			-- for comparing references? (Default: no, use `='.)
    			-- (from CONTAINER)

    	valid_index (i: INTEGER_32): BOOLEAN
    			-- Is `i' within the bounds of the array?
    			-- (from ARRAY)
    		require -- from  TABLE
    			True
    		require -- from  TO_SPECIAL
    			True
    		ensure then -- from INDEXABLE
    			only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper))

    feature {ANY} -- Status setting

    	compare_objects
    			-- Ensure that future search operations will use equal
    			-- rather than `=' for comparing references.
    			-- (from CONTAINER)
    		require -- from CONTAINER
    			changeable_comparison_criterion: changeable_comparison_criterion
    		ensure -- from CONTAINER
    			object_comparison

    	compare_references
    			-- Ensure that future search operations will use `='
    			-- rather than equal for comparing references.
    			-- (from CONTAINER)
    		require -- from CONTAINER
    			changeable_comparison_criterion: changeable_comparison_criterion
    		ensure -- from CONTAINER
    			reference_comparison: not object_comparison

    feature -- Element change

    	force (v: like item; some_indices: ARRAY [INTEGER_32])
    			-- Assign item `v' at indices `some_indices'.
    			-- Resize if necesary.
    		require
    			valid_indices: are_indices_large_enough (some_indices)
    		ensure
    			element_inserted: item (some_indices) = v

    	put (v: like item; some_indices: ARRAY [INTEGER_32])
    			-- Assign item `v' at indices `some_indices'.
    		require
    			valid_indices: are_indices_valid (some_indices)
    		ensure
    			element_inserted: item (some_indices) = v

    feature -- Removal

    	discard_items
    			-- Remove all elements
    		ensure -- from ARRAY
    			default_items: all_default

    feature -- Resizing

    	resize (n_upper_indices: ARRAY [INTEGER_32])
    			-- Rearrange array so that it can accommodate `n_upper_indices'
    			-- without losing any previously entered items
    			-- or changing their indices;
    			-- do nothing if possible.
    		require
    			are_indices_large_enough (n_upper_indices)

    feature -- Duplication

    	copy (other: like Current)
    			-- Reinitialize by copying all the items of `other'.
    			-- (This is also used by clone.)
    			-- (from ARRAY)
    		require -- from ANY
    			other_not_void: other /= Void
    			type_identity: same_type (other)
    		ensure -- from ANY
    			is_equal: is_equal (other)
    		ensure then -- from ARRAY
    			equal_areas: area.is_equal (other.area)

    	frozen deep_copy (other: like Current)
    			-- Effect equivalent to that of:
    			--		copy (`other' . deep_twin)
    			-- (from ANY)
    		require -- from ANY
    			other_not_void: other /= Void
    		ensure -- from ANY
    			deep_equal: deep_equal (Current, other)

    	frozen deep_twin: like Current
    			-- New object structure recursively duplicated from Current.
    			-- (from ANY)
    		ensure -- from ANY
    			deep_equal: deep_equal (Current, Result)

    	frozen standard_copy (other: like Current)
    			-- Copy every field of `other' onto corresponding field
    			-- of current object.
    			-- (from ANY)
    		require -- from ANY
    			other_not_void: other /= Void
    			type_identity: same_type (other)
    		ensure -- from ANY
    			is_standard_equal: standard_is_equal (other)

    	frozen standard_twin: like Current
    			-- New object field-by-field identical to `other'.
    			-- Always uses default copying semantics.
    			-- (from ANY)
    		ensure -- from ANY
    			standard_twin_not_void: Result /= Void
    			equal: standard_equal (Result, Current)

    	frozen twin: like Current
    			-- New object equal to `Current'
    			-- twin calls copy; to change copying/twining semantics, redefine copy.
    			-- (from ANY)
    		ensure -- from ANY
    			twin_not_void: Result /= Void
    			is_equal: Result.is_equal (Current)

    feature -- Basic operations

    	frozen default: like Current
    			-- Default value of object's type
    			-- (from ANY)

    	frozen default_pointer: POINTER
    			-- Default value of type `POINTER'
    			-- (Avoid the need to write `p'.default for
    			-- some `p' of type `POINTER'.)
    			-- (from ANY)

    	default_rescue
    			-- Process exception for routines with no Rescue clause.
    			-- (Default: do nothing.)
    			-- (from ANY)

    	frozen do_nothing
    			-- Execute a null action.
    			-- (from ANY)

    feature -- Output

    	io: STD_FILES
    			-- Handle to standard file setup
    			-- (from ANY)

    	out: STRING_8
    			-- New string containing terse printable representation
    			-- of current object
    			-- Was declared in ANY as synonym of tagged_out.
    			-- (from ANY)

    	print (some: ANY)
    			-- Write terse external representation of `some'
    			-- on standard output.
    			-- (from ANY)

    	frozen tagged_out: STRING_8
    			-- New string containing terse printable representation
    			-- of current object
    			-- Was declared in ANY as synonym of out.
    			-- (from ANY)

    feature -- Platform

    	operating_environment: OPERATING_ENVIRONMENT
    			-- Objects available from the operating system
    			-- (from ANY)

    invariant
    	consistent_upper_indices: upper_indices.count = dimension_count
    	consistent_lower_indices: lower_indices.count = dimension_count
    	consistent_element_counts: are_element_counts_consistent
    	consistent_size: capacity = total_count (element_counts)
    	non_negative_count: count >= 0

    		-- from ANY
    	reflexive_equality: standard_is_equal (Current)
    	reflexive_conformance: conforms_to (Current)

    		-- from ARRAY
    	area_exists: area /= Void
    	consistent_size: capacity = upper - lower + 1
    	non_negative_count: count >= 0
    	index_set_has_same_count: valid_index_set

    		-- from RESIZABLE
    	increase_by_at_least_one: minimal_increase >= 1

    		-- from BOUNDED
    	valid_count: count <= capacity
    	full_definition: full = (count = capacity)

    		-- from FINITE
    	empty_definition: is_empty = (count = 0)
    	non_negative_count: count >= 0

    		-- from INDEXABLE
    	index_set_not_void: index_set /= Void

    indexing
    	copyright: "Copyright (c) 1984-2006, Eiffel Software and others"
    	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
    	source: "[
    		Eiffel Software
    		356 Storke Road, 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 ECOM_ARRAY