home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / ada / 3310 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  1.7 KB

  1. Path: sparky!uunet!wupost!uwm.edu!biosci!agate!linus!linus.mitre.org!maestro!jclander
  2. From: jclander@maestro.mitre.org (Julian C. Lander)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: HELP! Input/Output of private types
  5. Message-ID: <1992Nov18.204927.12829@linus.mitre.org>
  6. Date: 18 Nov 92 20:49:27 GMT
  7. References: <Bxpwty.H8E@acsu.buffalo.edu>
  8. Sender: news@linus.mitre.org (News Service)
  9. Reply-To: jclander@maestro.mitre.org (Julian C. Lander)
  10. Organization: The MITRE Corporation, McLean, Va
  11. Lines: 41
  12. Nntp-Posting-Host: maestro.mitre.org
  13.  
  14. In article <Bxpwty.H8E@acsu.buffalo.edu>, kist@acsu.buffalo.edu (james e kist) writes:
  15. |> Someone please help! How can I use 'put' on a private type that is not
  16. |> fully delcared in the specification? This is my situation:
  17. |> 
  18. |> generic
  19. |>     type Element is private;
  20. |> package abcd
  21. |> .
  22. |> .
  23. |> .
  24. |> end abcd;
  25. |> 
  26. |> Now, how do I do I/O on an object that is of type Element? Thanks for any
  27. |> help.
  28.  
  29. The short answer is that you can't.  The long answer is to change the
  30. generic formal part so that it reads as follows:
  31.  
  32. generic
  33.    type Element is private;
  34.    with procedure Put_Element (File : in Text_IO.File_Type; The_Elt : in Element);
  35.    with procedure Get_Element (File : in Text_IO.File_Type; The_Elt : out Element);
  36. package abcd
  37. .
  38. .
  39. .
  40. .
  41. end abcd;
  42.  
  43. This means that the user of the generic package will need to supply
  44. procedures for reading and writing data objects of type Element.  I'd
  45. suggest including File in both profiles, since that lets you write to
  46. any file.  To write to the standard output, you would say Put_Element
  47. (Text_IO.Standard_Output, The_Elt).  (I suppose that even greater
  48. generality would involve reading from and writing to strings, but I 
  49. digress.)
  50.  
  51. Good luck.
  52.  
  53. Julian C. Lander
  54. jclander@mitre.orgg
  55.