From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Destructor question
Date: 1998/12/06
Date: 1998-12-06T00:00:00+00:00 [thread overview]
Message-ID: <m3zp915wo3.fsf@mheaney.ni.net> (raw)
In-Reply-To: 3665B85D.A2663591@nowhere.com
Rusnak <bogus@nowhere.com> writes:
> How are destrcutor methords properly implemented in Ada on tagged
> records? I have the following setup:
>
> Given a tagged record type:
>
> type Instance is abstract tagged
> record
> ...
> end record;
>
> type Object is access all Instance;
>
> type Class_Object is access all Instance'Class;
>
> and a package which keeps a container of "Class_Object"s.
>
> At the end of the day, I need to deallocate all the objects in the
> container.
Hers's an idea:
generic
type Item_Type is tagged private;
package Containers is
type Container_Type is limited private;
procedure Add
(Item : in Item_Type'Class;
To : in out Container_Type);
...
private
type Item_List is <list of pointers to Item_Type'Class>;
type Container_Type is
new Ada.Finalization.Controlled with record
Items : Item_List;
end record;
procedure Finalize (Container : in out Container_Type);
end Containers;
package body Containers is
procedure Finalize (Container : in out Container_Type) is
begin
<remove all items in Container.Items>
end;
...
end Containers;
prev parent reply other threads:[~1998-12-06 0:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-12-02 0:00 Destructor question Rusnak
1998-12-03 0:00 ` Jeff Carter
1998-12-03 0:00 ` Rusnak
1998-12-04 0:00 ` Robert I. Eachus
1998-12-06 0:00 ` Matthew Heaney
1998-12-08 0:00 ` Robert I. Eachus
1998-12-06 0:00 ` Matthew Heaney
1998-12-07 0:00 ` Jeff Carter
1998-12-06 0:00 ` david.c.hoos.sr
1998-12-06 0:00 ` Matthew Heaney
1998-12-08 0:00 ` Robert I. Eachus
1998-12-06 0:00 ` Matthew Heaney [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