comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Extending a type and Finalization
Date: Thu, 4 Jun 2009 12:33:04 -0700 (PDT)
Date: 2009-06-04T12:33:04-07:00	[thread overview]
Message-ID: <02bb50df-d833-4b08-8f12-a3b10d7dcd78@n8g2000vbb.googlegroups.com> (raw)
In-Reply-To: 303a64d4-2fdd-47fe-ae4b-3ddf1912cffe@f19g2000yqh.googlegroups.com

On Jun 4, 11:00 am, Hibou57 (Yannick Duchêne)
<yannick_duch...@yahoo.fr> 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 “components” 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




  reply	other threads:[~2009-06-04 19:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04 17:45 Extending a type and Finalization pascal.malaise
2009-06-04 18:00 ` Hibou57 (Yannick Duchêne)
2009-06-04 19:33   ` Adam Beneschan [this message]
2009-06-04 20:06     ` Dmitry A. Kazakov
2009-06-04 21:18       ` Adam Beneschan
2009-06-05  9:11         ` Dmitry A. Kazakov
2009-06-05 14:48           ` Adam Beneschan
2009-06-05 17:15             ` Dmitry A. Kazakov
2009-06-05 11:29     ` malaise
2009-06-05 12:21       ` Ludovic Brenta
2009-06-05 13:02         ` malaise
2009-06-05 13:14           ` Ludovic Brenta
2009-06-05 13:32             ` malaise
2009-06-15  6:30 ` AdaMagica
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox