comp.lang.ada
 help / color / mirror / Atom feed
From: "jimmaureenrogers@worldnet.att.net" <jimmaureenrogers@worldnet.att.net>
Subject: Re: How to properly clean up an extended, generic structure?
Date: 9 Jul 2006 07:29:24 -0700
Date: 2006-07-09T07:29:24-07:00	[thread overview]
Message-ID: <1152455364.613074.18170@75g2000cwc.googlegroups.com> (raw)
In-Reply-To: 44b107b7$0$3629$4d3efbfe@news.sover.net

Peter C. Chapin wrote:
> I've created a procedure Destroy_Tree that uses an instance of
> Ada.Unchecked_Deallocation to remove all the nodes in a given tree.
> Destroy_Tree is meant to be used when a tree is no longer needed and it
> serves the role of a destructor (using C++ terminology). It occurs to
> me, though, that Item_Type might have its own clean up needs. I assume
> that Unchecked_Deallocation knows nothing about that. Thus my code
> currently might be improperly cleaning up the Item_Types in each tree
> node. In C++ this is not a problem because deleting a node invokes the
> node's destructor (if there is one) so the issue is handled
> automatically. My question is how do I best deal with this in Ada?
>
> I could pass a clean up procedure for Item_Types as another generic
> parameter. However, in cases where no such procedure is necessary (for
> example, when Item_Type is just Integer), such a solution seems awkward.
> Is there a nicer solution?

You should read up on Ada controlled types. The tree itself can be a
controlled type. The tree elements may or may not be controlled types.

Ada controlled types allow you to specify actions to be taken upon
initialization, adjustment, and finalization of a data element. These
actions effectively mimic many of the characteristics of C++
constructors and destructors.

Jim Rogers




  reply	other threads:[~2006-07-09 14:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-09 13:42 How to properly clean up an extended, generic structure? Peter C. Chapin
2006-07-09 14:29 ` jimmaureenrogers [this message]
2006-07-09 14:33 ` Ludovic Brenta
2006-07-09 16:21   ` Peter C. Chapin
2006-07-09 14:49 ` Björn Persson
2006-07-09 14:57 ` Georg Bauhaus
2006-07-09 19:46 ` Jeffrey R. Carter
2006-07-10  7:38   ` Jean-Pierre Rosen
replies disabled

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