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: d96andgi@dtek.chalmers.se (Anders Gidenstam) Subject: Re: packet type ? Date: 2000/01/19 Message-ID: <8646k7$6g1$1@nyheter.chalmers.se>#1/1 X-Deja-AN: 574642316 References: <387F3DD1.485F7C70@icn.siemens.de> <85njs1$3rl$1@nnrp1.deja.com> <38845EBD.6F90845D@icn.siemens.de> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@chalmers.se X-Trace: nyheter.chalmers.se 948280775 6657 129.16.30.39 (19 Jan 2000 11:19:35 GMT) Organization: Chalmers University of Technology Mime-Version: 1.0 NNTP-Posting-Date: 19 Jan 2000 11:19:35 GMT Newsgroups: comp.lang.ada Date: 2000-01-19T11:19:35+00:00 List-Id: In article <38845EBD.6F90845D@icn.siemens.de>, Alfred Hilscher writes: > > Ted Dennison wrote: >> >> > question is obsolete. What I'm looking for is something like a >> "packege >> > type" (similar to "task type"). What I want do is something like this: >> >> > Any suggestions how to do this ? >> >> That's what generics with package formal parameters are for. > > > I think thats not quite the same. Taking the example below, how would > you do this with generics ? > > > package type stack is > push (item : in ...); > pop (item : out ...) > end stack > > procedure application is > User_stack : stack; > Supervisor_stack : stack; > Interrupt_stack : stack; > > Any_Stack : access Stack; > begin > ... > Any_Stack := new Stack; -- how do this ??? > ... > end application; 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.) /Anders -- "A well-written program is its own heaven; a poorly-written program is its own hell." - The Tao of Programming