[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Objects, File Names, and the Save command.
David Fanning wrote:
>
> J.D. Smith (jdsmith@astrosun.tn.cornell.edu) writes:
>
> > I am exploring a very promising use of the save/restore commands in
> > conjuction with objects. Given some complex object which contains a
> > host of different types of data (with pointers, etc.), as part of a
> > class method, one adds:
> >
> > save, self, FILENAME=fname
> >
> > to register on disk an accurate snapshot of the object. To restore,
> > later, use:
> >
> > restore,pname,RESTORED_OBJECTS=obj,/RELAXED_STRUCTURE_ASSIGNMENT
> >
> > and the object is in obj, but also brought back as the local variable
> > *self*.
>
> > [cut...]
>
> > This is all very convenient but leads to the strange situation of a
> > loaded object in memory which exists there *before* any of the class
> > methods, and/or the __define procedure for that object class are
> > compiled. Therefore, the usual paradigm of putting all class methods in
> > the __define procedure file before this procedure (suggested by RSI
> > itself in the manual) fails. How can the method be found if the
> > __define doesn't have to be compiled and isn't in it's own file? I
> > would like to come up with a solution which doesn't involve a separate
> > class__method.pro file for each method. Any ideas?
>
> How about something like this:
>
> thisClass = Obj_Class(self)
> Resolve_Routine, thisClass + '_define'
>
> I haven't tested this, but don't see any reason it wouldn't work.
> Resolve_Routine is the way IDL procedures and functions can
> be compiled from *within* other procedures and functions.
>
David,
This will certainly work, but has the unfortunate side-effect of
re-compiling every method each time an object is read from disk... I
thought of modifying it slightly to the tune of:
thisdef=Obj_Class(self)+'__DEFINE'
if (where(routine_info() eq thisdef))[0] eq -1 then
resolve_routine,thisdef
So that it would only compile if presently undefined.
Thanks for the tip.
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 |*|