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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e8cf506f89b5d0a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-19 19:58:04 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!enews.sgi.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: <9god9a$g04$0@208.164.98.151> Subject: Re: Looping over a tagged record? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: <%iUX6.205163$p33.4184632@news1.sttls1.wa.home.com> Date: Wed, 20 Jun 2001 02:58:03 GMT NNTP-Posting-Host: 24.248.45.203 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 993005883 24.248.45.203 (Tue, 19 Jun 2001 19:58:03 PDT) NNTP-Posting-Date: Tue, 19 Jun 2001 19:58:03 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:8908 Date: 2001-06-20T02:58:03+00:00 List-Id: I'll share a couple of idea's to explore: Idea 1) Instead of defining the fields of the record as String_60, Integer, etc.. Define each field as a descendent of a common object. In addition to the data fields, add an array of references to the fields. Something along the lines of: type Field_Type is abstract tagged private; type Field_Type_Acc is access all Field_Type; type String_Field is new Field_Type with private; type Integer_Field is new Field_Type with private; type Field_List is array( Positive range <> ) of Field_Type_Acc; type Big_Record is tagged record A1 : aliased String_Field; A2 : aliased String_Field; N1 : aliased Integer_Field; Field_References : Field_List(1..3); end record; Then at some point initialize "Field_References" to point to the fields within the same object. If Big_Record is derived from Ada.Finalization, then Field_References may be initialized automatically. Idea 2) Keep your existing record definition, but define each field as aliased. Then create a list of objects where again each object descends from the same base class, only now each different object contains a reference to each of the field types. Both of these approaches use the same basic theme of setting up an array that gives you access to all elements using a common base class. I believe both of these approaches are "workable" but neither is particularly elegant or pretty. I hope this helps, SteveD "M R Goodwin" wrote in message news:9god9a$g04$0@208.164.98.151... > Hi! > > This is a part practical, and a part 'I wonder' type problem. > I have a tagged record that is pretty big. Most, but not all of > the elements in it are a bounded string type. Because I don't feel > like the typing and all I would need to do to assign and later change > values, I was wondering if there is anyway to loop over all elements in > the record, checking their type and then taking the right action... > > type Big_record is tagged record > a1 : String_60; > a2 : String_60; > n1 : Integer; > ... > a30 : String_60; > end record; > > And I want to do something like: > (And yes, I know its not Ada code!) > For I in ?number of elements? loop > if I is Integer then Blah, blah > elsif I is String_60 Blah, Blah. > end; > > > I've been messing around with it, and have not come to any workable > solution. > > Thanks for the help, > > Matthew