note description: "[ References to objects containing reference to object meant to be exchanged with non-Eiffel software. ]" library: "Free implementation of ELKS library" status: "See notice at end of class." legal: "See notice at end of class." date: "$Date: 2018-04-28 20:48:52 +0000 (Sat, 28 Apr 2018) $" revision: "$Revision: 101697 $" class POINTER_REF inherit HASHABLE redefine out, is_equal, is_hashable end REFACTORING_HELPER redefine out, is_equal end create default_create feature -- Access item: POINTER -- Pointer value hash_code: INTEGER_32 -- Hash code value do Result := item.hash_code end feature -- Element change frozen set_item (p: POINTER) -- Make p the item value. do item := p end feature -- Comparison is_equal (other: like Current): BOOLEAN -- Is other attached to an object of the same type -- as current object and identical to it? do Result := other.item = item end memory_compare (other: POINTER; a_size: INTEGER_32): BOOLEAN -- True if Current and other are identical on a_size bytes. require valid_size: a_size > 0 valid_other: other /= default_pointer do Result := c_memcmp (item, other, a_size) = 0 end feature -- Status report is_hashable: BOOLEAN -- May current object be hashed? -- (True if it is not its type's default.) do Result := item /= default_pointer end is_default_pointer: BOOLEAN -- Is current default_pointer? do Result := item = default_pointer ensure definition: Result = (item = default_pointer) end feature -- Operations plus alias "+" (offset: INTEGER_32): POINTER -- Pointer moved by an offset of offset bytes. do Result := item + offset end feature {NONE} -- Initialization make_from_reference (v: POINTER_REF) -- Initialize Current with v.item. require v_not_void: v /= Void do set_item (v.item) ensure item_set: item = v.item end feature -- Conversion to_reference: POINTER_REF -- Associated reference of Current do create Result; Result.set_item (item) ensure to_reference_not_void: Result /= Void end to_integer_32: INTEGER_32 -- Convert item into an INTEGER_32 value. do fixme (once "Do not forget to add proper precondition to ensure we can convert pointer value into an INTEGER_32") Result := item.to_integer_32 end feature -- Memory copy memory_copy (a_source: POINTER; a_size: INTEGER_32) -- Copy a_size bytes from a_source to Current. -- a_source and Current should not overlap. require valid_size: a_size >= 0 valid_source: a_source /= default_pointer do c_memcpy (item, a_source, a_size) end memory_move (a_source: POINTER; a_size: INTEGER_32) -- Copy a_size bytes from a_source to Current. -- a_source and Current can overlap. require valid_size: a_size >= 0 valid_source: a_source /= default_pointer do c_memmove (item, a_source, a_size) end memory_set (val, n: INTEGER_32) -- Fill first n bytes of the memory pointed by Current -- with constant val. require valid_val: val >= 0 valid_n: n >= 0 do c_memset (item, val, n) end feature -- Allocation/free memory_alloc (a_size: INTEGER_32): POINTER -- Allocated size bytes using malloc. require valid_size: a_size > 0 do Result := c_malloc (a_size) ensure instance_free: class end memory_calloc (a_count, a_element_size: INTEGER_32): POINTER -- Allocate a_count elements of size a_element_size bytes using `calloc. require valid_element_count: a_count > 0 valid_element_size: a_element_size > 0 do Result := c_calloc (a_count, a_element_size) ensure instance_free: class end memory_realloc (a_size: INTEGER_32): POINTER -- Realloc Current. require valid_size: a_size >= 0 do Result := c_realloc (item, a_size) end memory_free -- Free allocated memory with malloc. do c_free (item) set_item (default_pointer) end feature -- Output out: STRING_8 -- Printable representation of pointer value do Result := item.out end feature {NONE} -- Implementation c_memcpy (destination, source: POINTER; count: INTEGER_32) -- C memcpy external "C signature (void *, const void *, size_t) use <string.h>" alias "memcpy" end c_memmove (destination, source: POINTER; count: INTEGER_32) -- C memmove external "C signature (void *, const void *, size_t) use <string.h>" alias "memmove" end c_memset (source: POINTER; val: INTEGER_32; count: INTEGER_32) -- C memset external "C signature (void *, int, size_t) use <string.h>" alias "memset" end c_memcmp (source, other: POINTER; count: INTEGER_32): INTEGER_32 -- C memcmp external "C signature (void *, void *, size_t): EIF_INTEGER use <string.h>" alias "memcmp" end c_malloc (size: INTEGER_32): POINTER -- C malloc external "C signature (size_t): EIF_POINTER use <stdlib.h>" alias "malloc" end c_calloc (nmemb, size: INTEGER_32): POINTER -- C calloc external "C signature (size_t, size_t): EIF_POINTER use <stdlib.h>" alias "calloc" end c_realloc (source: POINTER; size: INTEGER_32): POINTER -- C realloc external "C signature (void *, size_t): EIF_POINTER use <stdlib.h>" alias "realloc" end c_free (p: POINTER) -- C free external "C signature (void *) use <stdlib.h>" alias "free" end note copyright: "Copyright (c) 1984-2018, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software 5949 Hollister Ave., 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 POINTER_REF
Generated by ISE EiffelStudio