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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,80a67c84f8039eab X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Some questions on a library design Date: 1997/06/20 Message-ID: <33AA872C.3611@gsfc.nasa.gov>#1/1 X-Deja-AN: 251339208 References: Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1997-06-20T00:00:00+00:00 List-Id: Brian Rogoff wrote (in part): > > Absolutely. Let me provide a real piece of code, so I can illustrate a bit > better what I am trying to do, and we can really see if there is a problem > or I am just clueless (or both ;-) > > with AGL.Basic_Types; > with AGL.Input_Iterators; > with AGL.Output_Iterators; > with AGL.Forward_Iterators; > with AGL.Bidirectional_Iterators; > > generic > package AGL.Lists.Iterators is > type Iterator_Type is > record > Node: Cell_Ptr := null; > end record; > > function Start( L: List_Type ) return Iterator_Type; > function Finish( L: List_Type ) return Iterator_Type; > function "=" ( I: Iterator_Type; J: Iterator_Type ) return Boolean; > procedure Next( I: in out Iterator_Type ); > procedure Prev( I: in out Iterator_Type ); > function Get_Value( I: in Iterator_Type ) return Value_Type; > procedure Set_Value( I: in Iterator_Type; V: in Value_Type ); > function Get_Pointer( I: in Iterator_Type ) return Value_Ptr; > > package Input_Iterators is > new AGL.Input_Iterators(Value_Type, > Iterator_Type, > Next, > Get_Value > ); > package Output_Iterators is > new AGL.Output_Iterators(Value_Type, > Iterator_Type, > Next, > Set_Value > ); > package Forward_Iterators is > new AGL.Forward_Iterators(Value_Type, > Iterator_Type, > Value_Ptr, > Next, > Get_Value, > Set_Value, > Get_Pointer > ); > package Bidirectional_Iterators is > new AGL.Bidirectional_Iterators(Value_Type, > Iterator_Type, > Value_Ptr, > Next, > Prev, > Get_Value, > Set_Value, > Get_Pointer, > "="); > end AGL.Lists.Iterators; > > In the Iterators package for the Lists container, I instantiate all of the > possible Iterator signatures (Input, Output, Forward, Bidirectional) that a > list supports, so that a client can get at it without doing the > instantiation herself. Now, if we could alternate public and private parts > of a package, I could move my Iterator_Type to the private part of the > package, and then put those signature instantiations after that. (Ada > newbie quiz: why doesn't it work if we make Iterator_Type private?). Because generic instantiations require the full type definition (RM 13.14 (5)). However, you can move the instantiations into a child package(s); they can then see the full private type. If you put each instantiation in its own child package, the user can choose which ones she needs. This is one reason the interleaving of private and public parts is not needed in Ada; child packages give you some of the same capabilities. > -- Brian -- - Stephe