expanded class interface NATIVE_ARRAY[E]
--
-- This class gives access to the lowest level for arrays both for the C
-- language and for the Java language.
--
-- Warning: GURUS ONLY!! Using this class makes your Eiffel code non portable
-- on other Eiffel systems. This class may also be modified in further release
-- for a better interoperability between Java and C low level arrays.
--
-- Each class using some attribute of NATIVE_ARRAY type need an attribute
-- named capacity with value set to the size of the NATIVE_ARRAY. Value
-- has to be ajusted after each calloc/realloc/create_from.
--
feature(s) from SAFE_EQUAL
test (e1, e2: E): BOOLEAN
-- In order to avoid run-time type errors, feature safe_equal calls
-- is_equal only when e1 and e2 have exactly the same dynamic
-- type. Furthermore, this feature avoids argument passing from some
-- expanded type to the corresponding reference type (no automatic
-- allocation of some reference type during the comparison).
safe_equal (e1, e2: E): BOOLEAN
-- In order to avoid run-time type errors, feature safe_equal calls
-- is_equal only when e1 and e2 have exactly the same dynamic
-- type. Furthermore, this feature avoids argument passing from some
-- expanded type to the corresponding reference type (no automatic
-- allocation of some reference type during the comparison).
feature(s) from NATIVE_ARRAY
-- Basic features:
element_sizeof: INTEGER
-- The size in number of bytes for type E.
calloc (nb_elements: INTEGER): like Current
-- Allocate a new array of nb_elements of type E.
-- The new array is initialized with default values.
require
nb_elements > 0
ensure
Result.all_default(nb_elements - 1)
item (index: INTEGER): E
-- To read an item.
-- Assume that calloc is already done and that index is the range [0 .. nb_elements-1].
put (element: E; index: INTEGER)
-- To write an item.
-- Assume that calloc is already done and that index
-- is the range [0 .. nb_elements-1].
feature(s) from NATIVE_ARRAY
realloc (old_nb_elts, new_nb_elts: INTEGER): like Current
-- Assume Current is a valid NATIVE_ARRAY in range
-- [0 .. old_nb_elts-1]. Allocate a bigger new array in
-- range [0 .. new_nb_elts-1].
-- Old range is copied in the new allocated array.
-- New items are initialized with default values.
require
is_not_null;
old_nb_elts > 0;
old_nb_elts < new_nb_elts
ensure
Result.is_not_null
feature(s) from NATIVE_ARRAY
-- Comparison:
memcmp (other: like Current; capacity: INTEGER): BOOLEAN
-- True if all elements in range [0 .. capacity-1] are identical using is_equal.
-- Assume Current and other are big enough.
-- See also fast_memcmp.
require
capacity > 0 implies other.is_not_null
slice_memcmp (at: INTEGER; other: like Current; other_lower, other_upper: INTEGER): BOOLEAN
-- True if all elements in range [0 .. other_upper - other_lower] are identical
-- to the elements in range [other_lower .. other_upper] of other using
-- is_equal. Assume Current and other are big enough.
-- See also slice_fast_memcmp.
require
at >= 0;
other_lower >= 0;
other_upper >= other_lower - 1;
other_upper >= other_lower implies other.is_not_null
fast_memcmp (other: like Current; capacity: INTEGER): BOOLEAN
-- Same jobs as memcmp but uses infix "=" instead of is_equal.
require
capacity > 0 implies other.is_not_null
slice_fast_memcmp (at: INTEGER; other: like Current; other_lower, other_upper: INTEGER): BOOLEAN
-- Same jobs as slice_memcmp but uses infix "=" instead of is_equal.
require
at >= 0;
other_lower >= 0;
other_upper >= other_lower - 1;
other_upper >= other_lower implies other.is_not_null
deep_memcmp (other: like Current; capacity: INTEGER): BOOLEAN
-- Same jobs as memcmp but uses is_deep_equal instead of is_equal.
require
capacity > 0 implies other.is_not_null
slice_deep_memcmp (at: INTEGER; other: like Current; other_lower, other_upper: INTEGER): BOOLEAN
-- Same jobs as slice_memcmp but uses is_deep_equal instead of is_equal.
require
at >= 0;
other_lower >= 0;
other_upper >= other_lower - 1;
other_upper >= other_lower implies other.is_not_null
feature(s) from NATIVE_ARRAY
-- Searching:
index_of (element: E; upper: INTEGER): INTEGER
-- Give the index of the first occurrence of element using
-- is_equal for comparison.
-- Answer upper + 1 when element is not inside.
require
upper >= -1
slice_index_of (element: E; lower, upper: INTEGER): INTEGER
-- Give the index of the first occurrence of element using is_equal for comparison.
-- Answer upper + 1 when element is not inside.
require
lower >= 0;
upper >= lower - 1
fast_index_of (element: E; upper: INTEGER): INTEGER
-- Same as index_of but use basic = for comparison.
require
upper >= -1
slice_fast_index_of (element: E; lower, upper: INTEGER): INTEGER
-- Same as slice_index_of but use basic = for comparison.
require
lower >= 0;
upper >= lower - 1
has (element: E; upper: INTEGER): BOOLEAN
-- Look for element using is_equal for comparison.
-- Also consider fast_has to choose the most appropriate.
require
upper >= -1
fast_has (element: E; upper: INTEGER): BOOLEAN
-- Look for element using basic = for comparison.
-- Also consider has to choose the most appropriate.
require
upper >= -1
feature(s) from NATIVE_ARRAY
-- Removing:
remove_first (upper: INTEGER)
-- Assume upper is a valid index.
-- Move range [1 .. upper] by 1 position left.
require
upper >= 0
remove (index, upper: INTEGER)
-- Assume upper is a valid index.
-- Move range [index + 1 .. upper] by 1 position left.
require
index >= 0;
index <= upper
feature(s) from NATIVE_ARRAY
-- Replacing:
replace_all (old_value, new_value: E; upper: INTEGER)
-- Replace all occurrences of the element old_value by new_value using is_equal for comparison.
-- See also fast_replace_all to choose the apropriate one.
require
upper >= -1
fast_replace_all (old_value, new_value: E; upper: INTEGER)
-- Replace all occurrences of the element old_value by new_value
-- using basic = for comparison.
-- See also replace_all to choose the apropriate one.
require
upper >= -1
feature(s) from NATIVE_ARRAY
-- Adding:
copy_at (at: INTEGER; src: like Current; src_capacity: INTEGER)
-- Copy range [0 .. src_capacity - 1] of src to range
-- [at .. at + src_capacity - 1] of Current.
-- No subscript checking.
require
at >= 0;
src_capacity >= 0
slice_copy (at: INTEGER; src: like Current; src_min, src_max: INTEGER)
-- Copy range [src_min .. src_max] of src to range [at .. at + src_max - src_min] of Current.
-- No subscript checking.
require
at >= 0;
src_max >= src_min - 1;
useful_work: src /= Current or at /= src_min
feature(s) from NATIVE_ARRAY
-- Other:
set_all_with (v: E; upper: INTEGER)
-- Set all elements in range [0 .. upper] with
-- value v.
require
upper >= -1
set_slice_with (v: E; lower, upper: INTEGER)
-- Set all elements in range [lower .. upper] with
-- value v.
require
lower >= 0;
upper >= lower - 1
clear_all (upper: INTEGER)
-- Set all elements in range [0 .. upper] with
-- the default value.
require
upper >= -1
ensure
all_default(upper)
clear (lower, upper: INTEGER)
-- Set all elements in range [lower .. upper] with
-- the default value
require
lower >= 0;
upper >= lower - 1
copy_from (model: like Current; upper: INTEGER)
-- Assume upper is a valid index both in Current and model.
require
upper >= -1
deep_twin_from (capacity: INTEGER): like Current
-- To implement deep_twin. Allocate a new array of capacity
-- initialized with deep_twin. Assume capacity is valid both in
-- Current and model.
require
capacity >= 0
move (lower, upper, offset: INTEGER)
-- Move range [lower .. upper] by offset positions.
-- Freed positions are not initialized to default values.
require
lower >= 0;
upper >= lower;
lower + offset >= 0
occurrences (element: E; upper: INTEGER): INTEGER
-- Number of occurrences of element in range [0 .. upper] using is_equal for comparison.
-- See also fast_occurrences to chose the apropriate one.
require
upper >= -1
slice_occurrences (element: E; lower, upper: INTEGER): INTEGER
-- Number of occurrences of element in range [lower .. upper] using is_equal for comparison.
-- See also slice_fast_occurrences to chose the apropriate one.
require
lower >= 0;
upper >= lower - 1
fast_occurrences (element: E; upper: INTEGER): INTEGER
-- Number of occurrences of element in range [0 .. upper]
-- using basic "=" for comparison.
-- See also occurrences to chose the apropriate one.
require
upper >= -1
slice_fast_occurrences (element: E; lower, upper: INTEGER): INTEGER
-- Number of occurrences of element in range [lower .. upper]
-- using basic "=" for comparison.
-- See also slice_occurrences to chose the apropriate one.
require
lower >= 0;
upper >= lower - 1
all_default (upper: INTEGER): BOOLEAN
-- Do all items in range [0 .. upper] have their type's
-- default value?
-- Note: for non Void items, the test is performed with the
-- is_default predicate.
require
upper >= -1
slice_default (lower, upper: INTEGER): BOOLEAN
-- Do all items in range [lower .. upper] have their type's
-- default value?
-- Note: for non Void items, the test is performed with the
-- is_default predicate.
require
lower >= 0;
upper >= lower - 1
feature(s) from NATIVE_ARRAY
-- Interfacing with C:
to_external: POINTER
-- Gives access to the C pointer on the area of storage.
from_pointer (pointer: POINTER): like Current
-- Convert pointer into Current type.
is_not_null: BOOLEAN
is_null: BOOLEAN
end of expanded NATIVE_ARRAY[E]