comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: non-library level finalization
Date: Mon, 21 Mar 2005 16:37:32 -0600
Date: 2005-03-21T16:37:32-06:00	[thread overview]
Message-ID: <q6ednRFe15Yx0aLfRVn-oQ@comcast.com> (raw)
In-Reply-To: VpOdnfiAMeCb36LfRVn-1Q@megapath.net

>I forgot the obvious. The problem is not with a controlled *object*, but
>rather declaring a controlled *type*. So, you can do this by declaring a
>controlled type outside of the generic. Now, to make that useful, you'd have
>to figure out some way to figure out how to do the needed actions inside of
>the generic -- and *that* might prove difficult depending on what you need
>done. (For instance, registering a handler would work, but it too would have
>to be at library-level -- so you wouldn't have gained anything.)
  I considered the obvious
package Finalization_Helper is
  type Ptr_Type is access procedure;
  type Finalizer_Type is new Ada.Finalization.Limited_Controlled with record
    Last_Wishes_Ptr : Ptr_Type;
  end record;
  procedure Finalize(Finalizer : in out Finalizer_Type)  ...  is
  begin
    Finalizer.Last_Wishes_Ptr.all;
  exception
    when others=>null;
  end Finalize;

and then putting in the generic
  procedure Cleanup;
  Finalizer : Finalization_Helper.Finalizer_Type
    := (Last_Wishes_Ptr=>Cleanup'access);
but that has an access level problem.

>For a lot of generics, restricting to library level isn't a major concern
>(or, it's happened already, as is usually the case for tagged types). But
>your case may be different.
  It's merely unpleasing and maintenance error-prone to add an extra
package to instantiate the generic, and a Use clause to hide the fact of
the extra package.



      reply	other threads:[~2005-03-21 22:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-21  1:28 non-library level finalization tmoran
2005-03-21  9:01 ` Martin Dowie
2005-03-21 13:09   ` Ada2005 again, was: " Tapio Kelloniemi
2005-03-21 14:59     ` Martin Dowie
2005-03-21 21:48       ` Randy Brukardt
2005-03-21 15:54 ` Robert A Duff
2005-03-21 21:42 ` Randy Brukardt
2005-03-21 21:54 ` Randy Brukardt
2005-03-21 22:37   ` tmoran [this message]
replies disabled

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