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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,90b27c91e19c3731 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: I/O streaming with custom data transport Date: Wed, 22 Nov 2006 15:37:12 +0100 Organization: CERN News Message-ID: References: <4sgsgoFvn3caU1@mid.individual.net> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: cernne03.cern.ch 1164206232 30302 137.138.37.241 (22 Nov 2006 14:37:12 GMT) X-Complaints-To: news@@cern.ch NNTP-Posting-Date: Wed, 22 Nov 2006 14:37:12 +0000 (UTC) User-Agent: Thunderbird 1.5.0.8 (X11/20061113) In-Reply-To: Xref: g2news2.google.com comp.lang.ada:7640 Date: 2006-11-22T15:37:12+01:00 List-Id: Robert A Duff wrote: >> procedure Write_Hello(Stream : in out Stream_Access) is >> begin >> String'Write(Stream, "Hello"); >> end Write_Hello; > > I don't understand this. Ada streams are streams of Stream_Elements > (usually bytes), and the 'Read/'Write attributes encode things in > some way that is not necessarily human-readable. That's right, but the above was written for experimental/presentation purposes and was based on the assumption that the implementation will not unnecessarily complicate things so that the output will anyway be easy to verify to show that the principle works. > For example, > I think the above outputs the bounds of the string in some > binary form. T'Input/'Output do, but T'Write/'Read don't. > But the original question was about streams of characters, > intended to be human-readable. Right? Not necessarily. The point was only to make sure that there is a possiblity to use streams in a polimorphic way. Or to put it more precisely, where the existing code can be reused with different data transport strategies and where the reuse method will be based on run-time polymorphism and not, for example, on generics. > So how do Ada's streams help, here? Taking into account these objective, they do. :-) Of course, the question about text streams is still valid - and was left open in one of my other posts. For the moment I assume that in order to do this with text, I have to first format it in some string buffer and then do: String'Write(S, Buf); (just like with the "Hello" above) Taking into account that T'Write does not output constraints, it might be a valid method to insert text into the stream. Is this correct? > It seems to me what you want is an abstract Character_Output_Stream > type, with a primitive (or class-wide?) operation that puts a Character > to the stream. Then you can make derived types for sending to a file, > to an in-memory buffer, etc. That makes sense as well, but seems to be further off from what the standard library offers out of the box. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/