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

Home » Public Forums » archive » Re: Are user-defined private methods possible?
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: Are user-defined private methods possible? [message #67172] Fri, 10 July 2009 01:33
Oliver is currently offline  Oliver
Messages: 6
Registered: July 2009
Junior Member
cool - I'm always amazed about the creativity of people when it comes
to circumvent all those IDL annoyances.

For my lib I used the much simpler approach of defining a 'magic'
number, something along the lines of

pro myClass::privateMethod, arg1, arg2, magic
if( magic ne 148 ) then message, 'private calls only...'
; ...
end

This is obviously no protection at all against someone who on purpose
wants
to call this method, but then its his/her own fault and I would
consider this
bad style and a programming error.

Speaking about mimicking OO concepts in IDL: what also annoys me is
the absence of static methods and class variables.
For the former I use the convention

pro myClass_staticMethodName

i.e. by mixing "classic" IDL and object orientation. Ugly but it
works.
For the latter I use commons:

common myClassStaticVars initializedFlag, var1, var2, var3

The problem with this approach is that variables cannot be initialized
here.
So I define a method

pro myClass_initializeStaticVars

which I either call at program start or (if there're not too many)
in the constructor and all 'static methods' of the class.
InitializedFlag
is set to '1' during the first call so repeated calls have no effect.

Cheers
Oliver
Re: Are user-defined private methods possible? [message #67198 is a reply to message #67172] Wed, 08 July 2009 12:17 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
F�LDY Lajos wrote:
>
> On Wed, 8 Jul 2009, Paul van Delst wrote:
>
>> As the subject states, are user-defined private methods possible in IDL?
>>
>> I have some object methods that I want to be private to the class
>> (like Init and Cleanup) but I can't find any info on how to do that in
>> the IDL help. Once the methods in question are invoked (and, thus,
>> compiled) in a public method, they're accessible from outside the class.
>
> You can not prevent calls to your "private" methods, but you can check
> whether the caller is a method of your class or not:
>
> ; cut here, copy to test.pro and .ru test
> ;
> pro o::private
> catch, stranger
> if stranger ne 0 then $
> begin
> catch, /cancel
> goto, prn
> endif
>
> if not obj_isa((scope_varfetch('self', level=-1)), 'o') then stranger=1
>
> prn:
> if stranger ne 0 then print, 'private call failed' $
> else print, 'private call succeeded'
> end
>
>
> pro o::public
> self->private
> end
>
>
> s={o, i:0}
> o=obj_new('o')
> print, 'calling private from class method:'
> o->public
> print, 'calling private directly:'
> o->private
> end
>
> ; cut here

schweet! I'll see if I can put this code in my error handler include file for use....

Thanks,

paulv
Re: Are user-defined private methods possible? [message #67199 is a reply to message #67198] Wed, 08 July 2009 12:16 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Paul van Delst writes:
>
>> As the subject states, are user-defined private methods possible in IDL?
>>
>> I have some object methods that I want to be private to the class (like Init and Cleanup)
>> but I can't find any info on how to do that in the IDL help. Once the methods in question
>> are invoked (and, thus, compiled) in a public method, they're accessible from outside the
>> class.
>
> There is nothing like a "private" method in IDL.
> However, there are some things you can do to keep
> neighborhood eyes from oggling the babes in the
> backyard pool.
>
> For example, you can give your "private" methods
> ugly names (I usually append an underscore to the
> method name), and you can set the HIDDEN compile
> option, so the casual user doesn't know it is there
> when the object code is compiled:
>
> PRO myobject::_myprivateMethod
> compile_opt HIDDEN
> ...
> END
>
> But nothing is going to stop a determined 14-year-old
> with a good set of field glasses. :-(

Cool, thanks!

cheers,

paulv
Re: Are user-defined private methods possible? [message #67201 is a reply to message #67199] Wed, 08 July 2009 11:56 Go to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Wed, 8 Jul 2009, Paul van Delst wrote:

> As the subject states, are user-defined private methods possible in IDL?
>
> I have some object methods that I want to be private to the class (like Init
> and Cleanup) but I can't find any info on how to do that in the IDL help.
> Once the methods in question are invoked (and, thus, compiled) in a public
> method, they're accessible from outside the class.

You can not prevent calls to your "private" methods, but you can check
whether the caller is a method of your class or not:

; cut here, copy to test.pro and .ru test
;
pro o::private
catch, stranger
if stranger ne 0 then $
begin
catch, /cancel
goto, prn
endif

if not obj_isa((scope_varfetch('self', level=-1)), 'o') then stranger=1

prn:
if stranger ne 0 then print, 'private call failed' $
else print, 'private call succeeded'
end


pro o::public
self->private
end


s={o, i:0}
o=obj_new('o')
print, 'calling private from class method:'
o->public
print, 'calling private directly:'
o->private
end

; cut here


regards,
lajos
Re: Are user-defined private methods possible? [message #67202 is a reply to message #67201] Wed, 08 July 2009 10:59 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> As the subject states, are user-defined private methods possible in IDL?
>
> I have some object methods that I want to be private to the class (like Init and Cleanup)
> but I can't find any info on how to do that in the IDL help. Once the methods in question
> are invoked (and, thus, compiled) in a public method, they're accessible from outside the
> class.

There is nothing like a "private" method in IDL.
However, there are some things you can do to keep
neighborhood eyes from oggling the babes in the
backyard pool.

For example, you can give your "private" methods
ugly names (I usually append an underscore to the
method name), and you can set the HIDDEN compile
option, so the casual user doesn't know it is there
when the object code is compiled:

PRO myobject::_myprivateMethod
compile_opt HIDDEN
...
END

But nothing is going to stop a determined 14-year-old
with a good set of field glasses. :-(

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: nike clothing,nike shoes,online store,http://www.nbashoe.com air Jordan Shoes,Nike Air Jordans, Air Force Ones,Retro Air Jordan, Bape Hoodies,Bape shoes-Tencent Traveler|Jordan Shoes,Nike Air Jordans, Air Force Ones,Retro Air Jordan, Bape Hoodie
Next Topic: Re: Question about user input in IDL

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

Current Time: Wed Oct 08 11:43:19 PDT 2025

Total time taken to generate the page: 0.00697 seconds