From: Alon Matas <amatas@classnet.co.il>
Subject: Help: Dynamic-size arrays using record discriminant.
Date: 1998/10/09
Date: 1998-10-09T00:00:00+00:00 [thread overview]
Message-ID: <361E3D0C.41AAC13B@classnet.co.il> (raw)
-- I have this problem:
-- There is a record with a discriminant (and a default value to the
-- discriminant). The record contains a constrained array, and the range
-- of the array depends on the discriminant. For example:
procedure PROBLEM is
type ARRAY_TYPE is array (INTEGER range <>) of NATURAL;
type RECORD_TYPE (SIZE: INTEGER:= 5) is
record
VECTOR: ARRAY_TYPE (1..SIZE);
end record;
-- Now, I have a variable with the record type:
REC: RECORD_TYPE;
TEMP: RECORD_TYPE; -- This variable will be explained later.
-- The question is how do I change the array size (i.e, the discriminant
-- value) WITHOUT loosing its current content.
-- For example, lets say it was filled with values:
begin
for I in REC.VECTOR'RANGE loop
REC.VECTOR(I):= I;
end loop;
-- Now the array contains the values 1, 2, 3, 4 and 5. Lets say I want
to
-- enlarge the array to 6 cells. Theoretically, I can do this:
REC:= (SIZE => 6, VECTOR => (1, 2, 3, 4, 5, 0));
-- But lets say I don't know the content of the first five cells (for
example,
-- they came from input). I must give SOME value to "VECTOR" (otherwise
it's
-- not a complete aggregate). Of course, I can do something like this:
REC:= (SIZE => 6, VECTOR => (others => 0));
-- ...but then I loose the original content of the array!
-- The only solution I could come up with is quite a shabby one. It goes
-- like this:
TEMP:= (SIZE => 6, VECTOR => (others => 0)); -- Copying
the original
-- array into a
-- temporary array.
TEMP.VECTOR(REC.VECTOR'RANGE):= REC.VECTOR; -- Enlarging the
-- original
-- array.
REC:= (SIZE => 6, VECTOR => TEMP.VECTOR); -- Copying the
temporary
-- array into the
-- original array.
-- It's working but it's ugly. Is there a better way?
-- If you have an idea, please help!
-- Thanks!
end PROBLEM;
next reply other threads:[~1998-10-09 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-09 0:00 Alon Matas [this message]
1998-10-11 0:00 ` Help: Dynamic-size arrays using record discriminant Niklas Holsti
1998-10-13 0:00 ` Robert I. Eachus
1998-10-16 0:00 ` Samuel Mize
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox