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,62eb5b45c7abf3a5,start X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Need help... Date: 1998/01/11 Message-ID: #1/1 X-Deja-AN: 315141610 Content-Transfer-Encoding: 8bit References: <69bvak$14d@bgtnsc01.worldnet.att.net> Content-Type: text/plain; charset=ISO-8859-1 Organization: Estormza Software Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-01-11T00:00:00+00:00 List-Id: In article <69bvak$14d@bgtnsc01.worldnet.att.net>, "Scott Barrish" wrote: Is there anway to instantiate a queue of stacks? I know it might not have >any value in real programming situations, but I just want to see if it can >be done. If you would like to help with this problem, I would be more than >happy to e-mail my packages and code files. Yes, you can. Consider these parial declarations generic type Queue_Item is private; with function "=" (L, R : Queue_Item) return Boolean is <>; package Queues is type Root_Queue is tagged null record; ... end Queue; generic type Stack_Item is private; with function "=" (L, R : Stack_Item) return Boolean is <>; package Stacks is type Root_Stack is tagged null record; ... end Stacks; Assume an instantiation of stacks with on type Integer with Stacks; package Integer_Stacks is new Stacks (Integer); with Integer_Stacks, Stacks.Bounded_G; package Integer_Stacks.Bounded is new Integer_Stacks.Bounded_G; (I think that's the syntax.) Now you can instantiate your queue with your bounded integer stack: with package Queues, Integer_Stacks.Bounded; package Integer_Stack_Queues is new Queues (Integer_Stacks.Bounded.Bounded_Stack); with Integer_Stack_Queues, Queues.Bounded_G; package Integer_Stack_Queues.Bounded is new Queues.Bounded_G; (I think that's the syntax.) Now you have a bounded queue of bounded stacks. Be careful, though. This is all by-copy. If you get the front item (stack) of the queue, you're getting a copy of what's in the queue. As in declare The_Queue : Integer_Stack_Queues.Bounded.Bounded_Queue; The_Stack : Integer_Stacks.Bounded.Bounded_Stack; begin The_Stack := Front (The_Queue); Push (10, On => The_Stack); end; Be careful, because even though you pushed the item 10 on the integer stack, it's only a copy of the stack at the front of the queue. If you were to get the front item of the queue again, that stack doesn't have the value 10 on its top. The question you need to ask is, do you want a copy, or do you want to get a pointer to what's on the queue? If the latter, then if you push an item on the stack, it will show up on top of the stack at the front of the queue. To do this, you need to instantiate the queue with a pointer to stack. When you put a stack in the queue, you're really putting a poointer-to-stack on the queue. Something like with Integer_Stacks; package Integer_Stack_Types is type Integer_Stack_Class_Access_All is access all Integer_Stack.Root_Stack'Class; end; with Integer_Stack_Types, Queues; package Integer_Stack_Queues is new Queues (Integer_Stack_Types.Integer_Stack_Class_Access_All); with Integer_Stack_Queues, Queues.Bounded_G; package Integer_Stack_Queues.Bounded is new Integer_Stack_Queues.Bounded_G; Now you have a bounded queue of pointers to integer stacks. As written, it's a pointer to any kind of stack in the class of integer stack types, so it's actually a heterogeneous queue of stacks. Pretty cool, huh? This is the kind of thing Chris Sparks was asking about a couple of days ago. With this formulation, when you ask for the front item of the queue, you're getting a pointer to the stack at the front. So any changes you make to the state of the stack will be reflected in the queue too. If you have any more questions about this issue, feel free to email me privately. Hope that helps, Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271