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

Home » Public Forums » archive » Re: pointer to object confusion (C++ programmer, IDL n00b)
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
Re: pointer to object confusion (C++ programmer, IDL n00b) [message #70722] Tue, 04 May 2010 08:01 Go to next message
Aram Panasenco is currently offline  Aram Panasenco
Messages: 41
Registered: April 2010
Member
Matt Francis wrote:
> Hi All, I'm new to IDL but am a reasonable C++ coder. I'm trying to
> set up some object classes in IDL and am having some trouble.
>
> I can create custom objects and use them okay, but I can't seem to get
> a custom object to use another custom object within it. So say I have
> defined allready a class FOO, and now I want another class FOO2 which
> stores within it an instance of FOO:
>
> PRO FOO2__DEFINE
> struct = {FOO2, ...., FOO:<???>, ...}
> END
>
> What I want to know is what goes in<???>. I can't use OBJ_NEW because
> I don't know yet what arguments will be fed to FOO when it gets
> instantiated in some method of FOO2. I tried using simply OBJ_NEW() to
> get a null pointer, but then when I try something like
>
> PRO FOO2::some_method
> ...
> FOO = OBJ_NEW('FOO',[ARGS])
> END
>
> I get an error. I've tried various combinations of *FOO etc to try and
> get the above to work without success.
>
> Can anyone help me? I'm probably thinking too much like a C++
> programmer here, but I can't see that I'm trying to do something crazy
> so there must be a way to do this. Any hints?

Hi Matt!
What's going on here is: In IDL it takes two routines to initialize an
object. One is CLASSNAME__DEFINE, and the other is CLASSNAME::INIT. The
CLASSNAME__DEFINE procedure simply creates the object's class structure.
All properties of the object are initially either zeroes, or null
strings, or empty objects, or etc. CLASSNAME::INIT initializes the
properties. All arguments passed in [ARGS] in FOO = OBJ_NEW('CLASSNAME',
[ARGS]) are arguments to the INIT function. The INIT function
initializes the object's properties and returns 1 if everything went
A-ok (and 0 if the object couldn't be initialized). For example, the
CLASSNAME file could look something like this:

function CLASSNAME::INIT, arg1, arg2, arg3=arg3

if ( (n_elements(arg1) eq 0) or (n_elements(arg2) eq 0) ) then $
return, 0

self.arg1 = arg1
self.arg2 = arg2
if (n_elements(arg3) gt 0) then begin
self.arg3 = arg3
endif else begin
self.arg3 = Obj_New('SomeClass')
endelse

return, 1
end

pro CLASSNAME__DEFINE
struct = {CLASSNAME, $
arg1:0, $
arg2:'', $
arg3:Obj_New() $
}
end

And then you could create a new CLASSNAME object:

myObject = Obj_New('CLASSNAME', 2, 'Custom String')
or
myObj2 = Obj_New('SomeClass', arg1,arg2,arg3)
myObject = Obj_New('CLASSNAME', 2, 'Custom String', arg3 = myObj2)

Hope that helped you understand object creation better

~Aram Panasenco
Re: pointer to object confusion (C++ programmer, IDL n00b) [message #70725 is a reply to message #70722] Mon, 03 May 2010 23:33 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On May 4, 3:18 am, Matt Francis <mattjamesfran...@gmail.com> wrote:

> instantiated in some method of FOO2. I tried using simply OBJ_NEW() to
> get a null pointer, but then when I try something like
>
> PRO FOO2::some_method
>    ...
>    FOO = OBJ_NEW('FOO',[ARGS])
> END
>
> I get an error. I've tried various combinations of *FOO etc to try and
> get the above to work without success.

That is the right idea. What error do you get? Note that what you are
doing above is putting the object reference in a (newly-defined) local
variable foo. The placeholder you made in the class definition is
self.foo, in that scope.
Re: pointer to object confusion (C++ programmer, IDL n00b) [message #70817 is a reply to message #70722] Tue, 04 May 2010 16:56 Go to previous message
Matt Francis is currently offline  Matt Francis
Messages: 94
Registered: May 2010
Member
Ahhh! Thankyou both for your help, that made things clearer.

The problem I was having was actually quite silly, as you pointed out
PP, what I really wanted was

self.foo = obj_new('FOO',[ARGS])

whereas I was simply assigning

foo = obj_new('FOO',[ARGS])

Looks like the code works now. Thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: pointer to object confusion (C++ programmer, IDL n00b)
Next Topic: problem with

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

Current Time: Wed Oct 08 19:05:34 PDT 2025

Total time taken to generate the page: 0.00615 seconds