comp.lang.ada
 help / color / mirror / Atom feed
* HELP! Input/Output of private types
@ 1992-11-14 18:03 james e kist
  0 siblings, 0 replies; 4+ messages in thread
From: james e kist @ 1992-11-14 18:03 UTC (permalink / raw)


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.

Jim Kist

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HELP! Input/Output of private types
@ 1992-11-16 16:11 Ron Sercely
  0 siblings, 0 replies; 4+ messages in thread
From: Ron Sercely @ 1992-11-16 16:11 UTC (permalink / raw)


You must add a subprogram specification to the generic declration that
will actually do the I/O.  You create this I/O procedure in the normal
way, then instantiate the generic with this procedure.  

If you are going to have LOTS of instantiations this indeed can be a pain,
because you will have to create the I/O procedure for each instantiation.
This is an example where and Ada pre-processor may be useful to you.

Ron Sercely

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HELP! Input/Output of private types
@ 1992-11-16 18:55 Bob Kitzberger
  0 siblings, 0 replies; 4+ messages in thread
From: Bob Kitzberger @ 1992-11-16 18:55 UTC (permalink / raw)


kist@acsu.buffalo.edu (james e kist) writes:

>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.


   generic
       type Element is private;
       with procedure Put( Item : in     Element );
       with procedure Get( Item :    out Element );
   package abcd is
   ...
       Get (Item);
       Put (Item);
   end abcd;
   

----------------
Bob Kitzberger          VisiCom Laboratories, Inc.
rlk@visicom.com         10052 Mesa Ridge Court, San Diego CA 92121 USA
                        +1 619 457 2111    FAX +1 619 457 0888

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HELP! Input/Output of private types
@ 1992-11-18 20:49 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!uwm.edu!biosci!agate!
  0 siblings, 0 replies; 4+ messages in thread
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!uwm.edu!biosci!agate! @ 1992-11-18 20:49 UTC (permalink / raw)


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 Elemen
t);
   with procedure Get_Element (File : in Text_IO.File_Type; The_Elt : out Eleme
nt);
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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1992-11-18 20:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-11-16 16:11 HELP! Input/Output of private types Ron Sercely
  -- strict thread matches above, loose matches on Subject: below --
1992-11-18 20:49 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!uwm.edu!biosci!agate!
1992-11-16 18:55 Bob Kitzberger
1992-11-14 18:03 james e kist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox