comp.lang.ada
 help / color / mirror / Atom feed
From: okellogg <okellogg@freenet.de>
Subject: Re: Generalized serialization for enumeration types
Date: Wed, 26 Aug 2009 05:03:55 -0700 (PDT)
Date: 2009-08-26T05:03:55-07:00	[thread overview]
Message-ID: <223e58cf-97d2-4db6-aa26-a5dc0d2b5056@m38g2000yqh.googlegroups.com> (raw)
In-Reply-To: 2b55b138-5827-480c-8095-256ad1b7e205@e27g2000yqm.googlegroups.com

On 26 Aug., 13:33, xorque <xorquew...@googlemail.com> wrote:
> On Aug 26, 11:00 am, okellogg <okell...@freenet.de> wrote:
>
> > If your enums are represented as you describe then why do you need
> > representations?
> > You could rely on the natural Ada representation (which happens to
> > conform with your encoding rules as far as the enum values are
> > concerned).
>
> Erm. Where in the (2005) RM does it state that enums are encoded
> at big-endian 32 bit integers?
>

Perhaps I am misunderstanding - I thought along following lines:

-- file: enum_to_big_endian_unsigned32.ads
with Interfaces;
generic
   type Enum_Type is (<>);
function Enum_To_Big_Endian_Unsigned32 (Value : Enum_Type)
         return Interfaces.Unsigned_32;

-- file: enum_to_big_endian_unsigned32.adb
function Enum_To_Big_Endian_Unsigned32 (Value : Enum_Type)
         return Interfaces.Unsigned_32 is
   function htonl (host_int : Interfaces.Unsigned_32)
                   return Interfaces.Unsigned_32;
   pragma Import (C, htonl, "htonl");
begin
   return htonl (Enum_Type'Pos (Value));
end Enum_To_Big_Endian_Unsigned32;


-- file: enum2u32_test.adb - Test Main Program
with Interfaces;
with Enum_To_Big_Endian_Unsigned32;

procedure Enum2U32_Test is

   type Color_T is (Red, Green, Blue);

   function To_U32 is new Enum_To_Big_Endian_Unsigned32 (Color_T);

   Result : Interfaces.Unsigned_32 := To_U32 (Green);

begin
   -- application code ...
   null;
end;





  reply	other threads:[~2009-08-26 12:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26 10:22 Generalized serialization for enumeration types xorque
2009-08-26 11:00 ` okellogg
2009-08-26 11:33   ` xorque
2009-08-26 12:03     ` okellogg [this message]
2009-08-26 11:17 ` Georg Bauhaus
2009-08-26 11:35   ` xorque
2009-08-26 12:05 ` Dmitry A. Kazakov
2009-08-26 19:44 ` Jeffrey R. Carter
2009-08-27  5:05 ` sjw
2009-08-28 10:47   ` xorque
replies disabled

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