/[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 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 3 months ago) by manus_eiffel
File size: 8674 byte(s)
Initial revision

1 indexing
2
3 description: "Implementation of the STORABLE mechanism with streams."
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 STREAM
9
10 inherit
11 IO_MEDIUM
12
13 create
14 make,
15 make_with_size
16
17 feature -- Initialization
18
19 make is
20 -- Create stream object with a default_size of 100 bytes
21 do
22 buffer_size := 200
23 create_c_buffer
24 end
25
26 make_with_size (n: INTEGER) is
27 -- Create stream object with a default_size of `n' bytes
28 do
29 buffer_size := n
30 create_c_buffer
31 end
32
33 feature -- Status report
34
35 support_storable: BOOLEAN is True
36 -- Can medium be used to store an Eiffel structure?
37
38 feature -- Access
39
40 item: POINTER is
41 -- Direct access to stored/retrieved data
42 do
43 Result := c_buffer (internal_buffer_access)
44 end
45
46 buffer: POINTER is
47 -- C buffer correspond to the Eiffel STREAM
48 obsolete
49 "Use `item' instead to directly access stored/retrieved data"
50 do
51 Result := internal_buffer_access
52 end
53
54 buffer_size: INTEGER
55 -- Buffer's size.
56
57 object_stored_size: INTEGER
58 -- Size of last stored object.
59
60 create_c_buffer is
61 -- Create the C memory corresponding to the C buffer.
62 do
63 internal_buffer_access := c_malloc (buffer_size)
64 end
65
66 retrieved: ANY is
67 -- Retrieved object structure
68 -- To access resulting object under correct type,
69 -- use assignment attempt.
70 -- Will raise an exception (code `Retrieve_exception')
71 -- if content is not a stored Eiffel structure.
72 require else
73 True
74 local
75 size: INTEGER
76 do
77 (create {MISMATCH_CORRECTOR}).mismatch_information.do_nothing
78 Result := c_retrieved (internal_buffer_access, buffer_size, 0, $size)
79 object_stored_size := size
80 end
81
82 feature -- Element change
83
84 basic_store (object: ANY) is
85 -- Produce an external representation of the
86 -- entire object structure reachable from `object'.
87 -- Retrievable within current system only.
88 local
89 size: INTEGER
90 do
91 buffer_size := c_stream_basic_store (internal_buffer_access, buffer_size, $object, $size)
92 object_stored_size := size
93 end
94
95 general_store (object: ANY) is
96 -- Produce an external representation of the
97 -- entire object structure reachable from `object'.
98 -- Retrievable from other systems for same platform
99 -- (machine architecture).
100 --| This feature may use a visible name of a class written
101 --| in the `visible' clause of the Ace file. This makes it
102 --| possible to overcome class name clashes.
103 local
104 size: INTEGER
105 do
106 buffer_size := c_stream_general_store (internal_buffer_access, buffer_size, $object, $size)
107 object_stored_size := size
108 end
109
110 independent_store (object: ANY) is
111 -- Produce an external representation of the
112 -- entire object structure reachable from `object'.
113 -- Retrievable from other systems for the same or other
114 -- platform (machine architecture).
115 local
116 size: INTEGER
117 do
118 buffer_size := c_stream_independent_store (internal_buffer_access, buffer_size, $object, $size)
119 object_stored_size := size
120 end
121
122 set_additional_size (new_size: INTEGER) is
123 -- Set `new_size' to BUFFER_SIZE, internal value used to
124 -- increment `buffer_size' during storable operations.
125 external
126 "C | %"eif_store.h%""
127 alias
128 "set_buffer_size"
129 end
130
131 feature {NONE} -- Implementation
132
133 internal_buffer_access: POINTER
134 -- Access to C buffer pointed by `item'.
135
136 c_buffer (a_buf: POINTER): POINTER is
137 -- Dereferenced pointer of `a_buf'
138 require
139 a_buf_not_null: a_buf /= default_pointer
140 external
141 "C inline"
142 alias
143 "*(EIF_POINTER *) $a_buf"
144 end
145
146 c_stream_basic_store (stream_buffer: POINTER; stream_buffer_size: INTEGER; object: POINTER; c_real_size: POINTER): INTEGER is
147 -- Store object structure reachable form current object
148 -- Return new size of `internal_buffer_access'.
149 external
150 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_REFERENCE, EIF_INTEGER *): EIF_INTEGER use %"eif_store.h%""
151 alias
152 "stream_estore"
153 end
154
155 c_stream_general_store (stream_buffer: POINTER; stream_buffer_size: INTEGER; object: POINTER; c_real_size: POINTER): INTEGER is
156 -- Store object structure reachable form current object
157 -- Return new size of `internal_buffer_access'.
158 external
159 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_REFERENCE, EIF_INTEGER *): EIF_INTEGER use %"eif_store.h%""
160 alias
161 "stream_eestore"
162 end
163
164 c_stream_independent_store (stream_buffer: POINTER; stream_buffer_size: INTEGER; object: POINTER; c_real_size: POINTER): INTEGER is
165 -- Store object structure reachable form current object
166 -- Return new size of `internal_buffer_access'.
167 external
168 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_REFERENCE, EIF_INTEGER *): EIF_INTEGER use %"eif_store.h%""
169 alias
170 "stream_sstore"
171 end
172
173 c_retrieved (stream_buffer: POINTER; stream_buffer_size: INTEGER; stream_buffer_position: INTEGER; c_real_size: POINTER): ANY is
174 -- Object structured retrieved from stream of pointer
175 -- `stream_ptr'
176 external
177 "C signature (EIF_POINTER *, EIF_INTEGER, EIF_INTEGER, EIF_INTEGER *): EIF_REFERENCE use %"eif_retrieve.h%""
178 alias
179 "stream_eretrieve"
180 end
181
182 c_malloc (size: INTEGER): POINTER is
183 external
184 "C | %"eif_store.h%""
185 alias
186 "stream_malloc"
187 end
188
189 c_free (buf: POINTER) is
190 external
191 "C signature (EIF_POINTER *) use %"eif_store.h%""
192 alias
193 "stream_free"
194 end
195
196 feature -- Status report
197
198 exists: BOOLEAN is True
199 -- Stream exists in any cases.
200
201 is_open_read: BOOLEAN is True
202 -- Stream opens for input.
203
204 is_open_write: BOOLEAN is True
205 -- Stream opens for output.
206
207 is_readable: BOOLEAN is True
208
209 is_executable: BOOLEAN is
210 -- Is stream executable?
211 do
212 Result := False
213 end
214
215 is_writable: BOOLEAN is True
216 -- Stream is writable.
217
218 readable: BOOLEAN is
219 -- Is there a current item that may be read?
220 do
221 end
222
223 extendible: BOOLEAN is
224 -- May new items be added?
225 do
226 Result := True
227 end
228
229 is_closed: BOOLEAN
230 -- Is the I/O medium open
231
232 feature -- Status setting
233
234 close is
235 -- Close medium.
236 do
237 is_closed := True
238 c_free (internal_buffer_access)
239 internal_buffer_access := default_pointer
240 end
241
242 feature -- Output
243
244 put_new_line, new_line is
245 -- Write a new line character to medium
246 require else
247 stream_exists: exists
248 do
249 put_character ('%N')
250 end
251
252 put_string, putstring (s: STRING) is
253 -- Write `s' to medium.
254 do
255 end
256
257 put_character, putchar (c: CHARACTER) is
258 -- Write `c' to medium.
259 do
260 end
261
262 put_real, putreal (r: REAL) is
263 -- Write `r' to medium.
264 do
265 end
266
267 put_integer, putint (i: INTEGER) is
268 -- Write `i' to medium.
269 do
270 end
271
272 put_boolean, putbool (b: BOOLEAN) is
273 -- Write `b' to medium.
274 do
275 end
276
277 put_double, putdouble (d: DOUBLE) is
278 -- Write `d' to medium.
279 do
280 end
281
282 feature -- Input
283
284 read_real, readreal is
285 -- Read a new real.
286 -- Make result available in `last_real'.
287 do
288 end
289
290 read_double, readdouble is
291 -- Read a new double.
292 -- Make result available in `last_double'.
293 do
294 end
295
296 read_character, readchar is
297 -- Read a new character.
298 -- Make result available in `last_character'.
299 do
300 end
301
302 read_integer, readint is
303 -- Read a new integer.
304 -- Make result available in `last_integer'.
305 do
306 end
307
308 read_stream, readstream (nb_char: INTEGER) is
309 -- Read a string of at most `nb_char' bound characters
310 -- or until end of medium is encountered.
311 -- Make result available in `last_string'.
312 do
313 end
314
315 read_line, readline is
316 -- Read characters until a new line or
317 -- end of medium.
318 -- Make result available in `last_string'.
319 do
320 end
321
322 feature {NONE} -- Not exported
323
324 name: STRING is
325 -- Not meaningful
326 do
327 end
328
329 handle: INTEGER is
330 -- Handle to medium
331 do
332 end
333
334 handle_available: BOOLEAN is
335 -- Is the handle available after class has been
336 -- created?
337 do
338 end
339
340 indexing
341
342 library: "[
343 EiffelBase: Library of reusable components for Eiffel.
344 ]"
345
346 status: "[
347 Copyright 1986-2001 Interactive Software Engineering (ISE).
348 For ISE customers the original versions are an ISE product
349 covered by the ISE Eiffel license and support agreements.
350 ]"
351
352 license: "[
353 EiffelBase may now be used by anyone as FREE SOFTWARE to
354 develop any product, public-domain or commercial, without
355 payment to ISE, under the terms of the ISE Free Eiffel Library
356 License (IFELL) at http://eiffel.com/products/base/license.html.
357 ]"
358
359 source: "[
360 Interactive Software Engineering Inc.
361 ISE Building
362 360 Storke Road, Goleta, CA 93117 USA
363 Telephone 805-685-1006, Fax 805-685-6869
364 Electronic mail <info@eiffel.com>
365 Customer support http://support.eiffel.com
366 ]"
367
368 info: "[
369 For latest info see award-winning pages: http://eiffel.com
370 ]"
371
372 end -- class STREAM
373
374

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23