/[eiffelstudio]/FreeELKS/trunk/library/kernel/raw_file.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/raw_file.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 2 months ago) by manus_eiffel
File size: 5350 byte(s)
Initial revision

1 indexing
2
3 description:
4 "Files, viewed as persistent sequences of bytes"
5
6 status: "See notice at end of class"
7 date: "$Date$"
8 revision: "$Revision$"
9
10 class RAW_FILE
11
12 inherit
13 FILE
14 rename
15 index as position
16 redefine
17 file_reopen, file_open, file_dopen
18 end
19
20 create
21
22 make, make_open_read, make_open_write, make_open_append,
23 make_open_read_write, make_create_read_write,
24 make_open_read_append
25
26 feature -- Status report
27
28 support_storable: BOOLEAN is True
29 -- Can medium be used to an Eiffel structure?
30
31 feature -- Output
32
33 put_integer, putint (i: INTEGER) is
34 -- Write binary value of `i' at current position.
35 do
36 file_pib (file_pointer, i)
37 end
38
39 put_boolean, putbool (b: BOOLEAN) is
40 -- Write binary value of `b' at current position.
41 do
42 if b then
43 put_character ('%/001/')
44 else
45 put_character ('%U')
46 end
47 end
48
49 put_real, putreal (r: REAL) is
50 -- Write binary value of `r' at current position.
51 do
52 file_prb (file_pointer, r)
53 end
54
55 put_double, putdouble (d: DOUBLE) is
56 -- Write binary value `d' at current position.
57 do
58 file_pdb (file_pointer, d)
59 end
60
61 put_data (p: POINTER; size: INTEGER) is
62 -- Put `data' of length `size' pointed by `p' at
63 -- current position.
64 require
65 p_not_null: p /= default_pointer
66 do
67 file_ps (file_pointer, p, size)
68 end
69
70 feature -- Input
71
72 read_integer, readint is
73 -- Read the binary representation of a new integer
74 -- from file. Make result available in `last_integer'.
75 do
76 last_integer := file_gib (file_pointer)
77 end
78
79
80 read_real, readreal is
81 -- Read the binary representation of a new real
82 -- from file. Make result available in `last_real'.
83 do
84 last_real := file_grb (file_pointer)
85 end
86
87 read_double, readdouble is
88 -- Read the binary representation of a new double
89 -- from file. Make result available in `last_double'.
90 do
91 last_double := file_gdb (file_pointer)
92 end
93
94 read_data (p: POINTER; nb_bytes: INTEGER) is
95 -- Read a string of at most `nb_bytes' bound bytes
96 -- or until end of file.
97 -- Make result available in `p'.
98 local
99 new_count: INTEGER
100 do
101 new_count := file_fread (p, 1, nb_bytes, file_pointer)
102 end
103
104 feature {NONE} -- Implementation
105
106 read_to_string (a_string: STRING; pos, nb: INTEGER): INTEGER is
107 -- Fill `a_string', starting at position `pos' with at
108 -- most `nb' characters read from current file.
109 -- Return the number of characters actually read.
110 do
111 Result := file_gss (file_pointer, a_string.area.item_address (pos - 1), nb)
112 end
113
114 file_gib (file: POINTER): INTEGER is
115 -- Get an integer from `file'
116 external
117 "C (FILE *): EIF_INTEGER | %"eif_file.h%""
118 end
119
120 file_grb (file: POINTER): REAL is
121 -- Read a real from `file'
122 external
123 "C (FILE *): EIF_REAL | %"eif_file.h%""
124 end
125
126 file_gdb (file: POINTER): DOUBLE is
127 -- Read a double from `file'
128 external
129 "C (FILE *): EIF_DOUBLE | %"eif_file.h%""
130 end
131
132 file_open (f_name: POINTER; how: INTEGER): POINTER is
133 -- File pointer for file `f_name', in mode `how'.
134 external
135 "C signature (char *, int): EIF_POINTER use %"eif_file.h%""
136 alias
137 "file_binary_open"
138 end
139
140 file_dopen (fd, how: INTEGER): POINTER is
141 -- File pointer for file of descriptor `fd' in mode `how'
142 -- (which must fit the way `fd' was obtained).
143 external
144 "C signature (int, int): EIF_POINTER use %"eif_file.h%""
145 alias
146 "file_binary_dopen"
147 end
148
149 file_reopen (f_name: POINTER; how: INTEGER; file: POINTER): POINTER is
150 -- File pointer to `file', reopened to have new name `f_name'
151 -- in a mode specified by `how'.
152 external
153 "C (char *, int, FILE *): EIF_POINTER | %"eif_file.h%""
154 alias
155 "file_binary_reopen"
156 end
157
158 file_pib (file: POINTER; n: INTEGER) is
159 -- Put `n' to end of `file'.
160 external
161 "C (FILE *, EIF_INTEGER) | %"eif_file.h%""
162 end
163
164 file_prb (file: POINTER; r: REAL) is
165 -- Put `r' to end of `file'.
166 external
167 "C (FILE *, EIF_REAL) | %"eif_file.h%""
168 end
169
170 file_pdb (file: POINTER; d: DOUBLE) is
171 -- Put `d' to end of `file'.
172 external
173 "C (FILE *, EIF_DOUBLE) | %"eif_file.h%""
174 end
175
176 file_fread (dest: POINTER; elem_size, nb_elems: INTEGER; file: POINTER): INTEGER is
177 -- Read `nb_elems' of size `elem_size' in file `file' and store them
178 -- in location `dest'.
179 external
180 "C macro signature (void *, size_t, size_t, FILE *): EIF_INTEGER use <stdio.h>"
181 alias
182 "fread"
183 end
184
185 invariant
186
187 not_plain_text: not is_plain_text
188
189 indexing
190
191 library: "[
192 EiffelBase: Library of reusable components for Eiffel.
193 ]"
194
195 status: "[
196 Copyright 1986-2001 Interactive Software Engineering (ISE).
197 For ISE customers the original versions are an ISE product
198 covered by the ISE Eiffel license and support agreements.
199 ]"
200
201 license: "[
202 EiffelBase may now be used by anyone as FREE SOFTWARE to
203 develop any product, public-domain or commercial, without
204 payment to ISE, under the terms of the ISE Free Eiffel Library
205 License (IFELL) at http://eiffel.com/products/base/license.html.
206 ]"
207
208 source: "[
209 Interactive Software Engineering Inc.
210 ISE Building
211 360 Storke Road, Goleta, CA 93117 USA
212 Telephone 805-685-1006, Fax 805-685-6869
213 Electronic mail <info@eiffel.com>
214 Customer support http://support.eiffel.com
215 ]"
216
217 info: "[
218 For latest info see award-winning pages: http://eiffel.com
219 ]"
220
221 end -- class RAW_FILE
222
223
224

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23