The IDL_Object::_overloadMethod function method allows you to create dynamic methods off of IDL objects. By implementing _overloadMethod on your class, users can then make an arbitrary method call on an object reference. This method call could then execute different code based upon the object's current state.

Note: This method is designed to replicate the default behavior of objects that do not use operator overloading. As a result, object classes that do inherit from the IDL_Object class but that do not override this particular method will throw an error when you try to call an unknown method on the object.

Example


Create an IDL_PROXY class that wraps other objects and lets you call any method. Save the following code in a file called idl_proxy__define.pro:

function IDL_Proxy::Init, objref
  self.objref = objref
  return, 1
end
function IDL_Proxy::_overloadMethod, method, arg1, arg2, _EXTRA=ex
  if (ISA(ex)) then begin
    case N_PARAMS()-1 of
    1: result = CALL_METHOD(method, self.objref, arg1, _EXTRA=ex)
    2: result = CALL_METHOD(method, self.objref, arg1, arg2, _EXTRA=ex)
    endcase
  endif else begin
    case N_PARAMS()-1 of
    1: result = CALL_METHOD(method, self.objref, arg1)
    2: result = CALL_METHOD(method, self.objref, arg1, arg2)
    endcase
  endelse
  return, result
end
pro IDL_Proxy__define
  void = {IDL_Proxy, inherits IDL_Object, objref: OBJ_NEW()}
end

Now execute the following code to wrap an IDLgrModel object and call an arbitrary method on it:

COMPILE_OPT idl2
objref = IDLgrModel()
proxy = IDL_Proxy(objref)
PRINT, proxy.GetByName('foo')

Note: We need to ensure that compile_opt idl2 is set so that parentheses are treated like a function call instead of array indexing.

Syntax


In most cases, this method is called indirectly when you make a method call on your object reference. When called explicitly, the syntax is:

Result = Obj->[IDL_Object::]_overloadMethod( Method, Arg1, Arg2, ..., Keyword1=..., Keyword2=... )

Return Value


The return value is an IDL variable containing whatever result your method decides to return.

Arguments


Method

A string giving the name of the method which was called on your object.

Arg1...ArgN

The input arguments to your function.

Keywords


Keywords

The keyword values for your function.

Routine Signature


To overload this function method for an object class, implement a method with the following signature:

FUNCTION class::_overloadMethod, method, arg1, arg2, ..., Keyword1=...

Version History


8.5

Introduced

See Also


IDL_Object::_overloadFunction