comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison<dennison@telepath.com>
Subject: Re: accesing internal codes used for an enumeration
Date: Mon, 07 May 2001 15:54:28 GMT
Date: 2001-05-07T15:54:28+00:00	[thread overview]
Message-ID: <UyzJ6.4576$vg1.356895@www.newsranger.com> (raw)
In-Reply-To: mailman.989244246.26083.comp.lang.ada@ada.eu.org

In article <mailman.989244246.26083.comp.lang.ada@ada.eu.org>, Marius Amado
Alves says...
>
>I am trying to implement a lexicon (in the database sense) as an
>enumeration with a representation clause.
>
>Example lexicon:
>
>  Name <-> Code
>  -------------
>  Ping      123
>  Pong      456
>
>Implementation:
>
>  type Names is (Ping, Pong);
>  for Names use (Ping => 123, Pong => 456);

What this does is tell the compiler to use 123 as the actual bit pattern that
represents "Ping" when it is stored in memory (or perhaps on disk). There is no
way to get at that value, short of converting it to something else in an
"unchecked" manner. 

If all you want to do is make force a specific bit pattern on those objects when
they are stored, then this is the way to do it. If instead you just want a
mapping that you can use internally in your program, you would probably be
better off doing something like the following:

type Names is (Ping, Pong);
type Name_Integer_Mapping is array (Names) of Integer;
Name_Map : constant Name_Integer_Mapping := (Ping => 123, Pong => 456);


---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



  parent reply	other threads:[~2001-05-07 15:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-07 16:03 accesing internal codes used for an enumeration Marius Amado Alves
2001-05-07 15:33 ` Jacob Sparre Andersen
2001-05-07 15:54 ` Ted Dennison [this message]
2001-05-08  3:51 ` Marc A. Criley
  -- strict thread matches above, loose matches on Subject: below --
2001-05-07 18:53 Beard, Frank
2001-05-08  5:56 ` Jacob Sparre Andersen
     [not found] <Pine.LNX.4.21.0105071543050.9145-100000@lux38>
2001-05-07 21:18 ` Marius Amado Alves
2001-05-10 18:45 Beard, Frank
replies disabled

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