comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: I/O streaming with custom data transport
Date: Wed, 22 Nov 2006 15:37:12 +0100
Date: 2006-11-22T15:37:12+01:00	[thread overview]
Message-ID: <ek1nao$tiu$1@cernne03.cern.ch> (raw)
In-Reply-To: <wccvel7egkw.fsf@shell01.TheWorld.com>

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/



  reply	other threads:[~2006-11-22 14:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-21 15:11 I/O streaming with custom data transport Maciej Sobczak
2006-11-21 15:28 ` gautier_niouzes
2006-11-21 17:51 ` Alex R. Mosteo
2006-11-22  9:16   ` Maciej Sobczak
2006-11-22 10:01     ` Alex R. Mosteo
2006-11-22 10:39       ` Maciej Sobczak
2006-11-22 16:06         ` Dmitry A. Kazakov
2006-11-22 16:30         ` Alex R. Mosteo
2006-11-23  5:48         ` Simon Wright
2006-11-22 13:50     ` Robert A Duff
2006-11-22 14:37       ` Maciej Sobczak [this message]
2006-11-22 16:11         ` Georg Bauhaus
2006-11-21 19:02 ` Dmitry A. Kazakov
2006-11-22  9:21   ` Maciej Sobczak
2006-11-22 10:31     ` 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