From: d96andgi@dtek.chalmers.se (Anders Gidenstam)
Subject: Re: packet type ?
Date: 2000/01/19
Date: 2000-01-19T11:19:35+00:00 [thread overview]
Message-ID: <8646k7$6g1$1@nyheter.chalmers.se> (raw)
In-Reply-To: 38845EBD.6F90845D@icn.siemens.de
In article <38845EBD.6F90845D@icn.siemens.de>,
Alfred Hilscher <Alfred.Hilscher@icn.siemens.de> 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
next prev parent reply other threads:[~2000-01-19 0:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-01-14 0:00 packet type ? Alfred Hilscher
2000-01-14 0:00 ` Ted Dennison
2000-01-18 0:00 ` Alfred Hilscher
2000-01-18 0:00 ` Ted Dennison
2000-01-18 0:00 ` Brian Rogoff
2000-01-19 0:00 ` Anders Gidenstam [this message]
2000-01-19 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Andy S
2000-01-20 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox