home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / ada / 2625 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  2.3 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!umn.edu!The-Star.honeywell.com!saifr00.cfsat.honeywell.com!lam
  2. From: lam@saifr00.cfsat.honeywell.com (Josh Lam)
  3. Newsgroups: comp.lang.ada
  4. Subject: Novice Question On Generics
  5. Message-ID: <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com>
  6. Date: 15 Sep 92 18:43:45 GMT
  7. Organization: Honeywell Air Transport Systems Division
  8. Lines: 57
  9.  
  10. Hi there:
  11.  
  12. I have a generic package Queue that has the function enqueue.
  13.  
  14. This generic package is 'with' into two packages A and B that looks
  15. like:
  16.  
  17. with Queue                                with Queue
  18. package A  is                             package B is 
  19.  
  20.  ...                                      ...
  21.  
  22.  type A_record is                           type B_record is
  23.   record                                     record
  24.    ...                                         ...
  25.   end record                                 end record
  26.  
  27.  package my_QA is new Queue(A_record);       package my_QB is new Queue(B_record);
  28.  
  29.  ...                                          ...
  30.  
  31.  Run_Proc(X : A_record);                      Run_Proc(Y : B_record);
  32.  
  33.  ...                                          ...
  34.  
  35. end A;                                    end B;
  36.  
  37.  
  38. Now the Run_Proc procedures for both packages will look like:
  39.  
  40. -- Run_Proc in package A                  -- Run_Proc in package B 
  41.  
  42. Run_Proc(X : A_record) is                 Run_Proc(Y : B_record) is
  43. begin                                     begin
  44.   my_QA.enqueue(X);                         my_QB.enqueue(Y);
  45. end Run_Proc;                              end Run_Proc;
  46.  
  47.  
  48. Basically, they contain the same functionality.  In this example, I only
  49. wrote one line of code for simplicity of illustration, in reality, there
  50. could be more lines of code but same functionality.  The only difference
  51. is the queue instantiations my_QA and my_QB.  
  52.  
  53. Question:
  54. Is there a way to write a generic procedure Run_Proc that the two packages 
  55. A and B can use?   Note that the user *does not* need to know my_QA 
  56. and my_QB ie they are private members to A and B respectively and Run_Proc is 
  57. the only interface to the outside world. ie, The user only need to type 
  58. A.Run_Proc(X) or B.Run_Proc(Y).
  59.  
  60.  
  61. Thanks in advance.
  62.  
  63. -- 
  64. Josh Lam
  65. Honeywell Inc
  66. lam@saifr00.cfsat.honeywell.com
  67.