/[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 91477 - (show annotations)
Sun Jan 14 09:47:13 2007 UTC (13 years ago) by ericb
File size: 8612 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2 description: "Files, viewed as persistent sequences of bytes"
3 library: "Free implementation of ELKS library"
4 copyright: "Copyright (c) 1986-2004, Eiffel Software and others"
5 license: "Eiffel Forum License v2 (see forum.txt)"
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class RAW_FILE
10
11 inherit
12 FILE
13 rename
14 index as position
15 redefine
16 file_reopen, file_open, file_dopen, read_to_managed_pointer
17 end
18
19 create
20
21 make, make_open_read, make_open_write, make_open_append,
22 make_open_read_write, make_create_read_write,
23 make_open_read_append
24
25 feature -- Status report
26
27 support_storable: BOOLEAN is True
28 -- Can medium be used to an Eiffel structure?
29
30 feature -- Output
31
32 put_integer, putint, put_integer_32 (i: INTEGER) is
33 -- Write binary value of `i' at current position.
34 do
35 file_pib (file_pointer, i)
36 end
37
38 put_integer_8 (i: INTEGER_8) is
39 -- Write binary value of `i' at current position.
40 do
41 integer_buffer.put_integer_8 (i, 0)
42 put_managed_pointer (integer_buffer, 0, 1)
43 end
44
45 put_integer_16 (i: INTEGER_16) is
46 -- Write binary value of `i' at current position.
47 do
48 integer_buffer.put_integer_16 (i, 0)
49 put_managed_pointer (integer_buffer, 0, 2)
50 end
51
52 put_integer_64 (i: INTEGER_64) is
53 -- Write binary value of `i' at current position.
54 do
55 integer_buffer.put_integer_64 (i, 0)
56 put_managed_pointer (integer_buffer, 0, 8)
57 end
58
59 put_natural_8 (i: NATURAL_8) is
60 -- Write binary value of `i' at current position.
61 do
62 integer_buffer.put_natural_8 (i, 0)
63 put_managed_pointer (integer_buffer, 0, 1)
64 end
65
66 put_natural_16 (i: NATURAL_16) is
67 -- Write binary value of `i' at current position.
68 do
69 integer_buffer.put_natural_16 (i, 0)
70 put_managed_pointer (integer_buffer, 0, 2)
71 end
72
73 put_natural, put_natural_32 (i: NATURAL_32) is
74 -- Write binary value of `i' at current position.
75 do
76 integer_buffer.put_natural_32 (i, 0)
77 put_managed_pointer (integer_buffer, 0, 4)
78 end
79
80 put_natural_64 (i: NATURAL_64) is
81 -- Write binary value of `i' at current position.
82 do
83 integer_buffer.put_natural_64 (i, 0)
84 put_managed_pointer (integer_buffer, 0, 8)
85 end
86
87 put_boolean, putbool (b: BOOLEAN) is
88 -- Write binary value of `b' at current position.
89 do
90 if b then
91 put_character ('%/001/')
92 else
93 put_character ('%U')
94 end
95 end
96
97 put_real, putreal (r: REAL) is
98 -- Write binary value of `r' at current position.
99 do
100 file_prb (file_pointer, r)
101 end
102
103 put_double, putdouble (d: DOUBLE) is
104 -- Write binary value `d' at current position.
105 do
106 file_pdb (file_pointer, d)
107 end
108
109 put_data (p: POINTER; size: INTEGER) is
110 -- Put `data' of length `size' pointed by `p' at
111 -- current position.
112 obsolete
113 "Use `put_managed_pointer' instead."
114 require
115 p_not_null: p /= default_pointer
116 extendible: extendible
117 do
118 file_ps (file_pointer, p, size)
119 end
120
121 feature -- Input
122
123 read_integer, readint, read_integer_32 is
124 -- Read the binary representation of a new 32-bit integer
125 -- from file. Make result available in `last_integer'.
126 do
127 last_integer := file_gib (file_pointer)
128 end
129
130 read_integer_8 is
131 -- Read the binary representation of a new 8-bit integer
132 -- from file. Make result available in `last_integer_8'.
133 do
134 read_to_managed_pointer (integer_buffer, 0, 1)
135 last_integer_8 := integer_buffer.read_integer_8 (0)
136 end
137
138 read_integer_16 is
139 -- Read the binary representation of a new 16-bit integer
140 -- from file. Make result available in `last_integer_16'.
141 do
142 read_to_managed_pointer (integer_buffer, 0, 2)
143 last_integer_16 := integer_buffer.read_integer_16 (0)
144 end
145
146 read_integer_64 is
147 -- Read the binary representation of a new 64-bit integer
148 -- from file. Make result available in `last_integer_64'.
149 do
150 read_to_managed_pointer (integer_buffer, 0, 8)
151 last_integer_64 := integer_buffer.read_integer_64 (0)
152 end
153
154 read_natural_8 is
155 -- Read the binary representation of a new 8-bit natural
156 -- from file. Make result available in `last_natural_8'.
157 do
158 read_to_managed_pointer (integer_buffer, 0, 1)
159 last_natural_8 := integer_buffer.read_natural_8 (0)
160 end
161
162 read_natural_16 is
163 -- Read the binary representation of a new 16-bit natural
164 -- from file. Make result available in `last_natural_16'.
165
166 do
167 read_to_managed_pointer (integer_buffer, 0, 2)
168 last_natural_16 := integer_buffer.read_natural_16 (0)
169 end
170
171 read_natural, read_natural_32 is
172 -- Read the binary representation of a new 32-bit natural
173 -- from file. Make result available in `last_natural'.
174 do
175 read_to_managed_pointer (integer_buffer, 0, 4)
176 last_natural := integer_buffer.read_natural_32 (0)
177 end
178
179 read_natural_64 is
180 -- Read the binary representation of a new 64-bit natural
181 -- from file. Make result available in `last_natural_64'.
182 do
183 read_to_managed_pointer (integer_buffer, 0, 8)
184 last_natural_64 := integer_buffer.read_natural_64 (0)
185 end
186
187 read_real, readreal is
188 -- Read the binary representation of a new real
189 -- from file. Make result available in `last_real'.
190 do
191 last_real := file_grb (file_pointer)
192 end
193
194 read_double, readdouble is
195 -- Read the binary representation of a new double
196 -- from file. Make result available in `last_double'.
197 do
198 last_double := file_gdb (file_pointer)
199 end
200
201 read_data (p: POINTER; nb_bytes: INTEGER) is
202 -- Read a string of at most `nb_bytes' bound bytes
203 -- or until end of file.
204 -- Make result available in `p'.
205 obsolete
206 "Use `read_to_managed_pointer' instead."
207 require
208 p_not_null: p /= default_pointer
209 is_readable: file_readable
210 do
211 bytes_read := file_fread (p, 1, nb_bytes, file_pointer)
212 end
213
214 read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER) is
215 -- Read at most `nb_bytes' bound bytes and make result
216 -- available in `p' at position `start_pos'.
217 do
218 bytes_read := file_fread (p.item + start_pos, 1, nb_bytes, file_pointer)
219 end
220
221 feature {NONE} -- Implementation
222
223 integer_buffer: MANAGED_POINTER is
224 -- Buffer used to read INTEGER_64, INTEGER_16, INTEGER_8
225 do
226 if internal_integer_buffer = Void then
227 create internal_integer_buffer.make (16)
228 end
229 Result := internal_integer_buffer
230 end
231
232 internal_integer_buffer: MANAGED_POINTER
233 -- Internal integer buffer
234
235 read_to_string (a_string: STRING; pos, nb: INTEGER): INTEGER is
236 -- Fill `a_string', starting at position `pos' with at
237 -- most `nb' characters read from current file.
238 -- Return the number of characters actually read.
239 do
240 Result := file_gss (file_pointer, a_string.area.item_address (pos - 1), nb)
241 end
242
243 file_gib (file: POINTER): INTEGER is
244 -- Get an integer from `file'
245 external
246 "C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
247 end
248
249 file_grb (file: POINTER): REAL is
250 -- Read a real from `file'
251 external
252 "C signature (FILE *): EIF_REAL_32 use %"eif_file.h%""
253 end
254
255 file_gdb (file: POINTER): DOUBLE is
256 -- Read a double from `file'
257 external
258 "C signature (FILE *): EIF_REAL_64 use %"eif_file.h%""
259 end
260
261 file_open (f_name: POINTER; how: INTEGER): POINTER is
262 -- File pointer for file `f_name', in mode `how'.
263 external
264 "C signature (char *, int): EIF_POINTER use %"eif_file.h%""
265 alias
266 "file_binary_open"
267 end
268
269 file_dopen (fd, how: INTEGER): POINTER is
270 -- File pointer for file of descriptor `fd' in mode `how'
271 -- (which must fit the way `fd' was obtained).
272 external
273 "C signature (int, int): EIF_POINTER use %"eif_file.h%""
274 alias
275 "file_binary_dopen"
276 end
277
278 file_reopen (f_name: POINTER; how: INTEGER; file: POINTER): POINTER is
279 -- File pointer to `file', reopened to have new name `f_name'
280 -- in a mode specified by `how'.
281 external
282 "C signature (char *, int, FILE *): EIF_POINTER use %"eif_file.h%""
283 alias
284 "file_binary_reopen"
285 end
286
287 file_pib (file: POINTER; n: INTEGER) is
288 -- Put `n' to end of `file'.
289 external
290 "C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
291 end
292
293 file_prb (file: POINTER; r: REAL) is
294 -- Put `r' to end of `file'.
295 external
296 "C signature (FILE *, EIF_REAL_32) use %"eif_file.h%""
297 end
298
299 file_pdb (file: POINTER; d: DOUBLE) is
300 -- Put `d' to end of `file'.
301 external
302 "C signature (FILE *, EIF_REAL_64) use %"eif_file.h%""
303 end
304
305 file_fread (dest: POINTER; elem_size, nb_elems: INTEGER; file: POINTER): INTEGER is
306 -- Read `nb_elems' of size `elem_size' in file `file' and store them
307 -- in location `dest'.
308 external
309 "C signature (void *, size_t, size_t, FILE *): EIF_INTEGER use <stdio.h>"
310 alias
311 "fread"
312 end
313
314 invariant
315
316 not_plain_text: not is_plain_text
317
318 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23