From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6c383a046f41e91 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed-0.progon.net!progon.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Text_IO from a stream Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <0465edf8-7272-43c8-82fd-fcae7cf0ef11@y21g2000hsf.googlegroups.com> <1y2oi69ev939v.1xugoel9fadnb$.dlg@40tude.net> <0c9ab8b7-a666-4fd2-a876-dca818ad5461@c65g2000hsa.googlegroups.com> Date: Mon, 31 Mar 2008 18:33:23 +0200 Message-ID: <17unr8ffxzcm.1ee1ucd0fwd1q$.dlg@40tude.net> NNTP-Posting-Date: 31 Mar 2008 18:33:27 CEST NNTP-Posting-Host: aba0ef84.newsspool2.arcor-online.net X-Trace: DXC=NRidTRHmJ\BH3YbbVCFON;JZ4cDNcfSJ;bb[eIRnRBaCd On Mon, 31 Mar 2008 09:05:35 -0700 (PDT), gautier_niouzes@hotmail.com wrote: > 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