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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!postnews.google.com!t10g2000vbg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Extending a type and Finalization Date: Thu, 4 Jun 2009 14:18:41 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <303a64d4-2fdd-47fe-ae4b-3ddf1912cffe@f19g2000yqh.googlegroups.com> <02bb50df-d833-4b08-8f12-a3b10d7dcd78@n8g2000vbb.googlegroups.com> <1weng8cyxd5bf$.19oxow5s49g48$.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1244150321 1574 127.0.0.1 (4 Jun 2009 21:18:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 4 Jun 2009 21:18:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t10g2000vbg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6281 Date: 2009-06-04T14:18:41-07:00 List-Id: On Jun 4, 1:06=A0pm, "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: > > > =A0 =A0type Control_Type (Ref : access P.T'Class) is new > > =A0 =A0 =A0 =A0Ada.Finalization.Limited_Controlled with null record; > > > =A0 =A0overriding procedure Initialize (Obj : in out Control_Type); > > =A0 =A0overriding procedure Finalize =A0 (Obj : in out Control_Type); > > > And then when defining TT: > > > =A0 =A0type TT is new P.T with record > > =A0 =A0 =A0 Control : Control_Type (TT'Access); > > =A0 =A0 =A0 ... > > =A0 =A0end 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. =A0It might be Matthew Heaney's, but I'm not > > sure. =A0The 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) -- Adam