Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Text_IO fro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 10 Topic 5628 of 5827
Post > Topic >>

Re: Text_IO from a stream

by "Dmitry A. Kazakov" <mailbox@[EMAIL PROTECTED] > Mar 31, 2008 at 09:47 PM

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
 




 10 Posts in Topic:
Text_IO from a stream
gautier_niouzes@[EMAIL PR  2008-03-31 08:27:21 
Re: Text_IO from a stream
"Dmitry A. Kazakov&q  2008-03-31 17:49:00 
Re: Text_IO from a stream
gautier_niouzes@[EMAIL PR  2008-03-31 09:05:35 
Re: Text_IO from a stream
"Dmitry A. Kazakov&q  2008-03-31 18:33:23 
Re: Text_IO from a stream
Gautier <gautier@[EMAI  2008-03-31 21:17:10 
Re: Text_IO from a stream
"Dmitry A. Kazakov&q  2008-03-31 21:47:37 
Re: Text_IO from a stream
Gautier <gautier@[EMAI  2008-03-31 22:54:35 
Re: Text_IO from a stream
"Dmitry A. Kazakov&q  2008-04-01 09:49:59 
Re: Text_IO from a stream
Simon Wright <simon.j.  2008-04-01 21:49:41 
Re: Text_IO from a stream
"Dmitry A. Kazakov&q  2008-04-02 09:36:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 0:08:15 CDT 2008.