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

Home » Public Forums » archive » Treating an object as a structure
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Treating an object as a structure [message #65432] Wed, 04 March 2009 12:20 Go to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
If I've a struct I can do something like that:

a={s:'string', l: 0l}
print, n_tags(a)
print, tag_names(a)
help, a, /str
etc.

But if I've an object I can't do the same... Is it possible to parse
all the attributes inside the object using something similar ?
I mean, I don't want to use the GetProperty method, I only want to
know which attributes are stored in the definition of the object.

pro object__define
str ={ object, $
attribute_s: '', $
attribute_l: 0l }
end

The object saves a struct. It could be possible to take information
about this without the use of the getproperty method.

thanks
Re: Treating an object as a structure [message #65487 is a reply to message #65432] Fri, 06 March 2009 14:36 Go to previous message
JDS is currently offline  JDS
Messages: 94
Registered: March 2009
Member
I use this technique a lot:

snapshot=create_struct(NAME=obj_class(self))

or simply

snapshot={MYCLASS}
struct_assign,self,snapshot

later apply snapshot:

struct_assign,snapshot,self

This allows me to make snapshots of object data for the purpose of
undoing changes, or examining how it was at a certain point in time.
Keep a pointer to a list of these, and you have multiple undo. Add a
text phrase when snapshotting ("Frobnoid change") and you can
advertise "Undo Forbnoid change" and so on.

The lack of garbage collection starts getting painful at this point
though (since older versions could refer to data newer versions have
deleted).

Remember that snapshots of heap pointers (at whatever level in the
heirarchy) are not immutable. If you want a deep copy, you can use
the save/restore trick, first calling the new HEAP_NOSAVE routine on
items you won't need a deep copy of. Or you can simply replicate
certain heap data by hand (new=ptr_new(*old)). This reminds me that
we're still lacking deep copy capability without hitting the disk.

JD
Re: Treating an object as a structure [message #65507 is a reply to message #65432] Thu, 05 March 2009 08:05 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
Ups

Sorry ! I only tried inside a class method. thanks for you comment !
Re: Treating an object as a structure [message #65508 is a reply to message #65432] Thu, 05 March 2009 08:01 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
llo wrote:
> On Mar 4, 4:59 pm, David Fanning <n...@dfanning.com> wrote:
>> llo writes:
>>> It works but the problem is that the struct is not the object itself.
>> No, that's pretty much the point of objects. :-)
>
> That's not true David. You can get all the object attributes doing
> this:
>
> a=OBJ_NEW('object')
> str=CREATE_STRUCT(NAME=OBJ_CLASS(a))
> STRUCT_ASSIGN, a, str
>
> Now, ypu have all the attributes of a in the struct str.
>
> Cheers,
>
> Bernat
>
>

Not so fast! That trick only works inside an object's methods:

IDL> a=OBJ_NEW('idlgrmodel')
IDL> str=CREATE_STRUCT(NAME=OBJ_CLASS(a))
IDL> STRUCT_ASSIGN, a, str
% STRUCT_ASSIGN: Object instance data is not visible outside class
methods: A
% Execution halted at: $MAIN$

Mike
--
www.michaelgalloy.com
Associate Research Scientist
Tech-X Corporation
Re: Treating an object as a structure [message #65514 is a reply to message #65432] Wed, 04 March 2009 16:52 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
llo writes:

> Lately, we've learned a lot with my questions.

Yes, but be careful. Karma is a funny thing, and
if you learn too much you will be made to
listen to other people ask clever questions that
you can only hope to answer. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Treating an object as a structure [message #65515 is a reply to message #65432] Wed, 04 March 2009 16:35 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
Remember that STRUCT_ASSIGN is so useful too to clone object inside
the Init method
Re: Treating an object as a structure [message #65516 is a reply to message #65432] Wed, 04 March 2009 16:30 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
Cool !

Lately, we've learned a lot with my questions.

llo
Re: Treating an object as a structure [message #65518 is a reply to message #65432] Wed, 04 March 2009 15:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Michael Galloy writes:

> Just use STRUCT_ASSIGN:

Well, shoot, I knew that! How come I couldn't remember it? :-(

Probably because I didn't write it down on my web page,
my (almost) guaranteed way of remembering these sorts of
things. Look for an article soon. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: netCDF Read/Write Variable
Next Topic: Probably a Stupid Question

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

Current Time: Wed Oct 08 18:55:21 PDT 2025

Total time taken to generate the page: 0.00568 seconds