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

Contents of /FreeELKS/trunk/library/kernel/stream.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: 9641 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2 description: "Implementation of the STORABLE mechanism with streams."
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
10 STREAM
11
12 inherit
13 IO_MEDIUM
14
15 create
16 make,
17 make_with_size
18
19 feature -- Initialization
20
21 make is
22 -- Create stream object with a default_size of 100 bytes
23 do
24 buffer_size := 200
25 create_c_buffer
26 end
27
28 make_with_size (n: INTEGER) is
29 -- Create stream object with a default_size of `n' bytes
30 do
31 buffer_size := n
32 create_c_buffer
33 end
34
35 feature -- Status report
36
37 support_storable: BOOLEAN is True
38 -- Can medium be used to store an Eiffel structure?
39
40 feature -- Access
41
42 item: POINTER is
43 -- Direct access to stored/retrieved data
44 do
45 Result := c_buffer (internal_buffer_access)
46 end
47
48 buffer: POINTER is
49 -- C buffer correspond to the Eiffel STREAM
50 obsolete
51 "Use `item' instead to directly access stored/retrieved data"
52 do
53 Result := internal_buffer_access
54 end
55
56 buffer_size: INTEGER
57 -- Buffer's size.
58
59 object_stored_size: INTEGER
60 -- Size of last stored object.
61
62 create_c_buffer is
63 -- Create the C memory corresponding to the C buffer.
64 do
65 internal_buffer_access := c_malloc (buffer_size)
66 end
67
68 retrieved: ANY is
69 -- Retrieved object structure
70 -- To access resulting object under correct type,
71 -- use assignment attempt.
72 -- Will raise an exception (code `Retrieve_exception')
73 -- if content is not a stored Eiffel structure.
74 require else
75 True
76 local
77 size: INTEGER
78 do
79 (create {MISMATCH_CORRECTOR}).mismatch_information.do_nothing
80 Result := c_retrieved (internal_buffer_access, buffer_size, 0, $size)
81 object_stored_size := size
82 end
83
84 feature -- Element change
85
86 basic_store (object: ANY) is
87 -- Produce an external representation of the
88 -- entire object structure reachable from `object'.
89 -- Retrievable within current system only.
90 local
91 size: INTEGER
92 do
93 buffer_size := c_stream_basic_store (internal_buffer_access, buffer_size, $object, $size)
94 object_stored_size := size
95 end
96
97 general_store (object: ANY) is
98 -- Produce an external representation of the
99 -- entire object structure reachable from `object'.
100 -- Retrievable from other systems for same platform
101 -- (machine architecture).
102 --| This feature may use a visible name of a class written
103 --| in the `visible' clause of the Ace file. This makes it
104 --| possible to overcome class name clashes.
105 local
106 size: INTEGER
107 do
108 buffer_size := c_stream_general_store (internal_buffer_access, buffer_size, $object, $size)
109 object_stored_size := size
110 end
111
112 independent_store (object: ANY) is
113 -- Produce an external representation of the
114 -- entire object structure reachable from `object'.
115 -- Retrievable from other systems for the same or other
116 -- platform (machine architecture).
117 local
118 size: INTEGER
119 do
120 buffer_size := c_stream_independent_store (internal_buffer_access, buffer_size, $object, $size)
121 object_stored_size := size
122 end
123
124 set_additional_size (new_size: INTEGER) is
125 -- Set `new_size' to BUFFER_SIZE, internal value used to
126 -- increment `buffer_size' during storable operations.
127 external
128 "C use %"eif_store.h%""
129 alias
130 "set_buffer_size"
131 end
132
133 feature {NONE} -- Implementation
134
135 internal_buffer_access: POINTER
136 -- Access to C buffer pointed by `item'.
137
138 c_buffer (a_buf: POINTER): POINTER is
139 -- Dereferenced pointer of `a_buf'
140 require
141 a_buf_not_null: a_buf /= default_pointer
142 external
143 "C inline"
144 alias
145 "return (*(EIF_POINTER *) $a_buf);"
146 end
147
148 c_stream_basic_store (stream_buffer: POINTER; stream_buffer_size: INTEGER; object: POINTER; c_real_size: POINTER): INTEGER is
149 -- Store object structure reachable form current object
150 -- Return new size of `internal_buffer_access'.
151 external
152 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_REFERENCE, EIF_INTEGER *): EIF_INTEGER use %"eif_store.h%""
153 alias
154 "stream_estore"
155 end
156
157 c_stream_general_store (stream_buffer: POINTER; stream_buffer_size: INTEGER; object: POINTER; c_real_size: POINTER): INTEGER is
158 -- Store object structure reachable form current object
159 -- Return new size of `internal_buffer_access'.
160 external
161 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_REFERENCE, EIF_INTEGER *): EIF_INTEGER use %"eif_store.h%""
162 alias
163 "stream_eestore"
164 end
165
166 c_stream_independent_store (stream_buffer: POINTER; stream_buffer_size: INTEGER; object: POINTER; c_real_size: POINTER): INTEGER is
167 -- Store object structure reachable form current object
168 -- Return new size of `internal_buffer_access'.
169 external
170 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_REFERENCE, EIF_INTEGER *): EIF_INTEGER use %"eif_store.h%""
171 alias
172 "stream_sstore"
173 end
174
175 c_retrieved (stream_buffer: POINTER; stream_buffer_size: INTEGER; stream_buffer_position: INTEGER; c_real_size: POINTER): ANY is
176 -- Object structured retrieved from stream of pointer
177 -- `stream_ptr'
178 external
179 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_INTEGER, EIF_INTEGER *): EIF_REFERENCE use %"eif_retrieve.h%""
180 alias
181 "stream_eretrieve"
182 end
183
184 c_malloc (size: INTEGER): POINTER is
185 external
186 "C use %"eif_store.h%""
187 alias
188 "stream_malloc"
189 end
190
191 c_free (buf: POINTER) is
192 external
193 "C signature (EIF_POINTER *) use %"eif_store.h%""
194 alias
195 "stream_free"
196 end
197
198 feature -- Status report
199
200 exists: BOOLEAN is True
201 -- Stream exists in any cases.
202
203 is_open_read: BOOLEAN is True
204 -- Stream opens for input.
205
206 is_open_write: BOOLEAN is True
207 -- Stream opens for output.
208
209 is_readable: BOOLEAN is True
210
211 is_executable: BOOLEAN is
212 -- Is stream executable?
213 do
214 Result := False
215 end
216
217 is_writable: BOOLEAN is True
218 -- Stream is writable.
219
220 readable: BOOLEAN is
221 -- Is there a current item that may be read?
222 do
223 end
224
225 extendible: BOOLEAN is
226 -- May new items be added?
227 do
228 Result := True
229 end
230
231 is_closed: BOOLEAN
232 -- Is the I/O medium open
233
234 feature -- Status setting
235
236 close is
237 -- Close medium.
238 do
239 is_closed := True
240 c_free (internal_buffer_access)
241 internal_buffer_access := default_pointer
242 end
243
244 feature -- Output
245
246 put_new_line, new_line is
247 -- Write a new line character to medium
248 require else
249 stream_exists: exists
250 do
251 put_character ('%N')
252 end
253
254 put_string, putstring (s: STRING) is
255 -- Write `s' to medium.
256 do
257 end
258
259 put_character, putchar (c: CHARACTER) is
260 -- Write `c' to medium.
261 do
262 end
263
264 put_real, putreal (r: REAL) is
265 -- Write `r' to medium.
266 do
267 end
268
269 put_integer, putint, put_integer_32 (i: INTEGER) is
270 -- Write `i' to medium.
271 do
272 end
273
274 put_integer_8 (i: INTEGER_8) is
275 -- Write `i' to medium.
276 do
277 end
278
279 put_integer_16 (i: INTEGER_16) is
280 -- Write `i' to medium.
281 do
282 end
283
284 put_integer_64 (i: INTEGER_64) is
285 -- Write `i' to medium.
286 do
287 end
288
289 put_natural_8 (i: NATURAL_8) is
290 -- Write `i' to medium.
291 do
292 end
293
294 put_natural_16 (i: NATURAL_16) is
295 -- Write `i' to medium.
296 do
297 end
298
299 put_natural, put_natural_32 (i: NATURAL_32) is
300 -- Write `i' to medium.
301 do
302 end
303
304 put_natural_64 (i: NATURAL_64) is
305 -- Write `i' to medium.
306 do
307 end
308
309 put_boolean, putbool (b: BOOLEAN) is
310 -- Write `b' to medium.
311 do
312 end
313
314 put_double, putdouble (d: DOUBLE) is
315 -- Write `d' to medium.
316 do
317 end
318
319 put_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER) is
320 -- Put data of length `nb_bytes' pointed by `start_pos' index in `p' at
321 -- current position.
322 do
323 end
324
325 feature -- Input
326
327 read_real, readreal is
328 -- Read a new real.
329 -- Make result available in `last_real'.
330 do
331 end
332
333 read_double, readdouble is
334 -- Read a new double.
335 -- Make result available in `last_double'.
336 do
337 end
338
339 read_character, readchar is
340 -- Read a new character.
341 -- Make result available in `last_character'.
342 do
343 end
344
345 read_integer, readint, read_integer_32 is
346 -- Read a new integer.
347 -- Make result available in `last_integer'.
348 do
349 end
350
351 read_integer_8 is
352 -- Read a new integer.
353 -- Make result available in `last_integer_8'.
354 do
355 end
356
357 read_integer_16 is
358 -- Read a new integer.
359 -- Make result available in `last_integer_16'.
360 do
361 end
362
363 read_integer_64 is
364 -- Read a new integer.
365 -- Make result available in `last_integer_64'.
366 do
367 end
368
369 read_natural_8 is
370 -- Read a new natural.
371 -- Make result available in `last_natural_8'.
372 do
373 end
374
375 read_natural_16 is
376 -- Read a new natural.
377 -- Make result available in `last_natural_16'.
378 do
379 end
380
381 read_natural, read_natural_32 is
382 -- Read a new natural.
383 -- Make result available in `last_natural'.
384 do
385 end
386
387 read_natural_64 is
388 -- Read a new natural.
389 -- Make result available in `last_natural_64'.
390 do
391 end
392
393 read_stream, readstream (nb_char: INTEGER) is
394 -- Read a string of at most `nb_char' bound characters
395 -- or until end of medium is encountered.
396 -- Make result available in `last_string'.
397 do
398 end
399
400 read_line, readline is
401 -- Read characters until a new line or
402 -- end of medium.
403 -- Make result available in `last_string'.
404 do
405 end
406
407 read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER) is
408 -- Read at most `nb_bytes' bound bytes and make result
409 -- available in `p' at position `start_pos'.
410 do
411 end
412
413 feature {NONE} -- Not exported
414
415 name: STRING is
416 -- Not meaningful
417 do
418 end
419
420 handle: INTEGER is
421 -- Handle to medium
422 do
423 end
424
425 handle_available: BOOLEAN is
426 -- Is the handle available after class has been
427 -- created?
428 do
429 end
430
431 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23