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,e5dc20115bb61aec X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Generalized serialization for enumeration types 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: <249a69e5-8e21-4968-a183-64732618660a@h21g2000yqa.googlegroups.com> Date: Wed, 26 Aug 2009 14:05:19 +0200 Message-ID: NNTP-Posting-Date: 26 Aug 2009 14:05:20 CEST NNTP-Posting-Host: 339fa055.newsspool3.arcor-online.net X-Trace: DXC=G\4D3QbA1[CgMQ00McF=Q^Z^V384Fo<]lROoR1^YC2XCjHcb9LT1Ca=D7GD;DNcfSJ;bb[5FCTGGVUmh?4LK[5LiR>kg2H^<>5=A]Oa9 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7990 Date: 2009-08-26T14:05:20+02:00 List-Id: On Wed, 26 Aug 2009 03:22:08 -0700 (PDT), xorque wrote: > I'm designing a package that uses a lot of similar but distinct > enumeration types. > > At some point, those types need to be encoded to be sent over > the wire. The encoding rules are simple: > > The enumeration values are converted to unsigned 32 bit > integers with the first value as 0 and increasing sequentially > with each new value. The 32 bit value is packed into big-endian > byte order. We are using a chain code for same purpose. It is better for shorter values and is not limited from above. > The problem is: With so many enumeration types, I now have about 300 > lines of almost identical procedures (to be used as stream attributes) > that just call a procedure that packs Unsigned_32 values into > Storage_Element arrays. You can read/write Enumeration_Type'Pos (Value), instead, which is how we deal with this. The same will work with other discrete types. > Is there some clever way I can just write ONE 'Write attribute procedure > and ONE 'Read attribute procedure and have all the defined enumeration > types use those? No, because there is no common ancestor for these types. Another technique we are using is that there are "comm" values of tagged types rooted in the same abstract parent, while Get and Set operations are provided to get/set a type-specific non-tagged value from/to. But in this case, obviously, Get and Set must be implemented for each specific type new. Generic packages are used for that, which then leads to a geometric explosion of instances and an utter mess, as always when you deal with generics. > Freezing rules prevented me from writing a generic > Packed_Enumeration_IO > package ("representation item appears too late"). I don't understand why. It works to us, however as I said above, a generic solution is always bad, unless there is no any alternative. So far Ada does not provide alternatives (like ad-hoc supertypes and interfaces etc). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de