comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Extending a type and Finalization
Date: Thu, 4 Jun 2009 22:06:40 +0200
Date: 2009-06-04T22:06:40+02:00	[thread overview]
Message-ID: <1weng8cyxd5bf$.19oxow5s49g48$.dlg@40tude.net> (raw)
In-Reply-To: 02bb50df-d833-4b08-8f12-a3b10d7dcd78@n8g2000vbb.googlegroups.com

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



  reply	other threads:[~2009-06-04 20:06 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
2009-06-04 20:06     ` Dmitry A. Kazakov [this message]
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