comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert C. Leif" <rleif@rleif.com>
Subject: RE: Run-Time Type Assignment
Date: Wed, 28 Aug 2002 13:54:00 -0700
Date: 2002-08-28T13:54:00-07:00	[thread overview]
Message-ID: <mailman.1030568103.17788.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <3D6CB4F5.F4E05D76@myob.com>

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?
------------------------------------------------------
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;
------------------------------------------------------------------------
----
------------------------------------------------------------------------
----
generic
   Length : Positive;  
   type Record_Type is private; 
package Array_Of_Records_G_Pkg is
   type Array_Of_Records_Type is array (1 .. Length) of Record_Type; 
   ------------------------------------------------------------
   --Sets the value of an individual record in the array
   procedure Set_Record (
         Array_Of_Records : in out Array_Of_Records_Type; 
         Index            : in     Positive;              
         Record_Var       : in     Record_Type            ); 
   ------------------------------------------------------------
   --Retrieves a record from the array.
   function Get_Record (
         Array_Of_Records : in     Array_Of_Records_Type; 
         Index            : in     Positive               ) 
     return Record_Type; 
   ------------------------------------------------------------
end Array_Of_Records_G_Pkg;
------------------------------------------------------------------------
----
------------------------------------------------------------------------
----
with Parameter_Recs_Pkg;
with Array_Of_Records_G_Pkg;
procedure Test is 
   ---------Table of Contents----------
   subtype Num_Paras_Type is Parameter_Recs_Pkg.Num_Paras_Type;
   subtype Para_Rec_Psuedo_Tagged_Type is
Parameter_Recs_Pkg.Para_Rec_Psuedo_Tagged_Type;
   --------End Table of Contents----------
   Num_Of_Records : Positive       := 5;  
   Num_Paras      : Num_Paras_Type := 2;  
   type Array_Record_Type is new Para_Rec_Psuedo_Tagged_Type 
         (Num_Paras); 
   ---------------------------------------------------
   package Array_Of_Records_Pkg is new Array_Of_Records_G_Pkg(
      Length      => Num_Of_Records,   
      Record_Type => Array_Record_Type);
   ---------------------------------------------------
begin --Test
   null;
end Test;




  parent reply	other threads:[~2002-08-28 20:54 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
2002-08-28 20:54   ` Robert C. Leif [this message]
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