+
Point of view
All features
deferred class WRAPPER_COLLECTION [ITEM_ -> WRAPPER]
Summary
A collection of wrappers.
copyright
Copyright (C) 2008-2022: Paolo Redaelli This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Direct parents
Inherit list: COLLECTION, WRAPPER_FACTORY
Known children
Inherit list: C_ARRAY
Class invariant
Overview
Features
Implementation
{WRAPPER, WRAPPER_HANDLER}
Accessing:
{ANY}
Writing:
{ANY}
Adding:
{ANY}
  • add_first (element: ANY)
    Add a new item in first position : count is increased by one and all other items are shifted right.
  • add_last (element: ANY)
    Add a new item at the end : count is increased by one.
  • add (element: ANY, index: INTEGER_32)
    Add a new element at rank index : count is increased by one and range [index .. upper] is shifted right by one position.
  • append_collection (other: COLLECTION[E_])
    Append other to Current.
  • append_traversable (other: TRAVERSABLE[E_])
    Append other to Current.
Modification:
{ANY}
  • force (element: E_, index: INTEGER_32)
    Make element the item at index, enlarging the collection if necessary (new bounds except index are initialized with default values).
  • copy (other: WRAPPER_COLLECTION [ITEM_ -> WRAPPER])
    Reinitialize by copying all the items of other.
  • from_collection (model: TRAVERSABLE[ANY])
    Initialize the current object with the contents of model.
Removing:
{ANY}
Looking and Searching:
{ANY}
Looking and comparison:
{ANY}
Other features:
{ANY}
Implement manifest generic creation:
{}
{ANY}
Other features:
{ANY}
Agent-based features:
{ANY}
Printing:
{ANY}
{ANY}
{}
Counting:
{ANY}
Agent-based features:
{ANY}
{}
Indexing:
{ANY}
Accessing:
{ANY}
Looking and Searching:
{ANY}
Implementation
{WRAPPER, WRAPPER_HANDLER}
  • wrapper_or_void (a_pointer: POINTER): ITEM_
    A wrapper for a_pointer or Void if a_pointer default_pointer (NULL in C).
Utility features
{}
Wrapper related exceptions
{}
Various exceptions codes:
{ANY}
{ANY}
Status report:
{ANY}
Basic operations:
{ANY}
  • die (code: INTEGER_32)
    Terminate execution with exit status code, without triggering an exception.
  • raise (name: STRING)
    Raise a developer exception of name name.
  • throw (a_exception: EXCEPTION)
Non-Standard Extensions:
{ANY}
{}
wrapper (a_pointer: POINTER): ITEM_
deferred function
The wrapper for a_pointer.
It could be newly created or retrieved from a cache, a dictionary, from the underlying object, depending on the implementation.
require
  • pointer_not_null: a_pointer.is_not_null
ensure
  • non_void: Result /= Void
  • correct: Result.handle = a_pointer
as_c_array: NATIVE_ARRAY[POINTER]
deferred function
Current collection as a C array meant to be passed to C functions expectiong an array of wrapped items.
Result - at C level - will be a Item**, i.e. a pointer to pointers to Item structures or - in other words - an array of pointers to Items.
infix "@" (i: INTEGER_32): E_
frozen
effective function
{ANY}
The infix notation which is actually just a synonym for item.
See also item.
require ensure
  • definition: Result = item(i)
put (element: ANY, i: INTEGER_32) assign item
deferred procedure
{ANY}
Make element the item at index i.
require ensure
swap (i1: INTEGER_32, i2: INTEGER_32)
effective procedure
{ANY}
Swap item at index i1 with item at index i2.
See also item, put.
require ensure
set_all_with (v: ANY)
deferred procedure
{ANY}
Set all items with value v.
See also set_slice_with.
ensure
set_slice_with (v: ANY, lower_index: INTEGER_32, upper_index: INTEGER_32)
effective procedure
{ANY}
Set all items in range [lower_index .. upper_index] with v.
See also set_all_with.
require ensure
clear_all
effective procedure
{ANY}
Set every item to its default value.
The count is not affected.
See also clear, all_default.
ensure
add_first (element: ANY)
deferred procedure
{ANY}
Add a new item in first position : count is increased by one and all other items are shifted right.
See also add_last, first, last, add.
ensure
add_last (element: ANY)
deferred procedure
{ANY}
Add a new item at the end : count is increased by one.
See also add_first, last, first, add.
ensure
add (element: ANY, index: INTEGER_32)
deferred procedure
{ANY}
Add a new element at rank index : count is increased by one and range [index .. upper] is shifted right by one position.
require ensure
append_collection (other: COLLECTION[E_])
effective procedure
{ANY}
Append other to Current.
This feature is obsolete: Use `append_traversable' instead.
append_traversable (other: TRAVERSABLE[E_])
effective procedure
{ANY}
Append other to Current.
See also add_last, add_first, add.
require
  • other /= Void
ensure
force (element: E_, index: INTEGER_32)
deferred procedure
{ANY}
Make element the item at index, enlarging the collection if necessary (new bounds except index are initialized with default values).
See also put, item, swap.
require ensure
copy (other: WRAPPER_COLLECTION [ITEM_ -> WRAPPER])
deferred procedure
{ANY}
Reinitialize by copying all the items of other.
require
    • not immutable
    • same_dynamic_type(other)
      • not immutable
      • same_dynamic_type(other)
      • not immutable
      • same_dynamic_type(other)
ensure
  • is_equal(other)
from_collection (model: TRAVERSABLE[ANY])
deferred procedure
{ANY}
Initialize the current object with the contents of model.
require
  • model /= Void
  • useful_work: model /= Current
ensure
remove_first
deferred procedure
{ANY}
Remove the first element of the collection.
require ensure
remove_head (n: INTEGER_32)
deferred procedure
{ANY}
Remove the n elements of the collection.
require ensure
remove (index: INTEGER_32)
deferred procedure
{ANY}
Remove the item at position index.
Followings items are shifted left by one position.
See also remove_first, remove_head, remove_tail, remove_last.
require ensure
remove_last
deferred procedure
{ANY}
Remove the last item.
require ensure
remove_tail (n: INTEGER_32)
deferred procedure
{ANY}
Remove the last n item(s).
require ensure
clear_count
deferred procedure
{ANY}
Discard all items (is_empty is True after that call).
If possible, the actual implementation supposed to keep its internal storage area in order to refill Current in an efficient way.
See also clear_count_and_capacity.
ensure
clear_count_and_capacity
deferred procedure
{ANY}
Discard all items (is_empty is True after that call).
If possible, the actual implementation supposed to release its internal storage area for this memory to be used by other objects.
See also clear_count.
ensure
has (x: ANY): BOOLEAN
effective function
{ANY}
Look for x using is_equal for comparison.
ensure
  • definition: Result = valid_index(first_index_of(x))
fast_has (x: ANY): BOOLEAN
effective function
{ANY}
Look for x using basic = for comparison.
See also has, fast_index_of, index_of.
ensure
  • definition: Result = valid_index(fast_first_index_of(x))
last_index_of (element: ANY): INTEGER_32
effective function
{ANY}
Using is_equal for comparison, gives the index of the last occurrence of element at or before upper.
Search is done in reverse direction, which means from the upper down to the lower index . Answer lower -1 when the search fail.
See also fast_last_index_of, reverse_index_of, index_of.
ensure
  • definition: Result = reverse_index_of(element, upper)
fast_last_index_of (element: ANY): INTEGER_32
effective function
{ANY}
Using basic = for comparison, gives the index of the last occurrence of element at or before upper.
Search is done in reverse direction, which means from the upper down to the lower index . Answer lower -1 when the search fail.
See also fast_reverse_index_of, last_index_of.
ensure
  • definition: Result = fast_reverse_index_of(element, upper)
fast_is_equal (other: WRAPPER_COLLECTION [ITEM_ -> WRAPPER]): BOOLEAN
deferred function
{ANY}
Do both collections have the same lower, upper, and items?
The basic = is used for comparison of items.
See also is_equal, same_items.
ensure
is_equal (other: WRAPPER_COLLECTION [ITEM_ -> WRAPPER]): BOOLEAN
deferred function
{ANY}
Do both collections have the same lower, upper, and items?
Feature is_equal is used for comparison of items.
See also fast_is_equal, same_items.
require
    • other /= Void
      • other /= Void
      • other /= Void
ensure
  • Result implies lower = other.lower and upper = other.upper
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)
is_equal_map (other: WRAPPER_COLLECTION [ITEM_ -> WRAPPER]): BOOLEAN
effective function
{ANY}
Do both collections have the same lower, upper, and items?
This feature is obsolete: Use `is_equal' instead.
all_default: BOOLEAN
deferred function
{ANY}
Do all items have their type's default value?
Note: for non Void items, the test is performed with the is_default predicate.
See also clear_all.
same_items (other: COLLECTION[E_]): BOOLEAN
effective function
{ANY}
Do both collections have the same items?
The basic = is used for comparison of items and indices are not considered (for example this routine may yield True with Current indexed in range [1..2] and other indexed in range [2..3]).
See also is_equal, fast_is_equal.
require
  • other /= Void
ensure
occurrences (element: ANY): INTEGER_32
deferred function
{ANY}
Number of occurrences of element using is_equal for comparison.
ensure
  • Result >= 0
fast_occurrences (element: ANY): INTEGER_32
deferred function
{ANY}
Number of occurrences of element using basic = for comparison.
See also occurrences, index_of.
ensure
  • Result >= 0
replace_all (old_value: ANY, new_value: ANY)
deferred procedure
{ANY}
Replace all occurrences of the element old_value by new_value using is_equal for comparison.
See also fast_replace_all, move.
ensure
fast_replace_all (old_value: ANY, new_value: ANY)
deferred procedure
{ANY}
Replace all occurrences of the element old_value by new_value using basic = for comparison.
See also replace_all, move.
ensure
move (lower_index: INTEGER_32, upper_index: INTEGER_32, distance: INTEGER_32)
effective procedure
{ANY}
Move range lower_index ..
upper_index by distance positions. Negative distance moves towards lower indices. Free places get default values.
See also slice, replace_all.
require ensure
slice (min: INTEGER_32, max: INTEGER_32): WRAPPER_COLLECTION [ITEM_ -> WRAPPER]
deferred function
{ANY}
New collection consisting of items at indexes in [min..max].
Result has the same dynamic type as Current. The lower index of the Result is the same as lower.
See also from_collection, move, replace_all.
require ensure
reverse
deferred procedure
{ANY}
Reverse the order of the elements.
ensure
manifest_semicolon_check: BOOLEAN
is False
constant attribute
{}
manifest_put (index: INTEGER_32, element: ANY)
deferred procedure
{}
require
  • index >= 0
enumerate: ENUMERATE[E_]
effective function
{ANY}
new_iterator: ITERATOR[E_]
deferred function
{ANY}
ensure
get_new_iterator: ITERATOR[E_]
frozen
effective function
{ANY}
This feature is obsolete: Use `new_iterator' instead. This historical SmartEiffel feature is badly named.
for_each (action: PROCEDURE[TUPLE[TUPLE 1[E_]]])
effective procedure
{ANY}
Apply action to every item of Current.
See also for_all, exists, aggregate.
require
  • action /= Void
for_all (test: FUNCTION[TUPLE[TUPLE 1[E_]]]): BOOLEAN
effective function
{ANY}
Do all items satisfy test?
See also for_each, exists, aggregate.
require
  • test /= Void
exists (test: FUNCTION[TUPLE[TUPLE 1[E_]]]): BOOLEAN
effective function
{ANY}
Does at least one item satisfy test?
See also for_each, for_all, aggregate.
require
  • test /= Void
aggregate (action: FUNCTION[TUPLE[TUPLE 2[E_, E_], E_]], initial: E_): E_
effective function
{ANY}
Aggregate all the elements starting from the initial value.
See also for_each, for_all, exists.
require
  • action /= Void
out_in_tagged_out_memory
effective procedure
{ANY}
Append terse printable representation of current object in tagged_out_memory.
require
  • locked: tagged_out_locked
ensure
  • still_locked: tagged_out_locked
  • not_cleared: tagged_out_memory.count >= old tagged_out_memory.count
  • append_only: old tagged_out_memory.twin.is_equal(tagged_out_memory.substring(1, old tagged_out_memory.count))
generation: INTEGER_32
writable attribute
{ANY}
next_generation
effective procedure
{}
ensure
count: INTEGER_32
deferred function
{ANY}
Number of available items in the hoard.
See also is_empty
ensure
  • Result >= 0
is_empty: BOOLEAN
deferred function
{ANY}
Is the hoard empty ?
See also count.
ensure
  • definition: Result = count = 0
do_all (action: ROUTINE[TUPLE[TUPLE 1[E_]]])
frozen
effective procedure
{ANY}
Apply action to every item of Current.
This feature is obsolete: Use `for_each` instead. This feature is not secure because it accepts a FUNCTION, the result of which is lost.
_inline_agent1 (a: ROUTINE[TUPLE[TUPLE 1[E_]]], e: E_)
frozen
effective procedure
{}
lower: INTEGER_32
deferred function
{ANY}
Minimum index.
See also upper, valid_index, item.
upper: INTEGER_32
deferred function
{ANY}
Maximum index.
See also lower, valid_index, item.
valid_index (i: INTEGER_32): BOOLEAN
effective function
{ANY}
True when i is valid (i.e., inside actual bounds).
See also lower, upper, item.
ensure
item (i: INTEGER_32): E_
deferred function
{ANY}
Item at the corresponding index i.
See also lower, upper, valid_index.
require
first: E_
deferred function
{ANY}
The very first item.
See also last, item.
require ensure
last: E_
deferred function
{ANY}
The last item.
See also first, item.
require ensure
first_index_of (element: ANY): INTEGER_32
deferred function
{ANY}
Give the index of the first occurrence of element using is_equal for comparison.
Answer upper + 1 when element is not inside.
See also fast_first_index_of, index_of, last_index_of, reverse_index_of.
ensure
index_of (element: ANY, start_index: INTEGER_32): INTEGER_32
deferred function
{ANY}
Using is_equal for comparison, gives the index of the first occurrence of element at or after start_index.
Return upper + 1 if the search for element failed.
See also fast_index_of, reverse_index_of, first_index_of.
ensure
reverse_index_of (element: ANY, start_index: INTEGER_32): INTEGER_32
deferred function
{ANY}
Using is_equal for comparison, gives the index of the first occurrence of element at or before start_index.
Search is done in reverse direction, which means from the start_index down to the lower index . Answer lower -1 when the search fail.
See also fast_reverse_index_of, last_index_of, index_of.
require ensure
fast_first_index_of (element: ANY): INTEGER_32
deferred function
{ANY}
Give the index of the first occurrence of element using basic = for comparison.
Answer upper + 1 when element is not inside.
See also first_index_of, last_index_of, fast_last_index_of.
ensure
fast_index_of (element: ANY, start_index: INTEGER_32): INTEGER_32
deferred function
{ANY}
Using basic = for comparison, gives the index of the first occurrence of element at or after start_index.
Answer upper + 1 when element when the search fail.
See also index_of, fast_reverse_index_of, fast_first_index_of.
ensure
fast_reverse_index_of (element: ANY, start_index: INTEGER_32): INTEGER_32
deferred function
{ANY}
Using basic = comparison, gives the index of the first occurrence of element at or before start_index.
Search is done in reverse direction, which means from the start_index down to the lower index . Answer lower -1 when the search fail.
See also reverse_index_of, fast_index_of, fast_last_index_of.
require ensure
wrapper_or_void (a_pointer: POINTER): ITEM_
effective function
A wrapper for a_pointer or Void if a_pointer default_pointer (NULL in C).
A commodity feature to replace the following code snippet: my_gobject: A_WRAPPER local p: POINTER do
  p := get_foo(handle)
  if p.is_not_null then
    Result := factory.wrapper(p)
  end
end
with
my_gobject: A_G_OBJECT_HEIR
  do
    Result := factory.wrapper_or_void(get_foo(handle))
  end
ensure
  • null_pointer_returns_void: a_pointer.is_null implies Result = Void
  • correct: a_pointer.is_not_null implies Result /= Void and then Result.handle = a_pointer
null_or (a_wrapper: WRAPPER): POINTER
effective function
{}
The handle of a_wrapper, or the default_pointer if a_wrapper is Void
ensure
  • definition: Result = default_pointer or else a_wrapper /= Void and then Result = a_wrapper.handle
null_or_string (a_string: ABSTRACT_STRING): POINTER
effective function
{}
A pointer to a memory area containing the content of a_string or default_pointer if a_string is Void.
The memory area may be the internal buffer of a_string or a newly allocated one.
ensure
  • definition: Result = default_pointer or a_string /= Void implies Result = a_string.to_external
null_or_array (a_collection: WRAPPER_COLLECTION[WRAPPER]): POINTER
effective function
{}
A pointer to the contenct of a_collection or NULL (default_pointer) if a_collection is Void
ensure
  • definition: a_collection = Void implies Result.is_null and a_collection /= Void implies Result.is_not_null
collection_to_c_array (a_collection: COLLECTION[WRAPPER]): FAST_ARRAY[POINTER]
effective function
{}
An array containing the pointers to the objects wrapped by a_collection wrappers.
TODO: avoid creating a new array whenever possible.
require
  • a_collection /= Void
  • not a_collection.is_empty
pointer_to_unwrapped_deferred_object: STRING
is "A C function returned a pointer to an unwrapped object which is wrapped by a deferred class. It is not possible to create a correct wrapper."
constant attribute
{}
retrieved_object_mismatch: STRING
is "Retrieved_object_mismatch: the Eiffel wrapper associated with a pointer is not an actual wrapper for the object referred by that pointer "
constant attribute
{}
copying_an_uncopyable: STRING
is "Trying to copy an uncopyable wrapper: such objects are usually shortly lived"
constant attribute
{}
Check_instruction: INTEGER_32
is 1
constant attribute
{ANY}
Exception code for violated check.
Class_invariant: INTEGER_32
is 2
constant attribute
{ANY}
Exception code for violated class invariant.
Developer_exception: INTEGER_32
is 3
constant attribute
{ANY}
Exception code for developer exception.
See also: raise, throw
Incorrect_inspect_value: INTEGER_32
is 4
constant attribute
{ANY}
Exception code for inspect statement.
This exception occurs when Void is passed as the expression to inspect ("inspect on STRING only). This exception also occurs when the inspected value selects no branch (when the keyword "else" not used, one "when" branch _must_ be selected). Some value which is not one of the inspect constants, if there is no Else_part h
Loop_invariant: INTEGER_32
is 5
constant attribute
{ANY}
Exception code for violated loop invariant
Loop_variant: INTEGER_32
is 6
constant attribute
{ANY}
Exception code for non-decreased loop variant
No_more_memory: INTEGER_32
is 7
constant attribute
{ANY}
Exception code for failed memory allocation
Postcondition: INTEGER_32
is 8
constant attribute
{ANY}
Exception code for violated postcondition.
Precondition: INTEGER_32
is 9
constant attribute
{ANY}
Exception code for violated precondition.
Routine_failure: INTEGER_32
is 10
constant attribute
{ANY}
Exception code for failed routine.
Os_signal: INTEGER_32
is 11
constant attribute
{ANY}
Exception code for a signal received from the OS.
Void_attached_to_expanded: INTEGER_32
is 12
constant attribute
{ANY}
Exception code for attachment of Void value to expanded entity.
Void_call_target: INTEGER_32
is 13
constant attribute
{ANY}
Exception code for feature applied to Void reference
System_level_type_error: INTEGER_32
is 14
constant attribute
{ANY}
Exception code for the system-level type error (this kind of error mostly arise with covariant redefinition).
exception_name: STRING
effective function
{ANY}
name_of_exception (a_exception: INTEGER_32): STRING
effective function
{ANY}
developer_exception: EXCEPTION
effective function
{ANY}
The last developer-thrown exception.
require
developer_exception_name: STRING
effective function
{ANY}
Name of last developer-raised exception.
require
is_developer_exception: BOOLEAN
effective function
{ANY}
Is the last exception originally due to a developer exception?
is_developer_named_exception: BOOLEAN
effective function
{ANY}
Is the last exception originally due to a developer exception?
is_developer_exception_of_name (name: STRING): BOOLEAN
effective function
{ANY}
Is the last exception originally due to a developer exception of name name?
assertion_violation: BOOLEAN
effective function
{ANY}
Is last exception originally due to a violated assertion or non-decreasing variant?
exception: INTEGER_32
{ANY}
Code of last exception that occurred.
is_signal: BOOLEAN
effective function
{ANY}
Is last exception originally due to an external event (operating system signal) ?
die (code: INTEGER_32)
effective procedure
{ANY}
Terminate execution with exit status code, without triggering an exception.
raise (name: STRING)
effective procedure
{ANY}
Raise a developer exception of name name.
require
  • name /= Void
throw (a_exception: EXCEPTION)
effective procedure
{ANY}
require
  • a_exception /= Void
signal_number: INTEGER_32
{ANY}
Signal Number received from OS.
 Zero if exception is not an OS signal.
named_exception: NAMED_EXCEPTION
once function
{}
developer_exception_memory: REFERENCE[EXCEPTION]
once function
{}
raise_exception (code: INTEGER_32)
{}