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

  >  Docs Center  >  Using IDL  >  Example: Overloading the HELP and PRINT/PRINTF Procedures


Example: Overloading the HELP and PRINT/PRINTF Procedures

Example: Overloading the Help and Print Procedures

In this example, we create the spaceCraftObject_doc class, which stores a spacecraft’s name and mass. We overload the class’s _overloadHelp, _overloadImpliedPrint, and _overloadPrint methods, so that calling the help or print procedures with this class of object results in the output we desire.

The spaceCraftObject_doc object definition and overloaded function method code listed in this section is contained in the procedure file spacecraftobject_doc__define.pro, and is located in the examples/doc/objects subdirectory of the IDL distribution. To view the file in an IDL editor window, enter .EDIT spacecraftobject_doc__define.pro at the IDL command line.

For more information, refer to

FUNCTION spaceCraftObject_doc::Init, type, mass
    self.shipType = type
    self.shipMass = mass
    RETURN, 1
FUNCTION spaceCraftObject_doc::_overloadHelp, varname
    tempString = varname + ' = ' + '{spaceCraftObject_doc: ' $
      + self.shipType + STRING(self.shipMass) + '}'
      RETURN, tempString
FUNCTION spaceCraftObject_doc::_overloadPrint
    tempString = self.shipType + '  ' + STRING(self.shipMass) $
        + ' kg'
      RETURN, tempString
FUNCTION spaceCraftObject_doc::_overloadImpliedPrint, varname
  return, self->spaceCraftObject_doc::_overloadPrint()
PRO spaceCraftObject_doc__define
    struct = {spaceCraftObject_doc, INHERITS IDL_Object, $
      shipType: '', $
      shipMass:  0 }

Now enter the following commands in IDL:

IDL> a=SpaceCraftObject_doc('Soyuz', 6650)
IDL> a

IDL prints:

A = {spaceCraftObject_doc: Soyuz    6650}
Soyuz      6650 kg
Soyuz      6650 kg

Notice that for the _overloadImpliedPrint method we called our _overloadPrint method. This ensures that we get the same output whether we are using Implied Print or the PRINT procedure.

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