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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,514627f9964b6e38,start X-Google-Attributes: gid103376,public From: "Marin David Condic, 561.796.8997, M/S 731-96" Subject: Using the GNAT defined attribute: 'Enum_Rep Date: 1997/08/27 Message-ID: <97082719523509@psavax.pwfl.com>#1/1 X-Deja-AN: 269974238 Sender: Ada programming language Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU X-VMS-To: SMTP%"INFO-ADA@VM1.NODAK.EDU" X-VMS-Cc: CONDIC Newsgroups: comp.lang.ada Date: 1997-08-27T00:00:00+00:00 List-Id: Here's a little problem which I could use some help handling: I get external data for my program which is extracted from the internal representation of an enumerated type. That is to say, I'm getting integers which correspond to the representation clause of the enumerated type, not the position. On input, they are read as integers and I'd like to convert them to the enumerated type. The ARM suggests using Unchecked_Conversion to get from here to there, but now you've got to create an integer type that is the same size as the enumerated type. Here's a code fragment: -- type Temp_Integer is range Integer'First..Integer'Last ; for Temp_Integer'Size use User_Types.CL_Evt_Status'Size ; --^^^^^^^^^^^^^^^^^^^^^^ The enumerated type. function CVT_Evt_Status is new Ada.Unchecked_Conversion ( Source => Temp_Integer ; Target => User_Types.CL_Evt_Status) ; You can now use the CVT_Evt_Status function to get from the external integer to the internal representation. However, the declaration of Temp_Integer might not work because you don't know that the 'Size of the enumerated type is big enough for the range. You can easily build a custom one-off that will work if you know enough about the type and it's representation, but it would be nicer to have a general solution which will work for any enumerated type & representation. GNAT is nice enough to provide the attribute: 'Enum_Rep which returns a Universal_Integer of the internal representation of an enumerated object. (I'm surprised this isn't standard!) This is a great answer when I'm writing the data out - all I've got to worry about is that the enumeral doesn't create a constraint_error when assigned to an integer object for output. What I'd like is a corresponding "'Integer_Rep" (or some other more appropriate name) attribute which converted from a Universal_Integer to the internal representation of the enumerated type - risking only Constraint_Error if the integer is not a member of the representation set. Has anyone got a suggestion as to how this can be done more elegantly with some other attributes or Unchecked_Conversion? I don't see any simple way to do this. (Please don't suggest 'Pos and 'Val. These will work If and only if the representation is identical to the position numbers - what you get if you don't specify a representation. What I've got are representations with gaps in them.) Thanks for any suggestions you have to offer. MDC Marin David Condic, Senior Computer Engineer ATT: 561.796.8997 Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600 Fax: 561.796.4669 West Palm Beach, FL, 33410-9600 Internet: CONDICMA@PWFL.COM =============================================================================== "I saw a bank that said "24 Hour Banking", but I don't have that much time." -- Steven Wright ===============================================================================