From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Text_IO from a stream
Date: Mon, 31 Mar 2008 21:47:37 +0200
Date: 2008-03-31T21:47:37+02:00 [thread overview]
Message-ID: <1rmypswe6uyhs.10fy5p7ytb4os$.dlg@40tude.net> (raw)
In-Reply-To: 47f138b6$1_5@news.bluewin.ch
On Mon, 31 Mar 2008 21:17:10 +0200, Gautier wrote:
> Dmitry A. Kazakov:
>> But a stream has no defined formatting and is unrelated to ASCII.
>
> Still, you can read the stream through Character'Read(s,c).
Yes, but will that be ASCII-encoded? And it has somehow invent lines and
pages.
>> Then the idea of parsing stream looks problematic. If you have in the stream a
>> sequence " + -", what Get should do after discovering '-'?
>
> Exactly the same behaviour as when parsing an ill-formatted text.
Ah, yes. I cannot find the place in ARM, but it seems that Text_IO would
swallow syntactically incorrect input before propagating Data_Error.
> Reading a text file (or supposedly so) indirectly via a stream and Stream_IO
> would have the same result that via Ada.Text_IO.
>
>> 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.
>
> Fine, seems I need to rewrite a Text_IO for streams. I hoped for a ready-made
> solution...
But Text_IO also defines all Get procedures on String. So if you knew where
line ends are in your stream you could cache the current line in
Formatted_Stream and then simply route all its Gets to Ada.Text_IO Gets.
> Well, I think I'll switch to a binary format...
I would do that too. Also I would override 'Read and 'Write in order to
make it platform-independent. (Stream_Element should be replaced by
octets.)
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-03-31 19:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-31 15:27 Text_IO from a stream gautier_niouzes
2008-03-31 15:49 ` Dmitry A. Kazakov
2008-03-31 16:05 ` gautier_niouzes
2008-03-31 16:33 ` Dmitry A. Kazakov
2008-03-31 19:17 ` Gautier
2008-03-31 19:47 ` Dmitry A. Kazakov [this message]
2008-03-31 20:54 ` Gautier
2008-04-01 7:49 ` Dmitry A. Kazakov
2008-04-01 20:49 ` Simon Wright
2008-04-02 7:36 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox