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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3c37d6ac44550e08 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: ??? Help!: how to do unconstraned arrays/records??? Date: 1998/11/05 Message-ID: #1/1 X-Deja-AN: 408534967 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <36407C96.731EEB90@avionics2.robins.af.mil> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-11-05T00:00:00+00:00 List-Id: al johnston (johnstona@avionics2.robins.af.mil) wrote: : HELP!!!! : I a trying to convert the following "static" ada data : structure to a structure that can be created dynamically, : ie via the "new" ada function, and setting the two : constrants at that time. : I can not seem to find anything that will work (as : far as type declarations) short of : moving the second level array (Host_array) into : the top level structure (system_config_type) and : making it 2d. That is TOO ugly!!!! : Can one of you ada guru's help me out? : the current type definitions (ie the "static" : version) are below.... : thanks!!!! : -al : ------------------------------------------------------------- : NUMBER_OF_HOST_WIDGETS : Integer := some bound; : NUMBER_OF_NODE_WIDGETS : Integer := some other bound; : type Host_Config_Typ is : record : ID : Integer; : Label : String; : end record; : type Host_Array is array (natural range <>) of Host_Config_Typ; : type Node_Config_Typ is : record : ID : integer; : Label : String; : Number_of_hosts : Natural := 0; : Hosts : Host_Array(1..NUMBER_OF_HOSTS_WIDGETS); : end record; : type Node_Array is array (natural rangee <>) of Node_Config_Typ; : type System_Config_Typ is : record : Number_of_nodes : Natural := 0; : Nodes : Node_Array(NUMBER_OF_NODE_WIDGETS); : end record; : Config : System_Config_Typ; How about: type Host_Config_Typ is record ID : Integer; Label : String; end record; type Host_Array is array (Positive range <>) of Host_Config_Typ; type Host_Array_Ptr is access Host_Array; type Node_Config_Typ(Number_Of_Hosts_Widgets : Natural := 0) is record ID : integer; Label : String; Number_of_hosts : Natural := 0; Hosts : Host_Array_Ptr := new Host_Array(1..Number_Of_Hosts_Widgets); end record; type Node_Array is array (Positive range <>) of Node_Config_Typ; type System_Config_Typ(Number_Of_Node_Widgets : Natural; Number_Of_Hosts_Widgets : Natural) is record Number_of_nodes : Natural := 0; Nodes : Node_Array(1..Number_Of_Node_Widgets) := (others => Node_Config_Typ(Number_Of_Hosts_Widgets)); end record; type System_Config_Typ_Ptr is access System_Config_Typ; Now you can create a heap-resident structure as follows: X : System_Config_Typ_Ptr := new System_Config_Typ(Num_Nodes, Num_Hosts); Admittedly, there is an extra level of indirection to get to each Host_Array, but that's the canonical solution to any software engineering problem! -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA An AverStar Company