home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!uwm.edu!biosci!agate!linus!linus.mitre.org!maestro!jclander
- From: jclander@maestro.mitre.org (Julian C. Lander)
- Newsgroups: comp.lang.ada
- Subject: Re: HELP! Input/Output of private types
- Message-ID: <1992Nov18.204927.12829@linus.mitre.org>
- Date: 18 Nov 92 20:49:27 GMT
- References: <Bxpwty.H8E@acsu.buffalo.edu>
- Sender: news@linus.mitre.org (News Service)
- Reply-To: jclander@maestro.mitre.org (Julian C. Lander)
- Organization: The MITRE Corporation, McLean, Va
- Lines: 41
- Nntp-Posting-Host: maestro.mitre.org
-
- In article <Bxpwty.H8E@acsu.buffalo.edu>, kist@acsu.buffalo.edu (james e kist) writes:
- |> Someone please help! How can I use 'put' on a private type that is not
- |> fully delcared in the specification? This is my situation:
- |>
- |> generic
- |> type Element is private;
- |> package abcd
- |> .
- |> .
- |> .
- |> end abcd;
- |>
- |> Now, how do I do I/O on an object that is of type Element? Thanks for any
- |> help.
-
- The short answer is that you can't. The long answer is to change the
- generic formal part so that it reads as follows:
-
- generic
- type Element is private;
- with procedure Put_Element (File : in Text_IO.File_Type; The_Elt : in Element);
- with procedure Get_Element (File : in Text_IO.File_Type; The_Elt : out Element);
- package abcd
- .
- .
- .
- .
- end abcd;
-
- This means that the user of the generic package will need to supply
- procedures for reading and writing data objects of type Element. I'd
- suggest including File in both profiles, since that lets you write to
- any file. To write to the standard output, you would say Put_Element
- (Text_IO.Standard_Output, The_Elt). (I suppose that even greater
- generality would involve reading from and writing to strings, but I
- digress.)
-
- Good luck.
-
- Julian C. Lander
- jclander@mitre.orgg
-