I/O streaming with custom data transport



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).

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++?

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
.