From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: I/O streaming with custom data transport
Date: Tue, 21 Nov 2006 20:02:04 +0100
Date: 2006-11-21T20:01:58+01:00 [thread overview]
Message-ID: <17ayrefpaw84a$.2qy8q0wbzzwk.dlg@40tude.net> (raw)
In-Reply-To: ejv4u6$qvu$1@cernne03.cern.ch
On Tue, 21 Nov 2006 16:11:02 +0100, Maciej Sobczak 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. They should be overridden, but that were
impossible due to lack of multiple dispatch.
> I'm looking for something like this in Ada.
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.
> 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).
As I said it is basically same. But Ada also offers a sort of hard-wired
double dispatch through S'Read/Write, S'Input/Output attributes. See ARM
13.13.2.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2006-11-21 19:02 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
2006-11-22 16:11 ` Georg Bauhaus
2006-11-21 19:02 ` Dmitry A. Kazakov [this message]
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