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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,b85c1b84f840dc22 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: I need a little help - it's been a long time - with enumeration type and for use representation Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <7495d29e-0361-4eba-9e22-a770ae50f113@d5g2000yqm.googlegroups.com> Date: Fri, 13 Nov 2009 18:24:36 +0100 Message-ID: NNTP-Posting-Date: 13 Nov 2009 18:24:31 CET NNTP-Posting-Host: 1b27d82c.newsspool3.arcor-online.net X-Trace: DXC=7EKN_MbAS3o9kIfcjg:0fdMcF=Q^Z^V3h4Fo<]lROoRa8kFo`eP>Le[6LHn;2LCVn[ On Fri, 13 Nov 2009 08:03:23 -0800 (PST), Harry Tucker wrote: > I have a piece of data which represents a enumeration as a hexadecimal > value. It is a bit field but I see the data most usefull as an > enumeration. for example in the CSV file the data is represented as > '0x1'. So I defined the enum as: > > > type Spell_School_Type is ( > UNKNOWN, > PHYSICAL, > HOLY, > FIRE, > ... > > > And since the data has a value I use a represetation clause as: > > for Spell_School_Type use > (UNKNOWN => 2#0000_0000#, > PHYSICAL => 2#0000_0001#, > HOLY => 2#0000_0010#, > FIRE => 2#0000_0100#, > ... > For bit fields modular types are better: type Spell_School_Type is mod 2**3; -- 3 is the number of independent bits Unknown : constant Spell_School_Type := 0; Physical : constant Spell_School_Type := 2**0; Holy : constant Spell_School_Type := 2**1; Fire : constant Spell_School_Type := 2**2; Any : constant Spell_School_Type := Spell_School_Type'Last; > Is the best way to parse the raw info (i.e. 0x1) into the enumeration > (i.e PHYSICAL) to use a if/elsif and assign the enum position or is > there an attribute which works best. You parse "0x", then you do a hexadecimal number following it, then you pass that number (x) to: Spell_School_Type'Val (x) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de