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,e9247d4ba8198ede X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newspeer.monmouth.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Actual stream of a certain type 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: Thu, 27 Jul 2006 10:05:44 +0200 Message-ID: NNTP-Posting-Date: 27 Jul 2006 10:05:44 MEST NNTP-Posting-Host: e06f643d.newsread2.arcor-online.net X-Trace: DXC=5_nA]61Q?k53JZ2f42[h8HlV5[6LHn;2LCV>7enW;^6ZC`4IXm65S@:3>? X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:5960 Date: 2006-07-27T10:05:44+02:00 List-Id: On Thu, 27 Jul 2006 00:47:00 +0100, Marius Amado-Alves wrote: > Thanks, I know, I tried that, but I don't seem to succeed combining > that with providing T_Stream as a mix-in. I also tried Ada 2005 > interfaces with GNAT. I thought I saw a real case for interfaces and > that interested me because all examples I have seen so far are > academic, not compelling. But failed. Every time Ada got in the way. > It's really a love-hate relation with her. You have a "parallel types hierarchy" problem, which in general has no solution in Ada. On Thu, 27 Jul 2006 01:25:04 +0100, in comp.lang.ada you wrote: > Ok, here it goes. Of all idioms I tried maybe the least unsuccessful > (?) ones are those that raise Program_Error with message > "accessibility check failed" (GNAT) for line marked HERE below. The > problem here is: how to use the stream visible on that line, as the > good T_Stream object he is, pass it as a variable, etc? Thanks a > great lot. > > type T_Stream_Class_Access is access all T_Stream'Class; > > procedure Write_T > (Stream : T_Stream_Class_Access; > Item : in T) is > begin > Foobar (Stream.all, Item); > end; > > procedure Write > (Stream : not null access Ada.Streams.Root_Stream_Type'Class; > Item : in T) is > begin > if Stream.all not in T_Stream'Class then > raise Actual_Stream_Must_Be_A_T_Stream; > else > Write_T (T_Stream_Class_Access (Stream), Item); -- <== HERE > end if; > end; I would use (double-dispatch emulation): procedure Write_T (Stream : in out T_Stream; Item : T'Class) is begin Foobar (Stream, Item); end Write_T; procedure Write ( Stream : access Ada.Streams.Root_Stream_Type'Class; Item : T ) is begin if Stream.all not in T_Stream'Class then raise Actual_Stream_Must_Be_A_T_Stream; else Write_T (T_Stream'Class (Stream.all), Item); end if; end Write; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de