comp.lang.ada
 help / color / mirror / Atom feed
From: "DuckE" <nospam_steved94@home.com>
Subject: Re: Looping over a tagged record?
Date: Wed, 20 Jun 2001 02:58:03 GMT
Date: 2001-06-20T02:58:03+00:00	[thread overview]
Message-ID: <%iUX6.205163$p33.4184632@news1.sttls1.wa.home.com> (raw)
In-Reply-To: 9god9a$g04$0@208.164.98.151

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" <mgoodwinSPAMMY@redrocketconsortium.com> 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





  parent reply	other threads:[~2001-06-20  2:58 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-19 20:39 Looping over a tagged record? M R Goodwin
2001-06-19 21:31 ` Pascal Obry
2001-06-19 21:32 ` Pascal Obry
2001-06-19 22:20   ` Samuel T. Harris
2001-06-19 23:45     ` mgoodwinSPAMMY
2001-06-20  1:33 ` Pat Rogers
2001-06-20  3:13   ` Pat Rogers
2001-06-20  2:58 ` DuckE [this message]
2001-06-20 13:15 ` Ted Dennison
2001-06-20 15:01   ` M. A. Alves
2001-06-21  2:36     ` DuckE
2001-06-21 10:14       ` M. A. Alves
2001-06-21 13:24         ` Pat Rogers
2001-06-21 17:08     ` Charles Hixson
2001-06-21 18:58       ` tmoran
2001-06-21 23:02         ` Charles Hixson
2001-06-22 19:04           ` B.Gaffney
2001-06-22 20:36             ` Pascal Obry
2001-06-22  2:18       ` DuckE
2001-06-22 17:33         ` Charles Hixson
2001-06-22 18:24           ` tmoran
2001-09-13  0:29           ` Gnat Windows load error tmoran
2001-09-13 18:15             ` Jerry van Dijk
2001-09-13 23:17               ` tmoran
2001-09-13  3:58           ` Ada web crawler tmoran
2001-11-17 21:50           ` ada.strings.bounded slice errors tmoran
2001-11-18 17:16             ` Florian Weimer
2001-11-18 19:31               ` tmoran
2001-11-19  7:12                 ` Florian Weimer
2002-02-08 20:55           ` How to get a traceback in Gnat 3.14p tmoran
2002-02-08 21:24             ` Pascal Obry
2002-02-08 22:28               ` tmoran
2002-02-11  0:10           ` How to use gnatelim in Gnat 3.14p? tmoran
2002-02-15 17:23           ` does gnatelim work? tmoran
2002-02-15 18:18             ` Stephen Leake
2002-02-15 21:58               ` tmoran
2002-02-18  1:31                 ` Stephen Leake
2002-04-15  3:05           ` Announce: .rc files with Gnat tmoran
2002-04-15 14:48             ` Ted Dennison
2002-05-25  7:06           ` slice'access? tmoran
2002-05-25 16:47             ` slice'access? Robert Dewar
2002-05-25 18:28               ` slice'access? tmoran
2002-05-25 20:20                 ` slice'access? Jeffrey Carter
2002-05-25 23:39                   ` slice'access? tmoran
2002-05-26 14:22                     ` slice'access? Robert Dewar
2002-09-30  1:54           ` 'write of bounded string? tmoran
2002-09-30 16:06             ` Stephen Leake
2002-10-27 23:01           ` phone# etc bdean
2002-10-28  3:04             ` tmoran
2002-11-06  3:14           ` A little Ada app tmoran
2002-11-06 11:37             ` Larry Kilgallen
2002-11-06 15:08             ` Ted Dennison
2002-11-06 18:02               ` tmoran
2001-06-21  3:09 ` Looping over a tagged record? gresset1
replies disabled

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