comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Copying IDL objects
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Copying IDL objects [message #13048 is a reply to message #12981] Fri, 02 October 1998 00:00 Go to previous messageGo to previous message
J.D. Smith is currently offline  J.D. Smith
Messages: 214
Registered: August 1996
Senior Member
Mark Rivers wrote:
>
> I am trying to figure out how to make a copy of an instance of an IDL object.
>
> a = obj_new('myobj')
> b = a
> ; This does not do what I want, it makes a new reference to the same instance
>
> b = obj_copy(a) ; This is what I want
>
> The only way I can see how to do it is:
>
> pro my_obj::copy, out
> out->set_a, self.a
> out->set_b, self.b
> ....
> end
>
> This means I have to write a set_X function for each field, and each object
> class needs its own version of the ::copy routine. This seems crazy.
>
> I seem to recall a post from a few months ago about some ways of generally
> getting/setting properties in IDL objects. Any ideas?
>

Here's something really dirty that will do the trick. Use it if
desperate:

function obj_copy, obj
o=obj
file=filepath('obj.sav',/TMP)
save,o,FILENAME=file
restore, FILENAME=file
return,o
end

Does the job though. If you're really doing a lot of this, consider
setting up a small ram disk just for this purpose.

JD

--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-6263
304 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is this a bug?
Next Topic: Re: IDL messes up Julian day plots ?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 04:48:59 PDT 2025

Total time taken to generate the page: 1.03724 seconds