From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,330ec86e1824a689 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-28 15:56:13 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Run-Time Type Assignment Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Wed, 28 Aug 2002 22:55:12 GMT References: NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:28534 Date: 2002-08-28T22:55:12+00:00 List-Id: "Robert C. Leif" writes: > From: Bob Leif > From: Bob Leif > To: Fellow Readers of Comp.Lang.Ada > Firstly, thanks to all who suggested implementations. I now have a > solution based on the Example from Norman Cohen's Ada as a second > language page 377. > The two pages and main procedure below compile. Unfortunately, type > Para_Rec_Psuedo_Tagged_Type is brute force approach. Does anyone have a > simpler implementation? In this case, all the "Para"'s are of type Positive, so you could make an array inside the record, bounds 1..Num_Paras. You lose some range checking, unfortunately. If the types were not all the same type, then *make* them be all of the same type by the usual methods (pointer to class-wide, pointer to variant record, etc). > ------------------------------------------------------ > package Parameter_Recs_Pkg is > subtype Para_1_Type is Positive range 1..64_000; > subtype Para_2_Type is Positive range 1..256; > subtype Para_3_Type is Positive range 1..1024; > subtype Para_4_Type is Positive range 1..2048; > subtype Para_5_Type is Positive range 1..4096; > > subtype Num_Paras_Type is Positive range 1..5; > Num_Paras : Num_Paras_Type := 1; > > type Para_Rec_Psuedo_Tagged_Type (Num_Paras :Num_Paras_Type) is > record > Para_1 : Para_1_Type; --Always has one parameter > case Num_Paras is > when 1 => > null; > when 2|3|4|5 => > Para_2 : Para_2_Type; > case Num_Paras is > when 1|2 => > null; > when 3|4|5 => > Para_3 : Para_3_Type; > case Num_Paras is > when 1|2|3 => > null; > when 4|5 => > Para_4 : Para_4_Type; > case Num_Paras is > when 1|2|3|4 => > null; > when 5 => > Para_5: Para_5_Type; > end case; > end case; > end case; > end case; > end record; > end Parameter_Recs_Pkg; - Bob