From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,573be8c453ecbff4,start X-Google-Attributes: gid103376,public From: Ted Dennison Subject: 'Read for pointers Date: 2000/07/26 Message-ID: <8lndgv$1om$1@nnrp1.deja.com>#1/1 X-Deja-AN: 651090087 X-Http-Proxy: 1.0 x71.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Jul 26 19:17:57 2000 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) Date: 2000-07-26T00:00:00+00:00 List-Id: 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.