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,887bac6875d2db34 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!newsfeed-fusi2.netcologne.de!news.netcologne.de!newsfeed-hp2.netcologne.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Access idiom 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: <6j5lj.309998$Fc.80333@attbi_s21> <26cde0d5-2c5e-4316-aad7-95fd7269646a@c23g2000hsa.googlegroups.com> Date: Tue, 22 Jan 2008 10:01:41 +0100 Message-ID: <7z96v1lwnp09.advcjt2uyly.dlg@40tude.net> NNTP-Posting-Date: 22 Jan 2008 09:52:29 CET NNTP-Posting-Host: a316b004.newsspool2.arcor-online.net X-Trace: DXC=K6P3BhJDR4N[kmHKHnaEnMA9EHlD;3YcB4Fo<]lROoRAnkgeX?EC@@@:Q>ZOia_8lM[6LHn;2LCVN7enW;^6ZC`DIXm65S@:3>Ongci\eB7B@L X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:19530 Date: 2008-01-22T09:52:29+01:00 List-Id: On Mon, 21 Jan 2008 19:56:54 -0800 (PST), Gene wrote: > Further comments very welcome if there is a better way. Again, > thanks. > > This compiles and dispatches as expected: > > ---- hoo.ads > package Hoo is > > type Node_Type is abstract tagged null record; type Node_Type (<>) is abstract limited tagged private; 1. I would add limited to indicate that are nodes never copied. 2. Maybe Ada.Finalization.Limited_Controlled should be used as the base. 3. "null record" looks much like an interface. You are in Ada 2005, so Node_Type could become an interface. > type Node_Ptr_Type is access all Node_Type'Class; type Node_Ptr_Type is access Node_Type'Class; I don't like general access types. What if somebody allocated a node on the stack linked it with another in the pool and then left the scope? Also, trees can often profit from arena and mark-and-sweep allocators, so you could do: for Node_Ptr_Type'Storage_Pool use My_Nice_Arena_Pool; > procedure XForm(P : access Node_Type; > Rtn : out Node_Ptr_Type) is abstract; > > type Binary_Type is new Node_Type with record > Left, Right : access Node_Type'Class; Left, Right : Node_Ptr_Type; We have an access type for that, and we don't want nodes having children allocated on the stack. (Not-null constraint can be added in Ada2005 if required.) > end record; > > overriding > procedure XForm(P : access Binary_Type; > Rtn : out Node_Ptr_Type); > end Hoo; > > ---- hoo.adb > package body Hoo is > > overriding > procedure XForm > (P : access Binary_Type; > Rtn : out Node_Ptr_Type) > is > begin > Rtn := Node_Ptr_Type(P); OK, that will be an unchecked conversion with pool-specific access types. This is a weaknesses of my approach, but I usually buy that. When conversions become too frequent I use the Rosen trick. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de