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: a07f3367d7,2c1aef7e0a2350d1 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!bolzen.all.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!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="iso-8859-1" Content-Transfer-Encoding: 8bit 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> <1weng8cyxd5bf$.19oxow5s49g48$.dlg@40tude.net> Date: Fri, 5 Jun 2009 11:11:25 +0200 Message-ID: NNTP-Posting-Date: 05 Jun 2009 11:11:25 CEST NNTP-Posting-Host: 7b79bac4.newsspool1.arcor-online.net X-Trace: DXC=IC\k90J2bmK@Y=h<_c3PkHic==]BZ:afN4Fo<]lROoRA^YC2XCjHcbIXofUeHBj;mJDNcfSJ;bb[EFCTGGVUmh?DLK[5LiR>kgBekJJNjD_A6G X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6291 Date: 2009-06-05T11:11:25+02:00 List-Id: On Thu, 4 Jun 2009 14:18:41 -0700 (PDT), Adam Beneschan wrote: > On Jun 4, 1:06�pm, "Dmitry A. Kazakov" > wrote: >> 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? > > RM 7.6(12) Then it should rather be: � �type TT is new P.T with record � � � ... � � � Control : Control_Type (TT'Access); -- The last component � �end record; BTW, it seems that this pattern has a more consistent behavior upon extension than Ada.Finalization itself: type TTT; � type TTT_Hook (Ref : not null access TTT'Class) is new � � �Ada.Finalization.Limited_Controlled with null record; � overriding procedure Initialize (Obj : in out TTT_Hook); � overriding procedure Finalize � (Obj : in out TTT_Hook); � type TTT is new TT with record � � �... � � �Hook : TTT_Hook (TTT'Access); � end record; Unlikely to Ada.Finalize from the Initialize of TTT_Hook we do not call to the Initialize of Control_Type, because it has been called. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de