From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Type detection
Date: Fri, 30 Apr 2004 13:54:31 GMT
Date: 2004-04-30T13:54:31+00:00 [thread overview]
Message-ID: <rUskc.57669$mU6.235826@newsb.telia.net> (raw)
In-Reply-To: <409243DA.2000906@noos.fr>
Axel Druesnes wrote:
> i am currently writing a generic package. Despite being really generic
> one (at least) particular type need a special handling in two functions.
> I am therefore wondering how i can either detect the type...
[...]
> function Type_Id ( Value : in Boolean ) return E_Type_Id;
> function Type_Id ( Value : in Integer ) return E_Type_Id;
>
> -- Inside the body
> procedure I_Need_The_Type ( Value : Generic_Type )
> ....
> Type_Identifier := Type_Id ( Value ); -- i wish it worked here
For the special case of distinguishing integer types from enumeration
types, I've been thinking of using something like this:
if Ada.Characters.Handling.Is_Letter
(Generic_Type'Image(Generic_Type'First)(1)) then
-- It's an enumeration.
else
-- It's an integer type.
end if;
Further tests could be done to see if an enumeration is Boolean or
something else.
For more general cases, since the type is known when you instantiate the
generic package, maybe you can pass an extra parameter (of type
E_Type_Id)? Or you could keep the common parts in one highly generic
package and then have a number of more specific generic packages for
different types. The more specific packages would then instantiate the
highly generic package and call the common subprograms in it.
--
Björn Persson
jor ers @sv ge.
b n_p son eri nu
next prev parent reply other threads:[~2004-04-30 13:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-30 12:17 Newbie Ada Axel Druesnes
2004-04-30 12:22 ` Preben Randhol
2004-04-30 13:20 ` Hyman Rosen
2004-04-30 13:54 ` Björn Persson [this message]
2004-04-30 15:04 ` Type detection Marius Amado Alves
2004-05-01 0:28 ` Robert I. Eachus
2004-05-01 5:01 ` James Rogers
2004-05-01 7:12 ` Robert I. Eachus
2004-05-01 12:43 ` Björn Persson
2004-05-01 12:42 ` Björn Persson
2004-04-30 14:49 ` Newbie Ada Lutz Donnerhacke
2004-05-02 13:33 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox