From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Unconstrained Array ??
Date: 1999/08/10
Date: 1999-08-10T00:00:00+00:00 [thread overview]
Message-ID: <7oprdt$opl@hobbes.crc.com> (raw)
In-Reply-To: 934306216.27590.0.nnrp-10.c2de38ef@news.demon.co.uk
Duncan Woodward <drdw@synthsoft.demon.co.uk> wrote in message
news:934306216.27590.0.nnrp-10.c2de38ef@news.demon.co.uk...
> hi;
> I want to create a package that handles actions upon
> a multi dimensional unconstrained array.
>
> It is likely that I've approached this problem from the
> wrong direction, but this is where I'm at..
>
> package array_Handler is
>
> type Container_Matrix is array(POSITIVE range <>,
> POSITIVE range <>,
> POSITIVE range <>) of Boolean;
>
> procedure1 Set_Container_Size(x,y,z:Integer);
>
> -- this procedure takes in the three axis values for
> -- the array index ranges.
> -- Creates instance of Container_Matrix using parameters
> -- x,y,z.
>
> procedure2 ...etc
> procedure3 ...etc
>
> end array_Handler;
>
> PROBLEM: How do I create an instance of type Container_Matrix
> that is visible to all procedures in the package.
>
> A single global declaration would be fine if the array sizes were know
> in advance!
>
If you're going to have multiple subprograms accessing the same object,
it sounds like a candidate for a protected type.
Why not something like the following example?
package array_Handler is
type Matrix is array
(Positive range <>, Positive range <>, Positive range <>)
of Boolean;
protected type Container_Matrix
(X: Positive;
Y: Positive;
Z : Positive) is
procedure Action_2;
procedure Action_3;
private
The_Matrix : Matrix (1 .. X, 1 .. Y, 1 .. Z);
end Container_Matrix;
end array_Handler;
with Ada.Text_IO;
package body array_Handler is
----------------------
-- Container_Matrix --
----------------------
protected body Container_Matrix is
--------------
-- Action_2 --
--------------
procedure Action_2 is
begin
Ada.Text_IO.Put_Line
("Action_2: " &
"X range is" &
Positive'Image (The_Matrix'First (1)) & " .." &
Positive'Image (The_Matrix'Last (1)) & "; " &
"Y range is" &
Positive'Image (The_Matrix'First (2)) & " .." &
Positive'Image (The_Matrix'Last (2)) & "; " &
"Z range is" &
Positive'Image (The_Matrix'First (3)) & " .." &
Positive'Image (The_Matrix'Last (3)) & ".");
end Action_2;
--------------
-- Action_3 --
--------------
procedure Action_3 is
begin
Ada.Text_IO.Put_Line
("Action_3: " &
"X range is" &
Positive'Image (The_Matrix'First (1)) & " .." &
Positive'Image (The_Matrix'Last (1)) & "; " &
"Y range is" &
Positive'Image (The_Matrix'First (2)) & " .." &
Positive'Image (The_Matrix'Last (2)) & "; " &
"Z range is" &
Positive'Image (The_Matrix'First (3)) & " .." &
Positive'Image (The_Matrix'Last (3)) & ".");
end Action_3;
end Container_Matrix;
end array_Handler;
with Array_Handler;
procedure Test_Array_Handler is
The_Array : Array_Handler.Container_Matrix (3, 4, 5);
begin
The_Array.Action_2;
The_Array.Action_3;
end Test_Array_Handler;
prev parent reply other threads:[~1999-08-10 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-10 0:00 Unconstrained Array ?? Duncan Woodward
1999-08-10 0:00 ` Stephen Leake
1999-08-10 0:00 ` David C. Hoos, Sr. [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox