comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: I/O streaming with custom data transport
Date: Tue, 21 Nov 2006 18:51:12 +0100
Date: 2006-11-21T18:51:12+01:00	[thread overview]
Message-ID: <4sgsgoFvn3caU1@mid.individual.net> (raw)
In-Reply-To: ejv4u6$qvu$1@cernne03.cern.ch

Maciej Sobczak wrote:

> Hi,
> 
> In C++ the IOStreams library allows to vary the behaviour of the stream
> by decoupling formatting from data buffering and transport to the
> physical device, which are in turn strategies for the stream object.
> This means that having millions of functions like this:
> 
> void foo(ostream &s)
> {
>      s << "Hello";
>      s << someObject;
>      s << someOtherObject;
>      // ...
> }
> 
> (and *there are* millions of functions like this)
> 
> it is possible to reuse these functions with different stream objects,
> from standard console output:
> 
> foo(cout);
> 
> ...to file output:
> 
> foo(myFile);
> 
> ...to network socket output:
> 
> foo(someSocketStreamConnectedSomewhere);
> 
> ...to whatever else comes up to the programmer's mind. It's just the
> matter of providing the implementation for the stream buffer.
> The key point here is that the mass of code out there need not be aware
> of it and can be reused with new stream objects without any
> modifications (that's OO in action).
> 
> I'm looking for something like this in Ada.
> 
> The basic I/O facilities in the standard library don't seem to provide
> anything like this.
> I hoped that Ada.Streams allows this by subclassing Root_Stream_Type and
> providing some overriding operations, but unfortunately I cannot even
> find the specification of Root_Stream_Type (looks like there isn't any
> and this type is just a name placeholder in ARM).

I think you haven't looked right. That's precisely how it's done. I have
chainable streams for compression, buffering, file I/O, memory streaming,
etc. And you do this just as you say: you extend
Ada.Streams.Root_Stream_Type and provide the read/write subprograms. Then,
you can dispatch on these or use the 'Input/'Output attributes of any type.
Conversely, you can override these to provide your own stream
representation of any type.

(I mention calling the subprograms directly instead of the 'attributes
because for some array types it's much more efficient -- at least it was
with GNAT 3.15p. But, usually, you just want to use the attributes).

Maybe is a compiler matter. In GNAT you can inspect the specification, but
if this is done by compiler magic in your case, still you should be able to
override the Read/Write subprograms in your derived stream type. The
package spec is in the RM05 13.13.1.

> If the standard library does not provide the functionality that I'm
> looking for (and I hope that I'm still misunderstanding something here),
> did anybody tackle the problem by implementing some replacement IO
> library with the functionality similar to that of IOStreams in C++?
 
If you're using GPS, go to Help -> GNAT runtime -> Ada -> Streams. You have
there the spec of Root_Stream_Type.

Ada 2005 adds new features for some kind of magic needed when inputting
types from an stream. I have had no need for this, but you may be as well
interested. It's all in the Barnes' rationale articles.



  parent reply	other threads:[~2006-11-21 17:51 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 [this message]
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
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