From: "Rodrigo Garcia" <rodrigo.garcia@epfl.ch>
Subject: Re: How to define an array of a variant record type?
Date: Mon, 17 Nov 2003 19:45:00 +0100
Date: 2003-11-17T19:45:00+01:00 [thread overview]
Message-ID: <3fb91731$1@epflnews.epfl.ch> (raw)
In-Reply-To: BBDEBC6C.902D%office@anobject.net
"Harald Schmidt" <office@anobject.net> wrote in message
news:BBDEBC6C.902D%office@anobject.net...
> Hi,
>
> I would like to define an array, which its element type is a variant
record
> and the Value_Type is only known at runtime.
>
> type Name_Value_Type is (String_Type,
> Integer_Type,
> Float_Type);
>
> type Name_Value(Value_Type : Name_Value_Type) is
> record
> The_Name : Unbounded_String;
> case Value_Type is
> when String_Type =>
> String_Value : Unbounded_String;
> when Integer_Type =>
> Integer_Value : Integer;
> when Float_Type =>
> The_Value : Float;
> end case;
> end record;
>
> type Name_Value_Sequence is array(Natural range <>) of Name_Value;
>
> The compiler says "unconstrained element type in array declaration",
> ...right!
>
> I know Ada is a strong typed language, but sometimes information is only
at
> runtime available. Does anyone know some workaround, or a regulare design
> pattern for this problem?
>
> Harald
I would use "Indirection": Use an array of _accesses_ to the variant record.
type Name_Value_Ptr is access Name_Value;
type Name_Value_Sequence is array (Natural range <>) of Name_Value_Ptr;
Rodrigo
next prev parent reply other threads:[~2003-11-17 18:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-17 16:57 How to define an array of a variant record type? Harald Schmidt
2003-11-17 17:35 ` Stephen Leake
2003-11-20 10:02 ` Craig Carey
2003-11-17 17:37 ` Marius Amado Alves
2003-11-18 2:48 ` Steve
2003-11-18 9:04 ` Marius Amado Alves
2003-11-17 18:45 ` Rodrigo Garcia [this message]
2003-11-18 2:48 ` Steve
2003-11-18 17:48 ` Nick Roberts
2003-11-19 2:38 ` Steve
2003-11-19 8:11 ` Preben Randhol
2003-11-19 13:26 ` Rodrigo Garcia
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox