SECOM
Overview Cluster Class Classes Index          Top Features

secom.ewg

Class EWG_MANAGED_POINTER


Direct ancestors

MEMORY, EWG_IMPORTED_EXTERNAL_ROUTINES, EWG_EXTERNAL_MEMORY_ROUTINES

Creation

Features

Invariants

indexing

description

Wrapps a C pointer in a safe way

library

Eiffel Wrapper Generator Library

copyright

Copyright (c) 1999, Andreas Leitner and others

license

Eiffel Forum License v2 (see license.txt)

class EWG_MANAGED_POINTER

inherit

MEMORY
DISPOSABLE

create

make_new_unshared (a_capacity: INTEGER)

-- Create a new pointer wrapper to a new memory area where
-- all bytes have been reset to zero.
-- Allocates as a_capacity bytes of new memory.
-- 'unshared' means if the Current object
-- gets collected by the garbage collector,
-- the allocated memory will
-- be freed as well.

require

a_capacity_greater_equal_zero: a_capacity >= 0

ensure

exists: exists
is_not_shared: not is_shared
capacity_set: capacity = a_capacity
initialized_to_zero: read_integer_8 (0) = 0 and then read_integer_8 (capacity - 1) = 0

make_new_shared (a_capacity: INTEGER)

-- Create a new pointer wrapper to a new memory area where
-- all bytes have been reset to zero.
-- Allocates as a_capacity bytes of new memory.
-- 'shared' means if the Current object
-- gets collected by the garbage collector,
-- the allocated memory will
-- not be freed as well.

require

a_capacity_greater_equal_zero: a_capacity >= 0

ensure

exists: exists
is_shared: is_shared
capacity_set: capacity = a_capacity
initialized_to_zero: read_integer_8 (0) = 0 and then read_integer_8 (capacity - 1) = 0

make_new_unshared_uninitialized (a_capacity: INTEGER)

-- Create a new pointer wrapper to a new memory area. Bytes
-- have a random value.
-- Allocates as a_capacity bytes of new memory.
-- 'unshared' means if the Current object
-- gets collected by the garbage collector,
-- the allocated memory will
-- be freed as well.

require

a_capacity_greater_equal_zero: a_capacity >= 0

ensure

exists: exists
is_not_shared: not is_shared
capacity_set: capacity = a_capacity

make_new_shared_uninitialized (a_capacity: INTEGER)

-- Create a new pointer wrapper to a new memory area. Bytes
-- have a random value.
-- Allocates as a_capacity bytes of new memory.
-- 'shared' means if the Current object
-- gets collected by the garbage collector,
-- the allocated memory will
-- not be freed as well.

require

a_capacity_greater_equal_zero: a_capacity >= 0

ensure

exists: exists
is_shared: is_shared
capacity_set: capacity = a_capacity

make_unshared (a_item: POINTER; a_capacity: INTEGER)

-- Create a new pointer wrapper to an existing memory area.
-- a_item must be the pointer to the memory area to wrap.
-- a_capacity specifies how big the memory area is that
-- the pointer points to.
-- 'unshared' means if the Current object
-- gets collected by the garbage collector,
-- the allocated memory will
-- be freed as well.

require

a_capacity_greater_equal_zero: a_capacity >= 0

ensure

exists: exists
item_is_a_item: item = a_item
is_not_shared: not is_shared
capacity_set: capacity = a_capacity

make_shared (a_item: POINTER; a_capacity: INTEGER)

-- Create a new pointer wrapper to an existing memory area.
-- a_item must be the pointer to the memory area to wrap.
-- a_capacity specifies how big the memory area is that
-- the pointer points to.
-- 'shared' means if the Current object
-- gets collected by the garbage collector,
-- the memory allocated for the struct will
-- not be freed as well.

require

a_capacity_greater_equal_zero: a_capacity >= 0

ensure

exists: exists
item_is_a_item: item = a_item
is_shared: is_shared
capacity_set: capacity = a_capacity

make_default_pointer

-- Create a pointer wrapper for the default pointer (NULL).

ensure

not_exists: not exists

feature -- Access

capacity: INTEGER

-- Size of the memory area that the wrapped
-- pointer points to.

exists: BOOLEAN

-- Does item point to a valid C memory area ?

is_shared: BOOLEAN

-- Is the contents of item referenced by other C or Eiffel code?
-- If is_shared is True then when the current object will be
-- collected by the garbage collector, the wrapped memory area will
-- also be freed.
-- This is a good idea, only if you can be sure that when the
-- Eiffel object gets collected, the C side does not have a reference
-- to the wrapped memory anymore.

item: POINTER

-- Wrapped C pointer

read_double (a_pos: INTEGER): DOUBLE

-- Get the double at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads sizeof_double bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_double

read_integer (a_pos: INTEGER): INTEGER

-- Get the integer at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads sizeof_int bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_int

read_integer_16 (a_pos: INTEGER): INTEGER

-- Get the integer at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads 16 bits.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity - 1

ensure

result_is_int16: Result >= -32768 and Result <= 32767

read_integer_32 (a_pos: INTEGER): INTEGER

-- Get the integer at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads 32 bits.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity - 3

read_integer_8 (a_pos: INTEGER): INTEGER

-- Get the byte at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads 8 bits.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity

ensure

result_is_byte: Result >= -128 and Result <= 127

read_pointer (a_pos: INTEGER): POINTER

-- Get the pointer at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads sizeof_pointer bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_pointer

read_real (a_pos: INTEGER): REAL

-- Get the real at the a_pos-th
-- byte position of the wrapped memory
-- area.
-- Reads sizeof_real bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_real

feature -- Basic Operations

put_double (a_double: DOUBLE; a_pos: INTEGER)

-- Put a_double at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes sizeof_double bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_double

ensure

double_set: read_double (a_pos) = a_double

put_integer (a_int: INTEGER; a_pos: INTEGER)

-- Put a_int at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes sizeof_int bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_int

ensure

integer_set: read_integer (a_pos) = a_int

put_integer_16 (a_int: INTEGER; a_pos: INTEGER)

-- Put a_int at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes 16 bits.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity - 1
a_int_is_int16: a_int >= -32768 and a_int <= 32767

ensure

integer_16_set: read_integer_16 (a_pos) = a_int

put_integer_32 (a_int: INTEGER; a_pos: INTEGER)

-- Put a_int at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes 32 bits.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity - 3

ensure

integer_32_set: read_integer_32 (a_pos) = a_int

put_integer_8 (a_int: INTEGER; a_pos: INTEGER)

-- Put a_int at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes 8 bits.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity
a_int_is_byte: a_int >= -128 and a_int <= 127

ensure

integer_8_set: read_integer_8 (a_pos) = a_int

put_pointer (a_pointer: POINTER; a_pos: INTEGER)

-- Put a_pointer at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes sizeof_pointer bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_pointer

ensure

pointer_set: read_pointer (a_pos) = a_pointer

put_real (a_real: REAL; a_pos: INTEGER)

-- Put a_real at the a_pos-th byte position
-- of the wrapped memory area.
-- Writes sizeof_real bytes.

require

item_exists: exists
a_pos_greater_equal_zero: a_pos >= 0
a_pos_small_enough: a_pos < capacity + 1 - sizeof_real

ensure

real_set: read_real (a_pos) = a_real

feature --

sizeof_double: INTEGER

-- Returns the number of bytes a C double is broad

sizeof_int: INTEGER

-- Returns the number of bytes a C int is broad

sizeof_pointer: INTEGER

-- Returns the number of bytes a C pointer is broad

sizeof_real: INTEGER

-- Returns the number of bytes a C float is broad

invariant


Documentation generated by edoc