From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: array of generic packages?
Date: 22 Sep 2004 19:30:07 -0400
Date: 2004-09-22T19:30:07-04:00 [thread overview]
Message-ID: <mailman.66.1095895815.390.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <4151be92@dnews.tpgi.com.au>
"a malkiel" <malkiel@wannet.net> writes:
> hi im somewhat new to ada. i've been trying to nut this one but can't seem
> to. Would anyone know if defining an "array of generic packages" is
> possible? What im looking for is something of the nature:
>
> type shape_type is (circle, triangle);
> package shapePointer(1) is new shape(circle);
> package shapePointer(2) is new shape(triangle);
This is not directly possible.
But perhaps you are looking for tagged types:
type Shape_Type is tagged abstract limited private;
type Shape_Access_Type is access all Shape_Type;
procedure Draw (Item : in Shape_Type);
type Circle_Type is new Shape_Type with private;
procedure Draw (Item : in Circle_Type);
function New_Circle (Radius : in Float) return Shape_Access_Type;
type Triangle_Type is new Shape_Type with private;
procedure Draw (Item : in Triangle_Type);
function New_Triangle (A, B, C : in Float) return Shape_Access_Type;
Then you can do things like:
type Shape_Array_Type is array (...) of Shape_Access_Type;
My_Shapes : Shape_Array_Type :=
(New_Circle (2.0),
New_Triangle (3.0, 4.0, 5.0));
for I in My_Shapes'range loop
Draw (My_Shapes (I).all);
end loop;
If that's not what you want, perhaps you could say more about what you
do want, and we could talk about how to do it "the Ada way".
--
-- Stephe
next prev parent reply other threads:[~2004-09-22 23:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-22 18:03 array of generic packages? a malkiel
2004-09-22 18:26 ` Ludovic Brenta
2004-09-23 2:19 ` a malkiel
2004-09-22 23:30 ` Stephen Leake [this message]
2004-09-23 2:15 ` a malkiel
2004-09-24 12:39 ` Peter Hermann
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox