From: Brian Rogoff <bpr@shell5.ba.best.com>
Subject: Re: packet type ?
Date: 2000/01/19
Date: 2000-01-19T00:00:00+00:00 [thread overview]
Message-ID: <Pine.BSF.4.21.0001190930400.18715-100000@shell5.ba.best.com> (raw)
In-Reply-To: 8646k7$6g1$1@nyheter.chalmers.se
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
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 ` Brian Rogoff
2000-01-18 0:00 ` Ted Dennison
2000-01-19 0:00 ` Anders Gidenstam
2000-01-19 0:00 ` Brian Rogoff [this message]
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