From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,90b27c91e19c3731 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news2.volia.net!news.ecp.fr!u-picardie.fr!proxad.net!proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: I/O streaming with custom data transport Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Tue, 21 Nov 2006 20:02:04 +0100 Message-ID: <17ayrefpaw84a$.2qy8q0wbzzwk.dlg@40tude.net> NNTP-Posting-Date: 21 Nov 2006 20:01:58 CET NNTP-Posting-Host: 6417ef56.newsspool1.arcor-online.net X-Trace: DXC=Qf4bOP=;9IQ\PS5Xo=M[RVic==]BZ:af^4Fo<]lROoRQ^YC2XCjHcbYB2Pedkde5fYDNcfSJ;bb[UIRnRBaCd 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