On Mon, 31 Mar 2008 09:05:35 -0700 (PDT), gautier_niouzes@[EMAIL PROTECTED]
> Dmitry A. Kazakov:
>
>> You can always wrap a File_Type in your own stream object.
>
> Do you mean something like:
>
> type Text_Stream_Type is new Ada.Streams.Root_Stream_Type with record
> virtual_file : Ada.Text_IO.File_Type;
> end record;
Yes
> At the end of the day, what I'd really like is
> function File(stream: access Ada.Streams.Root_Stream_Type 'Class)
> return Ada.Text_IO.File_Type;
> so that I can do read ASCII data from any stream:
> f:= File(my_stream);
> -- f is as if open in In_File mode
> Get_Line(f, a_string, length);
> Get(f, an_integer); -- not binary, but 123_456
> Get(f, a_float); -- not binary, but -123.456e78
>
> I guess it would be difficult... But maybe I'm wrong ?
> Gautier
But a stream has no defined formatting and is unrelated to ASCII. Then the
idea of parsing stream looks problematic. If you have in the stream a
sequence " + -", what Get should do after discovering '-'?
Anyway, it is quite simple to do. You can do
type Formatted_Stream (Source : access Root_Stream_Type'Class) is
tagged limited private;
function Get (Stream : access Formatted_Stream) return Integer;
...
The implementation of Formatted_Stream will use Source for all its I/O. So
you could hang it on any existing stream.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


|