comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: ??? Help!: how to do unconstraned arrays/records???
Date: 1998/11/05
Date: 1998-11-05T00:00:00+00:00	[thread overview]
Message-ID: <F1yDsB.Lry.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: F1xI6L.8Dy.0.-s@inmet.camb.inmet.com

Tucker Taft (stt@houdini.camb.inmet.com) wrote:

: 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.

: How about:
: ...

My initial solution was more complicated than it needed to be.

Simpler is to introduce the level of indirection directly in the 
Node_Array, as follows:

 type Host_Config_Typ is
    record
      ID        : Integer;
      Label     : String;
    end record;

  type Host_Array is array (Positive range <>) of Host_Config_Typ;

  type Node_Config_Typ(Number_Of_Hosts_Widgets : Natural) is
    record
      ID              : integer;
      Label           : String;
      Number_of_hosts : Natural := 0;
      Hosts           : Host_Array(1..Number_Of_Hosts_Widgets);
    end record;

  type Node_Config_Ptr is access Node_Config_Type;

  type Node_Array is array (Positive range <>) of Node_Config_Ptr;

  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 => new 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);

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




  parent reply	other threads:[~1998-11-05  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-04  0:00 ??? Help!: how to do unconstraned arrays/records??? al johnston
1998-11-04  0:00 ` Albert S. Johnston
1998-11-05  0:00   ` dewarr
1998-11-05  0:00     ` al johnston
1998-11-05  0:00       ` Stephen Leake
1998-11-05  0:00       ` dewar
1998-11-05  0:00 ` Tucker Taft
1998-11-05  0:00   ` Tucker Taft
1998-11-05  0:00     ` al johnston
1998-11-05  0:00   ` Tucker Taft [this message]
1998-11-05  0:00     ` Mats Weber
1998-11-05  0:00       ` Tucker Taft
1998-11-05  0:00         ` al johnston
1998-11-05  0:00           ` Tucker Taft
1998-11-06  0:00             ` Mats Weber
1998-11-06  0:00               ` Tucker Taft
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox