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 4 of 10 Topic 5628 of 5828
Post > Topic >>

Re: Text_IO from a stream

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

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
 




 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 14:47:55 CDT 2008.