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,ea81945e8b96701b X-Google-Attributes: gid103376,public From: Brian Rogoff Subject: Re: packet type ? Date: 2000/01/19 Message-ID: #1/1 X-Deja-AN: 574770572 References: <387F3DD1.485F7C70@icn.siemens.de> <85njs1$3rl$1@nnrp1.deja.com> <38845EBD.6F90845D@icn.siemens.de> <8646k7$6g1$1@nyheter.chalmers.se> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: nntp1.ba.best.com 948303625 199 bpr@206.184.139.136 MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-01-19T00:00:00+00:00 List-Id: On 19 Jan 2000, Anders Gidenstam wrote: > Well, you make a generic package containing the stack ADT. > It'll be something like this: > > generic > type Element_Type is private; > package Stack_ADT is > > type Stack(Size : Natural) is private; > > procedure Push (S : in out Stack; I : in Element_Type); > procedure Pop (S : in out Stack; I : out Element_Type); > > ... > > private > type Element_Array is array (Positive range <>) of Element_Type; > > type Stack(Size : Natural) is > record > S : Element_Array (1..Size); > Top : Natural := 0; > end record; > end Stack_ADT; > > And you use it like this: > > with Stack_ADT; > procedure Something is > > package Integer_Stack is new Stack_ADT (Integer); > use Integer_Stack; > package Float_Stack is new Stack_ADT (Float); > use Float_Stack; > > > My_Stack : Integer_Stack.Stack (Size => 100); > Some_Stack : Float_Stack.Stack (Size => 50); > begin > Push (My_Stack, 3); > Push (Some_Stack, 7.0); > ... > > I hope this was helpful in understanding this part of Ada. > (Note that this isn't OO in the C++ sense, you can't let any type inherit > the stack's properties but I don't think that type of inheritance is needed > for an ADT like this. And of course one could make the stack a tagged type > which would allow inheritance.) Ada 95 also allows you to create a stack signature generic type Item_Type is private; type Stack_Type is private; with procedure Push(Stack : in out Stack_Type; Item : in Item_Type); with procedure Pop(Stack : in out Stack_Type; Item : out Item_Type); ... package Stack_Sig is begin end; and write code which only depends on an instantiation having that profile, so that your stack code and many others can supply the stack ADT for the code. This is a very nice feature of Ada 95 which is not described in many Ada books; Barnes and Ben-Ari are exceptional here. -- Brian