From: munnari.oz.au!yoyo.aarnet.edu.au!huon.itd.adelaide.edu.au!cs.adelaide.edu .au!andrewd@uunet.uu.net (Andrew Dunstan)
Subject: Re: Novice Question On Generics
Date: 16 Sep 92 05:24:46 GMT [thread overview]
Message-ID: <196geuINNacl@huon.itd.adelaide.edu.au> (raw)
In article <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com>, lam@saifr00.cf
sat.honeywell.com (Josh Lam) writes:
[sorry for long repost - I'v cut it down a fair bit]
|> with Queue with Queue
|> package A is package B is
|> ... ...
|> type A_record is type B_record is
|> record record
|> ... ...
|> end record end record
|> package my_QA is new Queue(A_record); package my_QB is new Queue(B_re
cord);
|> ... ...
|> Run_Proc(X : A_record); Run_Proc(Y : B_record);
|> ... ...
|> end A; end B;
|>
|> Now the Run_Proc procedures for both packages will look like:
|>
|> Run_Proc(X : A_record) is Run_Proc(Y : B_record) is
|> begin begin
|> my_QA.enqueue(X); my_QB.enqueue(Y);
|> end Run_Proc; end Run_Proc;
|>
|> Basically, they contain the same functionality. In this example, I only
|> wrote one line of code for simplicity of illustration, in reality, there
|> could be more lines of code but same functionality. The only difference
|> is the queue instantiations my_QA and my_QB.
|>
|> Question:
|> Is there a way to write a generic procedure Run_Proc that the two packages
|> A and B can use? Note that the user *does not* need to know my_QA
|> and my_QB ie they are private members to A and B respectively and Run_Proc i
s
|> the only interface to the outside world. ie, The user only need to type
|> A.Run_Proc(X) or B.Run_Proc(Y).
I think this is what you want:
with queue;
generic
type x is private;
package run_proc_pack is
-- following line might be in the body, if queue not needed to be public
package rpq is new queue(x);
procedure run_proc(a : x);
end run_proc_pack;
package body run_proc_pack is
procedure run_proc(a: x) is
begin
rpq.enqueue(a);
end run_proc;
end run_proc_pack;
...
package a_run is new run_proc_pack(a_record);
package b_run is new run_proc_pack(b_record);
...
a_run.run_proc(a_rec);
...
without knowing more about what you are actually trying to do, it is
hard to tell if this is what you really want.
--
#######################################################################
# Andrew Dunstan # There's nothing good or bad #
# Department of Computer Science # but thinking makes it so. #
# University of Adelaide # #
# South Australia # - Shakespeare #
# net: andrewd@cs.adelaide.edu.au # #
#######################################################################
next reply other threads:[~1992-09-16 5:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-09-16 5:24 Andrew Dunstan [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-09-16 0:17 Novice Question On Generics agate!linus!think.com!yale.edu!spool.mu.edu!caen!uakari.primate.wisc.edu!
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox