comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: containers and garbage collections.
Date: Sat, 13 Sep 2003 17:10:45 GMT
Date: 2003-09-13T17:10:45+00:00	[thread overview]
Message-ID: <u4qzgbokl.fsf@earthlink.net> (raw)
In-Reply-To: 23635057.dHrhOAZpeb@linux1.krischik.com

Martin Krischik <krischik@users.sourceforge.net> writes:

> Matthew Heaney wrote:
> 
> > Both of these containers are possible using the single declaration:
> > 
> > generic
> >    type Element_Type (<>) is private;
> > package GP is ...;
> > 
> > You can instantiate GP using either of the types in your example.  It's
> > not clear why you made two separate containers, one for tagged types
> > vs. another for array types, as a single container seems adequate.
> 
> Will it work with any combination of tagged types incl. controled types any
> derived types of Element_Type? If so I stay corrected and will rething my
> design.

Yes, it will work for any combination of tagged type.  All you need to
do is specify T'Class as the generic actual:

package P is new GP (T'Class);

This works becuase of Ada's built-in cloning facility.  So when you say

  X : Element_Access := new Element_Type'(Item);

this means

  X : T_Class_Access := new T'Class'(Item);

and now X designates a copy of Item, having the same type tag as Item.

When you query the item, just do this:

  E : T'Class := Top (Q);

This makes a copy of the (indefinite) element at the front of the queue.

If you want to be able to dispatch on the tag of an item in the
container, without having to make a copy of item, then you can expose
the internal pointer:

   E : constant Element_Access := Top_Access (Q);
begin
   Op (E.all);  --dispatch





  reply	other threads:[~2003-09-13 17:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-12 15:32 containers and garbage collections Martin Krischik
2003-09-12 16:41 ` Stephen Leake
2003-09-13  9:37   ` Martin Krischik
2003-09-13  3:33 ` Matthew Heaney
2003-09-13  9:45   ` Martin Krischik
2003-09-13 17:10     ` Matthew Heaney [this message]
2003-09-15 13:47     ` Dmitry A. Kazakov
2003-09-15 23:11       ` Matthew Heaney
2003-09-16 17:59         ` Martin Krischik
replies disabled

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