Welcome to the Harris Geospatial product documentation center. Here you will find reference guides, help documents, and product libraries.


  >  Docs Center  >  IDL Reference  >  Object-Oriented Programming  >  IDL_Object::_overloadFunction

IDL_Object::_overloadFunction

IDL_Object::_overloadFunction

The IDL_Object::_overloadFunction function method allows you to create "function pointers" in IDL. By implementing the _overloadFunction method on your class, users can then make a function call on an object reference. This function 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 the object as a function.

Example


Let's create an IDL_SMOOTH class that wraps various smoothing functions. Save the following code in a file called idl_smooth__define.pro:

function IDL_Smooth::Init, BOXCAR=boxcar, LEE=lee, MEDIAN=median
  if (KEYWORD_SET(boxcar)) then self.method = 0
  if (KEYWORD_SET(lee)) then self.method = 1
  if (KEYWORD_SET(median)) then self.method = 2
  return, 1
end
 
function IDL_Smooth::_overloadFunction, data, width, _EXTRA=extra
  case self.method of
    0: result = SMOOTH(data, width, _EXTRA=extra)
    1: result = LEEFILT(data, width, _EXTRA=extra)
    2: result = MEDIAN(data, width, _EXTRA=extra)
  endcase
  return, result
end
 
pro IDL_Smooth__define
  void = {IDL_Smooth, inherits IDL_Object, method: 0}
end

Now execute the following code to create an IDL_Smooth object and call it like a function:

COMPILE_OPT idl2
FUNC = IDL_Smooth(/MEDIAN)
x = RANDOMU(seed,100)
result = FUNC(x, 9, /DOUBLE)
HELP, result

IDL prints:

RESULT          DOUBLE    = Array[100]

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 function call on your object reference. When called explicitly, the syntax is:

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

Return Value


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

Arguments


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::_overloadFunction, arg1, arg2, ..., Keyword1=...

Version History


8.5

Introduced

See Also


IDL_Object::_overloadMethod



© 2018 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us