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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!news.cs.univ-paris8.fr!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Extending a type and Finalization 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: <303a64d4-2fdd-47fe-ae4b-3ddf1912cffe@f19g2000yqh.googlegroups.com> <02bb50df-d833-4b08-8f12-a3b10d7dcd78@n8g2000vbb.googlegroups.com> Date: Thu, 4 Jun 2009 22:06:40 +0200 Message-ID: <1weng8cyxd5bf$.19oxow5s49g48$.dlg@40tude.net> NNTP-Posting-Date: 04 Jun 2009 22:06:40 CEST NNTP-Posting-Host: 8af398e0.newsspool2.arcor-online.net X-Trace: DXC=:ZlC9XRe_h1d8Nb@@ZG@b=A9EHlD;3Yc24Fo<]lROoR1^YC2XCjHcb9O^aBVWN2hE6DNcfSJ;bb[5IRnRBaCd?2>BWMX2ZL3cO On Thu, 4 Jun 2009 12:33:04 -0700 (PDT), Adam Beneschan wrote: > In addition to making an individual component a Limited_Controlled > type, you can use trickery using access discriminants to allow the > Initialize and Finalize routines to access the entire record. > Assuming P.T is limited, you can define something like: > > type Control_Type (Ref : access P.T'Class) is new > Ada.Finalization.Limited_Controlled with null record; > > overriding procedure Initialize (Obj : in out Control_Type); > overriding procedure Finalize (Obj : in out Control_Type); > > And then when defining TT: > > type TT is new P.T with record > Control : Control_Type (TT'Access); > ... > end record; > > Then when you declare an object of type TT, Initialize will be called > on the Control component, and the access discriminant Ref will give > you access to the entire record inside the Initialize and Finalize > routines. > > (This idea isn't mine. It might be Matthew Heaney's, but I'm not > sure. The Control_Type declaration was adapted from a "shapes" > demonstration program, but I'm not sure where it came from.) I am not sure if this pattern is safe. What gives a guaranty that other components of TT are initialized before the Initialize gets called on Control and finalized after the Finalize gets called? Otherwise you might access broken components of TT. It would be a hell to track down such an error. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de