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

Home » Public Forums » archive » Re: Treating an object as a structure
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: Treating an object as a structure [message #65519 is a reply to message #65424] Wed, 04 March 2009 15:45 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
llo wrote:
> Ok, thanks ...
>
> With this discussion, all of a sudden I wondered how ITT people
> implement the ALL keyword in GetProperty method of the objects ?
> Because maybe the easiest way to get all the content of the object is
> having the ALL keyword in GetProperty method. ( I know I said I don't
> wanna use this method )
>
> I don't know how can I implement this method. Maybe I will try
> something like this:
>
> PRO object::GetProperty, A=a, B=b, C=c, D=d, E=e, F=f, G=g, ALL=all
>
> ....
>
> IF ARG_PRESENT(all) THEN BEGIN
> all=CREATE_STRUCT
> ('A',self.a,'B',self.b,'C',self.c,'D',self.d,'E',self.e,'F', self.f,'G',self.g)
> ENDIF
> END
>
> Is it correct or there are a better way to do that ?

Just use STRUCT_ASSIGN:

pro mg_instance_test::getProperty, all=all
compile_opt strictarr

if (arg_present(all)) then begin
all = create_struct(name=obj_class(self))
struct_assign, self, all
endif
end


function mg_instance_test::init
compile_opt strictarr

self.a = 3.0
self.b = 'Hello'
self.c = 123L

return, 1
end


pro mg_instance_test__define
compile_opt strictarr

define = { mg_instance_test, a: 0.0, b: '', c: 0L }
end


Run the example like:

IDL> o = obj_new('mg_instance_test')
IDL> o->getProperty, all=all
IDL> help, all, /structures
IDL> obj_destroy, o

Mike
--
www.michaelgalloy.com
Associate Research Scientist
Tech-X Corporation
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Go figure
Next Topic: IDL help error for Scale3 procedure.

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

Current Time: Sat Oct 11 14:44:33 PDT 2025

Total time taken to generate the page: 0.48452 seconds