From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32ba5f24e70f4e55 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-07 11:55:07 PST Path: newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "Beard, Frank" Newsgroups: comp.lang.ada Subject: RE: accesing internal codes used for an enumeration Date: Mon, 7 May 2001 14:53:20 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: avanie.enst.fr 989261706 3583 137.194.161.2 (7 May 2001 18:55:06 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Mon, 7 May 2001 18:55:06 +0000 (UTC) To: "'comp.lang.ada@ada.eu.org'" Return-Path: X-Mailer: Internet Mail Service (5.5.2448.0) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.3 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: newsfeed.google.com comp.lang.ada:7281 Date: 2001-05-07T14:53:20-04:00 I'm not sure where it is, other than the description of enumerated types. Since enumerated types map to an underlying integer representation, your Uncheck_Conversion will be from the enumerated type to an integer type (defined large enough to hold the all the possible numbers). If you wanted to be lazy, you could take the basic Standard Integer (-2**32-1 .. (2**32-1) - 1). In which case, you would have the following: type Names is (Ping, Pong); for Names use (Ping => 123, Pong => 456); function To_Integer is new Ada.Unchecked_Conversion(Source => Names, Target => integer); name : Names := Names'first; x : integer := 0; begin x := To_Integer(name); -- x is now 123 Hope this helps. Frank -----Original Message----- From: Marius Amado Alves [mailto:alves@systran.lu] Sent: Monday, May 07, 2001 12:03 PM To: comp.lang.ada@ada.eu.org Subject: accesing internal codes used for an enumeration 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); I found out the hardway that attribute Pos does not return the internal code. The ARM says this at 13.4(11), and tells you to use Unchecked_Conversion instead--but does not instruct you on the types of the conversion. Where might one learn that? Thanks. /* The point of a lexicon is to access its elements by either key. I expect the implementation above would be eficient. It is already simple to declare/define. The alternative is of course to use arrays, but then a search procedure is needed. I also wanted to avoid this complication. */ -- Marius Amado Alves alves@systran.lu Project Tradaut-Pt Systran Luxembourg 12, Rue de Vianden L-2680 LUXEMBOURG Tel 352 + 45 46 53 Fax 352 + 45 74 75 Mob 351 +939354002 _______________________________________________ comp.lang.ada mailing list comp.lang.ada@ada.eu.org http://ada.eu.org/mailman/listinfo/comp.lang.ada