From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Variant Record Component
Date: Sat, 01 Mar 2003 02:34:28 GMT
Date: 2003-03-01T02:34:28+00:00 [thread overview]
Message-ID: <3E601C1A.3000405@acm.org> (raw)
In-Reply-To: 3E5F8B38.EE7AE76F@boeing.com
John Harbaugh wrote:
>
> My question has more to do with understanding what language-level tools
> that are available. Ada is pretty slick at testing membership of a
> value within/without a subtype range. I was wondering if there was
> something analogous for variant records. I'm getting the impression
> that the answer is no. Yes?
No. Subtype membership is defined for all types. For a variant record
type, you can say
type Disc is (Alpha, Bravo, Charlie);
type Variant (D : Disc) is record
case D is
when Alpha =>
...
...
end case;
end record;
subtype Variant_Alpha is Variant (D => Alpha);
V : Variant := Some_Function;
...
if V in Variant_Alpha then
This will work if you've done a good design, and each Disc value has its
own variant part. If most of the variant parts have multiple
discriminant values then this is less useful.
I once saw a project (Ada 83, pre 1995) that had problems because they'd
done something like
type Disc is range 1 .. 100;
type Variant (D : Disc) is record
case D is
when 1 .. 10 =>
...
when 11 .. 20 =>
...
...
end case;
end record;
What they really had was a set of about 10 main classes, each of which
had a specific ID for one of about 10 specific things. What they should
have done was something like
type Disc is (One, Two, ..., Ten);
type ID_One is (One_One, One_Two, ..., One_Ten);
type ID_Two is (Two_One, Two_Two, ..., Two_Ten);
...
type ID_Ten is (Ten_One, Ten_Two, ..., Ten_Ten);
-- The project would have had more meaningful names,
-- but since it was a classified project I can't tell
-- you what they would have been.
type Variant (D : Disc) is record
case D is
when One =>
One_ID : ID_One;
...
when Two =>
Two_ID : ID_Two;
...
...
end case;
end record;
--
Jeff Carter
"C++ is like giving an AK-47 to a monk, shooting him
full of crack and letting him loose in a mall and
expecting him to balance your checking account
'when he has the time.'"
Drew Olbrich
next prev parent reply other threads:[~2003-03-01 2:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-26 18:00 Variant Record Component John Harbaugh
2003-02-26 19:08 ` Stephen Leake
2003-02-27 8:17 ` Anders Wirzenius
2003-02-27 8:46 ` John McCabe
2003-02-27 17:26 ` phone number database Stephen Leake
2003-02-27 18:09 ` tmoran
2003-02-28 0:07 ` Matthew Heaney
2003-02-28 6:46 ` Hijacking threads (was phone number database (was Variant Record Component)) Anders Wirzenius
2003-02-26 20:50 ` Variant Record Component David C. Hoos
2003-02-28 16:15 ` John Harbaugh
2003-02-28 18:18 ` tmoran
2003-02-28 22:07 ` John Harbaugh
2003-02-28 20:51 ` Randy Brukardt
2003-03-01 2:34 ` Jeffrey Carter [this message]
2003-03-03 9:24 ` John McCabe
2003-02-26 21:37 ` tmoran
-- strict thread matches above, loose matches on Subject: below --
2003-02-28 19:40 David C. Hoos
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox