indexing description: "Files, viewed as persistent sequences of bytes" status: "See notice at end of class" date: "$Date$" revision: "$Revision$" class RAW_FILE inherit FILE rename index as position redefine file_reopen, file_open, file_dopen, read_to_managed_pointer end create make, make_open_read, make_open_write, make_open_append, make_open_read_write, make_create_read_write, make_open_read_append feature -- Status report support_storable: BOOLEAN is True -- Can medium be used to an Eiffel structure? feature -- Output put_integer, putint (i: INTEGER) is -- Write binary value of `i' at current position. do file_pib (file_pointer, i) end put_boolean, putbool (b: BOOLEAN) is -- Write binary value of `b' at current position. do if b then put_character ('%/001/') else put_character ('%U') end end put_real, putreal (r: REAL) is -- Write binary value of `r' at current position. do file_prb (file_pointer, r) end put_double, putdouble (d: DOUBLE) is -- Write binary value `d' at current position. do file_pdb (file_pointer, d) end put_data (p: POINTER; size: INTEGER) is -- Put `data' of length `size' pointed by `p' at -- current position. obsolete "Use `put_managed_pointer' instead." require p_not_null: p /= default_pointer extendible: extendible do file_ps (file_pointer, p, size) end feature -- Input read_integer, readint is -- Read the binary representation of a new integer -- from file. Make result available in `last_integer'. do last_integer := file_gib (file_pointer) end read_real, readreal is -- Read the binary representation of a new real -- from file. Make result available in `last_real'. do last_real := file_grb (file_pointer) end read_double, readdouble is -- Read the binary representation of a new double -- from file. Make result available in `last_double'. do last_double := file_gdb (file_pointer) end read_data (p: POINTER; nb_bytes: INTEGER) is -- Read a string of at most `nb_bytes' bound bytes -- or until end of file. -- Make result available in `p'. obsolete "Use `read_to_managed_pointer' instead." require p_not_null: p /= default_pointer is_readable: file_readable local new_count: INTEGER do new_count := file_fread (p, 1, nb_bytes, file_pointer) end read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER) is -- Read at most `nb_bytes' bound bytes and make result -- available in `p' at position `start_pos'. local l_read: INTEGER do l_read := file_fread (p.item + start_pos, 1, nb_bytes, file_pointer) end feature {NONE} -- Implementation read_to_string (a_string: STRING; pos, nb: INTEGER): INTEGER is -- Fill `a_string', starting at position `pos' with at -- most `nb' characters read from current file. -- Return the number of characters actually read. do Result := file_gss (file_pointer, a_string.area.item_address (pos - 1), nb) end file_gib (file: POINTER): INTEGER is -- Get an integer from `file' external "C (FILE *): EIF_INTEGER | %"eif_file.h%"" end file_grb (file: POINTER): REAL is -- Read a real from `file' external "C (FILE *): EIF_REAL | %"eif_file.h%"" end file_gdb (file: POINTER): DOUBLE is -- Read a double from `file' external "C (FILE *): EIF_DOUBLE | %"eif_file.h%"" end file_open (f_name: POINTER; how: INTEGER): POINTER is -- File pointer for file `f_name', in mode `how'. external "C signature (char *, int): EIF_POINTER use %"eif_file.h%"" alias "file_binary_open" end file_dopen (fd, how: INTEGER): POINTER is -- File pointer for file of descriptor `fd' in mode `how' -- (which must fit the way `fd' was obtained). external "C signature (int, int): EIF_POINTER use %"eif_file.h%"" alias "file_binary_dopen" end file_reopen (f_name: POINTER; how: INTEGER; file: POINTER): POINTER is -- File pointer to `file', reopened to have new name `f_name' -- in a mode specified by `how'. external "C (char *, int, FILE *): EIF_POINTER | %"eif_file.h%"" alias "file_binary_reopen" end file_pib (file: POINTER; n: INTEGER) is -- Put `n' to end of `file'. external "C (FILE *, EIF_INTEGER) | %"eif_file.h%"" end file_prb (file: POINTER; r: REAL) is -- Put `r' to end of `file'. external "C (FILE *, EIF_REAL) | %"eif_file.h%"" end file_pdb (file: POINTER; d: DOUBLE) is -- Put `d' to end of `file'. external "C (FILE *, EIF_DOUBLE) | %"eif_file.h%"" end file_fread (dest: POINTER; elem_size, nb_elems: INTEGER; file: POINTER): INTEGER is -- Read `nb_elems' of size `elem_size' in file `file' and store them -- in location `dest'. external "C macro signature (void *, size_t, size_t, FILE *): EIF_INTEGER use " alias "fread" end invariant not_plain_text: not is_plain_text indexing library: "[ EiffelBase: Library of reusable components for Eiffel. ]" status: "[ Copyright 1986-2001 Interactive Software Engineering (ISE). For ISE customers the original versions are an ISE product covered by the ISE Eiffel license and support agreements. ]" license: "[ EiffelBase may now be used by anyone as FREE SOFTWARE to develop any product, public-domain or commercial, without payment to ISE, under the terms of the ISE Free Eiffel Library License (IFELL) at http://eiffel.com/products/base/license.html. ]" source: "[ Interactive Software Engineering Inc. ISE Building 360 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Electronic mail Customer support http://support.eiffel.com ]" info: "[ For latest info see award-winning pages: http://eiffel.com ]" end -- class RAW_FILE