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

Home » Public Forums » archive » Re: overload init function in class/object ?
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: overload init function in class/object ? [message #34984 is a reply to message #34982] Tue, 06 May 2003 13:26 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
paul wisehart (wisehart@runbox.com) writes:

> (So technically speaking you _cannot_ overload functions in
> IDL? You just use optional parameters to get the same effact?)

Isn't that a distinction without a difference?

When your parameters can be anything you would like
them to be, and you can have as many as you like,
what else could possibly be meant by "overloading".

Here is code for a GETCOLOR method on my ColorTool object.
The variable theColor can be absent, a scalar string, or a
string array. The variable colorIndex can be absent, a
scalar, or an array.

FUNCTION ColorTool::GetColor, theColor, colorIndex, $
AllColors=allcolors, $
Cancel=cancelled, $
Decomposed=decomposedState, $
_Extra=extra, $
Names=names, $
Row=row, $
Triple=triple, $
_Extra=extraKeywords

@cat_error_handler

; Make sure you have a color name and color index.

CASE N_Elements(theColor) OF
0: BEGIN
theColor = 'White'
IF N_Elements(colorIndex) EQ 0 THEN $
colorIndex = !P.Color < (!D.Table_Size - 1) $
ELSE colorIndex = 0 > colorIndex < (!D.Table_Size - 1)
ENDCASE

1: BEGIN
type = Size(theColor, /TNAME)
IF type NE 'STRING' THEN $
Message, 'The color must be expressed as a color name.'
IF N_Elements(colorIndex) EQ 0 THEN $
colorIndex = !P.Color < (!D.Table_Size - 1) $
ELSE colorIndex = 0 > colorIndex < (!D.Table_Size - 1)
ENDCASE

ELSE: BEGIN
type = Size(theColor, /TNAME)
IF type NE 'STRING' THEN $
Message, 'The colors must be expressed as color names.'
ncolors = N_Elements(theColor)
CASE N_Elements(colorIndex) OF
0: colorIndex = Indgen(ncolors) + $
(!D.Table_Size - (ncolors + 1))
1: colorIndex = Indgen(ncolors) + colorIndex
ELSE: IF N_Elements(colorIndex) NE ncolors THEN $
Message, 'Index vector must be the same ' + $
'length as color name vector.'
ENDCASE

ENDCASE


Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: sec : U Re: checking for Demo mode
Next Topic: Interpolation from a regular to an irregular grid?

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

Current Time: Sun Oct 12 12:16:39 PDT 2025

Total time taken to generate the page: 0.95696 seconds