Re: I/O streaming with custom data transport
- From: Maciej Sobczak <no.spam@xxxxxxxxxxx>
- Date: Wed, 22 Nov 2006 10:21:02 +0100
Dmitry A. Kazakov wrote:
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)
Alas, because it is a poor design based on ad-hoc polymorphism. All these
millions are overloaded.
I don't understand. The focus here is on foo - which represents the set of functions that can use the stream without really caring what the stream is.
In Ada it is exactly same. Consider:
Put (S : in out My_Root_Stream; X : String);
Put (S : in out My_Root_Stream; X : SomeObject);
...
An alternative design (still non-MD) is:
Put (S : in out Root_Stream'Class; X : String);
Put (S : in out Root_Stream'Class; X : SomeObject);
...
This achieves what you want. You can implement I/O on an object type like
String using some common class-wide functionality of streams and then
re-use it over all possible streams.
OK, now I see - there is a bit of misunderstanding. I'm not asking about how to provide new formatting, but rather how to provide new data transport. The practical intention is that I want to write some code that will be reused both with file streams and with network streams (for example).
Please see the example code in my reply to Alex, I think I've found the functionality that I'm looking for.
--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
.
- Follow-Ups:
- Re: I/O streaming with custom data transport
- From: Dmitry A. Kazakov
- Re: I/O streaming with custom data transport
- References:
- I/O streaming with custom data transport
- From: Maciej Sobczak
- Re: I/O streaming with custom data transport
- From: Dmitry A. Kazakov
- I/O streaming with custom data transport
- Prev by Date: Re: I/O streaming with custom data transport
- Next by Date: Re: I/O streaming with custom data transport
- Previous by thread: Re: I/O streaming with custom data transport
- Next by thread: Re: I/O streaming with custom data transport
- Index(es):
Relevant Pages
|