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

Home » Public Forums » archive » Object within an Object's 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
Object within an Object's Structure [message #71281] Wed, 09 June 2010 12:12 Go to next message
carl is currently offline  carl
Messages: 3
Registered: June 2010
Junior Member
Hello,

I am trying to make use of what OOP functionality IDL has, and I wish
to have as an object variable another object of a different type.

Is this possible? If so, how do I specify this?

I have an object type orbitingBody, and want to make an object
orbitingPair. Would this work? how would it be then coded in my init
function?

pro orbitingpair__define
struct = { orbitingPair,
planet: obj_new('orbitingbody', args)
star: obj_new('orbitingbody', args)
etc...}
end

thanks,

Carl
Re: Object within an Object's Structure [message #71366 is a reply to message #71281] Thu, 10 June 2010 15:22 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Paul van Delst wrote:
>
> carl wrote:
>> Hello,
>>
>> I am trying to make use of what OOP functionality IDL has, and I wish
>> to have as an object variable another object of a different type.
>>
>> Is this possible? If so, how do I specify this?
>>
>> I have an object type orbitingBody, and want to make an object
>> orbitingPair. Would this work? how would it be then coded in my init
>> function?
>>
>> pro orbitingpair__define
>> struct = { orbitingPair,
>> planet: obj_new('orbitingbody', args)
>> star: obj_new('orbitingbody', args)
>> etc...}
>> end
>
> Hmm. Why restrict yourself to only planetary and star orbiting bodies? (e.g. asteroids?
> comets?) Or even just two?
>
> Assuming your "orbitingbody" object definition contains property information about the
> type of orbiting body (i.e. planet, star, moon, asteroid, comet, etc), why not something like:
>
> pro orbitingSet__define
> void = { orbitingSet,
> n_bodies = 0L, $
> ; Container for orbiting bodies
> INHERITS IDL_Container }
> end
>
> ?
>
> You can then add as many orbiting bodies as you like:
>
> pro orbitingSet::Add, $
> obj, $ ; Object to add
> _REF_EXTRA = Extra ; Keywords passed onto IDL_Container::Add
>
> ; Add object to the container
> self->IDL_Container::Add, obj, _EXTRA = Extra
>
> ; If the object added is an orbitingBody object, increment the counter
> IF ( OBJ_ISA(obj, 'orbitingBody') ) THEN self.n_bodies++
> end
>
> This way you can store more information in your "orbitingSet" container if the need ever
> arises... and the objects you add needn't be just orbitingBody objects either.

I forgot to add a proposed get function

function orbitingSet::Get, $
_REF_EXTRA = Extra ; Keywords passed onto IDL_Container::Get

; Get the requested object reference
objref = self->IDL_Container::Get(_EXTRA = Extra)

RETURN, objref

end

(I can't recall if the _REF_EXTRA keyword just needs to be an _EXTRA or not....)

Via the IDL_Container::Get keywords, for an orbitingSet object (let's call it oSet), you
can do things like:

obj = oSet->Get(ISA='orbitingBody', COUNT=n)
if ( n EQ 0 ) then $
message, 'No orbiting bodies in set!'

You can then fancy the internals up a bit so you can return particular types of orbiting
bodies too.

Anyway....

cheers,

paulv
Re: Object within an Object's Structure [message #71367 is a reply to message #71281] Thu, 10 June 2010 15:00 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
carl wrote:
> Hello,
>
> I am trying to make use of what OOP functionality IDL has, and I wish
> to have as an object variable another object of a different type.
>
> Is this possible? If so, how do I specify this?
>
> I have an object type orbitingBody, and want to make an object
> orbitingPair. Would this work? how would it be then coded in my init
> function?
>
> pro orbitingpair__define
> struct = { orbitingPair,
> planet: obj_new('orbitingbody', args)
> star: obj_new('orbitingbody', args)
> etc...}
> end

Hmm. Why restrict yourself to only planetary and star orbiting bodies? (e.g. asteroids?
comets?) Or even just two?

Assuming your "orbitingbody" object definition contains property information about the
type of orbiting body (i.e. planet, star, moon, asteroid, comet, etc), why not something like:

pro orbitingSet__define
void = { orbitingSet,
n_bodies = 0L, $
; Container for orbiting bodies
INHERITS IDL_Container }
end

?

You can then add as many orbiting bodies as you like:

pro orbitingSet::Add, $
obj, $ ; Object to add
_REF_EXTRA = Extra ; Keywords passed onto IDL_Container::Add

; Add object to the container
self->IDL_Container::Add, obj, _EXTRA = Extra

; If the object added is an orbitingBody object, increment the counter
IF ( OBJ_ISA(obj, 'orbitingBody') ) THEN self.n_bodies++
end

This way you can store more information in your "orbitingSet" container if the need ever
arises... and the objects you add needn't be just orbitingBody objects either.

cheers,

paulv
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Creating a sub array from an array
Next Topic: Re: Contour data with two different lon/lat grids onto the same map projection

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

Current Time: Wed Oct 08 17:47:29 PDT 2025

Total time taken to generate the page: 0.00566 seconds