From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Run-Time Type Assignment
Date: Wed, 28 Aug 2002 18:53:29 GMT
Date: 2002-08-28T18:53:29+00:00 [thread overview]
Message-ID: <3D6D1C3C.884FAD77@acm.org> (raw)
In-Reply-To: mailman.1030549202.6278.comp.lang.ada@ada.eu.org
"Robert C. Leif" wrote:
>
> From: Bob Leif
> To: SK et al.
> How does your solution work, if the variants are:
> case Num_Parameters is
> when 1 =>
> Parameter_1: Parameter_1_Type;
> when 2 =>
> Parameter_1: Parameter_1_Type;
> Parameter_2: Parameter_2_Type;
> when 3 =>
> Parameter_1: Parameter_1_Type;
> Parameter_2: Parameter_2_Type;
> Parameter_3: Parameter_3_Type;
> end case;
> This is the equivalent of a tagged type.
One way is to make it a tagged type with a chain of types extended from
it. If you need/want to avoid tagged types, the composition equivalent
to type extension is to build up a bunch of record types, then combine
them in a variant record:
type Param_1_Data is record
Parameter_1 : Parameter_1_Type;
end record;
-- Further types may be in separate packages if desired
type Param_2_Data is record
Parent : Param_1_Data;
Parameter_2 : Parameter_2_Type;
end record;
type Param_3_Data is record
Parent : Param_2_Data;
Parameter_3 : Parameter_3_type;
end record;
type Any_Param_Data (Num_Params : Whatever) is record
case Num_Params is
when 1 =>
Parameter_1 : Param_1_Data;
when 2 =>
Parameter_2 : Param_2_Data;
when 3 =>
Parameter_3 : Param_3_Data;
end case;
end record;
Run-time dispatching is also easily implemented using this approach, and
is left as an exercise for the reader.
--
Jeff Carter
"I wave my private parts at your aunties."
Monty Python & the Holy Grail
next prev parent reply other threads:[~2002-08-28 18:53 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <002a01c24e5f$9ee347b0$789a0844@robertqgx6k4x9>
2002-08-28 11:33 ` Run-Time Type Assignment sk
[not found] ` <3D6CB4F5.F4E05D76@myob.com>
2002-08-28 11:37 ` sk
2002-08-28 15:39 ` Robert C. Leif
2002-08-28 18:53 ` Jeffrey Carter [this message]
2002-08-28 20:54 ` Robert C. Leif
2002-08-28 22:55 ` Robert A Duff
2002-08-29 3:18 ` Robert C. Leif
[not found] <005101c24ea9$0de9c960$789a0844@robertqgx6k4x9>
2002-08-28 16:06 ` sk
2002-08-28 22:44 ` tmoran
2002-08-29 0:37 ` tmoran
2002-08-28 6:53 Robert C. Leif
2002-08-28 11:04 ` Robert Dewar
2002-08-28 13:35 ` Robert A Duff
2002-08-28 14:56 ` Larry Kilgallen
2002-08-28 14:31 ` Robert A Duff
2002-08-28 14:59 ` Lutz Donnerhacke
2002-08-28 22:32 ` Robert A Duff
2002-08-29 22:55 ` Dmitry A.Kazakov
2002-08-28 18:03 ` Frank J. Lhota
2002-08-28 18:37 ` Pat Rogers
2002-08-28 22:47 ` Robert A Duff
2002-08-29 13:32 ` Ben Brosgol
2002-08-29 13:52 ` SIMON Claude
2002-08-29 14:30 ` Robert A Duff
2002-08-29 18:27 ` Randy Brukardt
2002-08-29 14:56 ` Robert A Duff
2002-08-30 3:04 ` Ben Brosgol
2002-08-30 22:54 ` Robert A Duff
2002-08-29 15:09 ` Larry Kilgallen
2002-08-29 14:29 ` Marin D. Condic
2002-08-28 13:41 ` Robert A Duff
2002-08-28 17:15 ` Hyman Rosen
2002-08-28 20:27 ` Björn Lundin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox