comp.lang.ada
 help / color / mirror / Atom feed
* 'Read for pointers
@ 2000-07-26  0:00 Ted Dennison
  2000-07-26  0:00 ` Pat Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Ted Dennison @ 2000-07-26  0:00 UTC (permalink / raw)


I've seen it suggested in several places to handle Stream writing of
pointers by writing what the pointer points to instead. That's simple
enough.

But say I want to make this automatic. Lets say I have a pointer type
declared thusly:

package Example is
   type Handle is private;

   ...
private

   type Instance;

   type Handle is access all Instance;

end Example;

The user doesn't even really know or care that Handle is really a
pointer. But they may need to do stream I/O with it.

The obvious solution is to create my own 'Write and 'Read routines for
Handle. But there's a problem. Following is the profile for 'Read:

   procedure Read
     (Stream : access Ada.Streams.Root_Stream_Type'Class;
      Item   : out    Handle
     );
   for Handle'Read use Read;

The problem is that Item is an *out* parameter. That means I won't have
acces to the pointer's old value inside Read. There's no way I can put
the newly read data from the stream into the Instance that Handle
currently points to!

I see two possible solutions to this:
  1)  Redefine "Handle" to be a record with a single pointer field for
Instance in it.
  2)  Provide my own Read routine with an "in" or "in out" parameter for
Handle, then warn the user with copious comments not to use 'Read. This
may involve them writing their own 'Read for their compound objects to
prevent their users from transitivly calling Handle'Read.

I'm not too fond of either solution. It would have been nice if Read
used "in out" instead. Does anyone have any other solutions?

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-07-31  0:00 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-26  0:00 'Read for pointers Ted Dennison
2000-07-26  0:00 ` Pat Rogers
2000-07-26  0:00   ` tmoran
2000-07-26  0:00     ` Pat Rogers
2000-07-27  0:00       ` tmoran
2000-07-26  0:00         ` Pat Rogers
2000-07-27  0:00   ` Ted Dennison
2000-07-27  0:00     ` Pat Rogers
2000-07-27  0:00       ` Ted Dennison
2000-07-27  0:00         ` Pat Rogers
2000-07-26  0:00 ` Pat Rogers
2000-07-28  0:00   ` Stephen Leake
2000-07-28  0:00     ` tmoran
2000-07-29  0:00     ` Pat Rogers
2000-07-31  0:00       ` Stephen Leake
2000-07-31  0:00         ` Robert A Duff
2000-07-31  0:00         ` Pat Rogers
2000-07-28  0:00 ` Stephen Leake
2000-07-31  0:00   ` Ted Dennison

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