The following table describes IDL’s operators and provides information on the object method you must implement in order to override each for a custom object class.

Operator

Non-Overloaded Operation

Operator Type

Object Method Name

Function or Procedure

++

Increment

Unary

Not overloadable

N/A

--

Decrement

Unary

Not overloadable

N/A

[ ]

Indexing, right side

Unary

_overloadBracketsRightSide (see Overloading the Array Indexing Operator for additional details)

Function

[ ]

Indexing, left side

Unary

_overloadBracketsLeftSide (see Overloading the Array Indexing Operator for additional details)

Procedure

-

Negate

Unary

_overloadMinusUnary

Function

NOT

Bitwise NOT

Unary

_overloadNOT

Function

~

Logical NOT

Unary

_overloadTilde

Function

+

Addition

Binary

_overloadPlus

Function

-

Subtraction

Binary

_overloadMinus

Function

*

Multiplication

Binary

_overloadAsterisk

Function

/

Division

Binary

_overloadSlash

Function

^

Exponentiation

Binary

_overloadCaret

Function

MOD

Modulo

Binary

_overloadMOD

Function

<

Minimum

Binary

_overloadLessThan

Function

>

Maximum

Binary

_overloadGreaterThan

Function

AND

Bitwise AND

Binary

_overloadAND

Function

OR

Bitwise OR

Binary

_overloadOR

Function

XOR

Bitwise XOR

Binary

_overloadXOR

Function

EQ

Relational Equal

Binary

_overloadEQ

Function

NE

Relational Not Equal

Binary

_overloadNE

Function

GE

Greater Than or Equal

Binary

_overloadGE

Function

GT

Greater Than

Binary

_overloadGT

Function

LE

Less Than or Equal

Binary

_overloadLE

Function

LT

Less Than

Binary

_overloadLT

Function

#

Matrix multiplication

Binary

_overloadPound

Function

##

Matrix Multiplication

Binary

_overloadPoundPound

Function

&&

Logical AND

Binary

Not overloadable, but respects truth value returned by
_overloadIsTrue

N/A

||

Logical OR

Binary

Not overloadable, but respects truth value returned by
_overloadIsTrue

N/A

if (obj)...

Logical: obj_valid(obj)

Unary

Not overloadable, but respects truth value returned by
_overloadIsTrue

Function

(? : )

Conditional expression

Binary

Not overloadable, but respects truth value returned by
_overloadIsTrue

N/A

*

Pointer dereference

Unary

Not overloadable

N/A

=

Assignment operator

Binary

Not overloadable

N/A

[ ]

Array concatenation

Unary

Not overloadable

N/A

(exp)

Grouping of expressions with parentheses

Unary

Not overloadable

N/A

.

Method invocation

Binary

Not overloadable

N/A

.

Property invocation

Binary

Not overloadable, but will call GetProperty or SetProperty

N/A

Note: The behavior of the LOGICAL_AND, LOGICAL_OR, and LOGICAL_TRUE functions is not affected by object operator overloading, but it does respect the truth values returned by the _overloadIsTrue function (see The -_overloadIsTrue Function for more information).

Overloading Compound Assignment Operators


Compound assignment operators cannot be overloaded directly. They will be overloaded if the operator that is compounded is overloaded. For example, if the addition operator “+” is overloaded, “+=” will also be overloaded using the same user method.

The _overloadIsTrue Function


By default, evaluating an object reference for TRUE or FALSE (as in an IF block) yields TRUE if the object reference is valid, and FALSE for null objects. However, you can change this default behavior by implementing the _overloadIsTrue function method. This method allows you to evaluate an object and use your own criteria to determine if its state is TRUE (1) or FALSE (0).

The signature of the _overloadIsTrue object method is:

FUNCTION className::_overloadIsTrue
   ; Determine whether the specified object meets the true
   ; criteria, and place a 1 or a 0 in truth_value
   RETURN, truth_value
END

For example, you could create an object class called highVoltage, with a VOLTAGE property. You could implement the object’s _overloadIsTrue function to check the VOLTAGE property, and return TRUE if VOLTAGE is greater than or equal to 220 volts. The method definition might look something like this:

FUNCTION highVoltage::_overloadIsTrue
   high_or_low = self->VOLTAGE GE 220 ? 1 : 0
   RETURN, high_or_low
END

Supposing you instantiated an object of the highVoltage class in ohighVoltage, the evaluation code would look like this:

IF (ohighVoltage) THEN ...

Note that the _overloadIsTrue function is a unary routine. In an expression such as (obj1 || obj2) where both objects enable overloading, the _overloadIsTrue function of obj1 is called. If the first object’s _overloadIsTrue function returns TRUE, the logical OR operator short-circuits and the expression evaluates as TRUE. If the first object’s _overloadIsTrue function returns FALSE, the logical OR does not short-circuit, and the second object’s _overloadIsTrue function is called, whose result is used as the value of the entire expression.

The _overloadIsTrue method is called whenever an overloaded object’s truth value must be evaluated. Specifically, when an overloaded object appears in any of the following constructions:

  • IF...THEN...ELSE statement
  • WHILE...DO statement
  • REPEAT...UNTIL statement
  • Logical AND (&&)
  • Logical OR (||)
  • Conditional expression (?:)

Overloadable Information Routines


In addition to the standard operators listed in the previous table, object classes that inherit from the IDL_Object class can customize the information returned by the following IDL routines:

Routine

Default Behavior

Object Method Name

HELP

Prints heap variable ID and object class name.

_overloadHelp

N_ELEMENTS

Always reports 1 for a scalar object.

_overloadSize

PRINT/PRINTF

Prints heap variable ID and object class name.

_overloadPrint

SIZE

Always reports information for a scalar object.

_overloadSize

Implied Print

Prints heap variable ID and object class name.

_overloadImpliedPrint

Overloadable Program Control Statements


If your object inherits from the IDL_Object class, you can iterate through the elements of your object using the FOREACH statement. You are responsible for writing your object’s ::_overloadForeach function method, which retrieves the value of the next object element in the iteration.