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

Home » Public Forums » archive » Re: Smart way to extract the same attribute from a list of 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: Smart way to extract the same attribute from a list of objects? [message #81552] Thu, 04 October 2012 09:53 Go to previous message
PMan is currently offline  PMan
Messages: 61
Registered: January 2011
Member
Well, I will share with you what I did. Not sure about if it qualitfies as better/faster/more-elegant, but here you go.

I created a new object that is just a list:

pro newObj__define
compile_opt idl2

_ = {newObj, $
inherits list $
}

Then, in my init, I created a struct like

function newObj::init, nSamples = nSamples
compile_opt idl2

newObjStruct = {newObjStruct, $
radiance:0, $
channel:0}

self->add, replicate(newObjStruct, nSamples), /extract

return, 1
end

Then I overloaded the setProperty and getProperty functions.

pro newObj::setProperty, _extra=extra
compile_opt idl2

if self->isEmpty() then return

if (~n_elements(extra)) then return

num = n_elements((tags=tag_names(extra)))

lArray = self->toArray()
self->remove, /all

for ii=0, num-1 do begin
ok = execute("lArray."+tags[ii]+ " = extra.(ii)")
endfor

self.add, lArray, /extract
end

pro newObj::getProperty, _ref_extra=extra
compile_opt idl2

if self->isEmpty() then return

if (~n_elements(extra)) then return

lArray = self.toArray()

for ii=0, n_elements(extra)-1 do begin
ok = execute("(scope_varfetch(extra[ii], /ref_extra)) = lArray."+extra[ii])
endfor

end
[Message index]
 
Read Message
Read Message
Previous Topic: Smart way to extract the same attribute from a list of objects?
Next Topic: 3d device coordinates from a 3D polyline....

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

Current Time: Wed Oct 08 15:22:57 PDT 2025

Total time taken to generate the page: 0.00380 seconds