From: Ted Dennison <dennison@telepath.com>
Subject: Re: packet type ?
Date: 2000/01/18
Date: 2000-01-18T00:00:00+00:00 [thread overview]
Message-ID: <862dm6$jr1$1@nnrp1.deja.com> (raw)
In-Reply-To: 38845EBD.6F90845D@icn.siemens.de
In article <38845EBD.6F90845D@icn.siemens.de>,
Alfred Hilscher <Alfred.Hilscher@icn.siemens.de> wrote:
>
> Ted Dennison wrote:
> 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;
The flip answer is I'd download the Booch components. :-)
Code wise, I'd do something like this:
generic
type Element is private;
package Stack is
type Instance is private;
Push (Item : in Element
Onto : in out Instance);
Pop (Item : out Element;
Off_Of : in out Instance);
private
...
end Stack;
It looks like your confusion is based on experience w/ other OO-based
languages. In Ada types and packages are completely separate kinds of
entities. Packages exist to provide for organizing other things into a
single namespace. Types define the data structure of objects.
Subprograms are defined within the context of packages, not types or
objects. For instance, to call what I created above, first I'd
instantiate it with my element type thusly:
with Stack;
...
procedure Whatever is
package Integer_Stack is new Stack (Integer);
Then I call push this way:
Pushee : Integer := 20;
Old_Integers : Integer_Stack.Instance;
...
begin
Integer_Stack.Push (Item => Pushee,
Onto => Old_Integers);
--
T.E.D.
http://www.telepath.com/~dennison/Ted/TED.html
Sent via Deja.com http://www.deja.com/
Before you buy.
next prev parent reply other threads:[~2000-01-18 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 [this message]
2000-01-19 0:00 ` Anders Gidenstam
2000-01-19 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Andy S
2000-01-20 0:00 ` Tucker Taft
2000-01-20 0:00 ` Brian Rogoff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox