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-Language: ENGLISH,CP1252 Path: g2news2.google.com!postnews.google.com!n8g2000vbb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Extending a type and Finalization Date: Thu, 4 Jun 2009 12:33:04 -0700 (PDT) Organization: http://groups.google.com Message-ID: <02bb50df-d833-4b08-8f12-a3b10d7dcd78@n8g2000vbb.googlegroups.com> References: <303a64d4-2fdd-47fe-ae4b-3ddf1912cffe@f19g2000yqh.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1244143984 13639 127.0.0.1 (4 Jun 2009 19:33:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 4 Jun 2009 19:33:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n8g2000vbb.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:6271 Date: 2009-06-04T12:33:04-07:00 List-Id: On Jun 4, 11:00=A0am, Hibou57 (Yannick Duch=EAne) wrote: > On 4 juin, 19:45, pascal.mala...@gmail.com wrote:> but the new attributes= require Ada.Finalization and Limited_Controlled > > is a tagged type (not an interface). > > When you talk about attributes, do you mean =93components=94 of the > record ? > > > Can I extend a type and together define the finalization of the new > > type, and how? > > If you are indeed talking about the record's components, then you are > not required to make the whole record controlled. You can do it on > individual compononents which requires this. 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.) However, if it's possible to go back and change P.T to make it a type derived from Limited_Controlled, that would be preferable, I think. The default Initialize and Finalize routines will be null, so doing this shouldn't change the semantics of the rest of the program any, although it will add some overhead. -- Adam