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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,399666c22a39304c X-Google-Attributes: gid103376,public From: cosc19z5@Bayou.UH.EDU (Spasmo) Subject: Re: Translate this into Ada ... Date: 1996/08/21 Message-ID: <4ved8g$att@Masala.CC.UH.EDU>#1/1 X-Deja-AN: 175445696 organization: University of Houston newsgroups: comp.lang.ada Date: 1996-08-21T00:00:00+00:00 List-Id: Richard Irvine (Richard.Irvine@eurocontrol.fr) wrote: : Can anyone help with what I imagine is a frequently ocurring problem? : We would like all lists in an application to be read using an iterator : with operations like: [Snip] Well I'm no expert in Ada, but I have successfully written generic linked list routines that pretty much do what you want. Here's some info, but if you would like the actual source code I'd be more than happy to provide it (I haven't done all that much debugging but it seems to work and at the very least should give you an idea of how to proceed). I did a generic package that was instantiated with the data type to be stored in the list. This data type was imbedded in a record similar to the following: type List_Node; type List_Node_Ptr is access List_Node; type List_Node is record Data : Generic_Data; Next : List_Node_Ptr; end record; Where Data was what was generically instantiated. Of course access restrictions were applied so the user only saw what I wanted him/her to see. Anyway as for the list itself I used a simple singly linked list with head and tail pointers for simplicity of operations, so the data type that was immediately visible to the user was something like the following: type List is private; private type List is record List_Body, Head, Tail : List_Node_Ptr; end record; So for use the user would say instantiate the package like the following: package My_List_Pkg is new Lists ( Rec ); Then declare lists by: My_List : My_List_Pkg.List; So the package would provide the data type for the list and also all the operations (iterators, etc...). I was able to do linked lists of linked lists like this and so forth. For multiple linked lists of the same type one could just use the same instantiation but of course different types would mean different instantiations but this was very flexible. BTW, I really didn't consider my implementation to be an "iterator", since it provided iterator operations and the data type itself, so it was more of a linked list package but the functionality again seems to be what you are looking for. One thing that's a problem is if you want a heterogenous list of objects. Something like the above would not accomodate your needs unfortunately so you'd have to have a linked list of pointers to class wide types, which isn't hard to achieve but it's something to keep in mind. My list package didn't do this so while it could handle any data type, heterogenous lists of related classes are pretty much out of the question. Damn I love Ada! -- Spasmo "Everyone has secrets, but sometimes you get caught, So if it's just between us, my silence can be bought" "Blackmail" by Sloppy Seconds