next up previous contents index
Next: Catching and Throwing Exceptions Up: FORTRAN 77 Bindings Previous: Basic Types   Contents   Index


Calling Methods From FORTRAN 77

All SIDL methods are implemented as FORTRAN 77 subroutines regardless of whether they have a return value or not. For object methods (as opposed to static methods), the object or interface pointer is passed as the first argument to the subroutine before all the formally declared arguments. The exception is static methods, where the object or interface pointer does not appear in the argument list at all.

When a method has a return value, a variable to hold the return value should be passed as an argument following the formally declared arguments. This extra argument behaves like an out parameter.

All methods can potentially throw exceptions, and the exception pointer is passed as an extra argument after the return value argument (if any). The exception argument behaves like an out parameter. A non-zero value indicates that an exception has been thrown. Exception handling for FORTRAN 77 is covered in greater depth in Section 8.4.

The name of the subroutine that FORTRAN 77 clients should call is derived from the fully qualified name of the class and the name(s) of the method. If the method is specified as overloaded (i.e., has a name extension), the method's full name will be used. That is, the concatenation of the short name and the name extension will be used for a unique method name. Hence, to determine the subroutine name for FORTRAN 77, take the fully qualified name, replace all the periods with underscores, append an underscore, append the short method name, append the method name extension (if any) and then append ``_f''.

These general rules will be illustrated with a set of practical examples. For the time being, the example codes will not check the out except argument that indicates if an exception has occurred. For example, to call the deleteRef() method on a sidl.BaseInterface interface, you would write:


       integer*8 interface1, except
C      code to initialize interface1 here
       call sidl_BaseInterface_deleteRef_f(interface1, except)

To call the isSame method on a sidl.BaseInterface, you would write:


       integer*8 interface1, interface2, except
       logical areSame
C      code to initialize interface1 and interface2 here
       call sidl_BaseInterface_isSame_f(interface1,
     $     interface2, areSame, except)
C      now areSame holds the return value

To call the isType method on a sidl.BaseInterface, you would write:


       integer*8 interface1, except
       logical typeMatch
C      code to initialize interface1 here
       call sidl_BaseInterface_isType_f(interface1, 'x.y.z',
     $   typeMatch, except)

Here is a code snippet to find the name of the SIDL class that implements a particular sidl.BaseInterface object. This example requires a sequence of related calls to SIDL methods.


       integer*8 interface1, classinfo, except
       character*256 className
C      code to initialize interface1 here
       call sidl_BaseInterface_getClassInfo_f(interface1,
     $   classinfo, except)
       call sidl_ClassInfo_getName(classinfo, className, except)
       call sidl_BaseInterface_deleteRef_f(classinfo, except)

Examples of calls to SIDL overloaded methods are based on the overload_sample.sidl file shown in Section 5.6. Recall that the file describes three versions of the getValue method. The first takes no arguments, the second takes an integer argument, and the third takes a boolean. Each is called in the code snippet below:


      integer*8 t, except
      logical b1, bretval
      integer*4 i1, iretval

      call Overload_Sample__create_f (t, except)

      call Overload_Sample_getValue_f (t, iretval, except)
      call Overload_Sample_getValueInt_f (t, i1, iretval, except)
      call Overload_Sample_getValueBool_f (t, b1, bretval, except)

For interfaces and classes, there are two implicit methods called _cast() and _cast2(). Both of these methods are used to convert from one type to another, and each can be used for upcasting up downcasting. If the cast succeeds, these method calls increment the reference count, and the caller owns the returned reference. In Babel releases prior to 0.11.0, these methods were special cases that did not increment the reference count, but now they behave like normal methods. The returned reference is owned by the caller.

_cast() is a static method. It tries to convert its opaque argument to the type of the class indicated by the method name. For example, x_y_z__cast(obj, xyz, except) will try to convert obj to type x.y.z. If except is nonzero, an exception occurred; otherwise, if xyz is nonzero, the cast was successful.

_cast2() is an object method. Its return type is opaque, and it has one formal argument, a string in addition to the implicit object/interface reference. The _cast() method attempts to cast the object/interface to the named type.

For non-abstract classes, there is an implicit method called _create(). It creates and returns an instance of the class.

Here are examples of the use of these two methods:


      integer*8 object, interface, except
      call sidl_BaseClass__create_f(object, except)
      call sidl_BaseInterface__cast_f(object, interface, except)
c     the following call to _cast2 is equivalent to the previous _cast call
      call sidl_BaseClass__cast2_f(object, 'SIDL.BaseInterface',
     $     interface, except)

Please note the presence of two underscores between BaseClass and create and between BaseClass and cast; the extra underscore is there because the first character of the method name is an underscore.

Below is an example call to the addSearchPath() in the sidl.Loader class. This is an example of calling a static method.


      integer*8 except
      call sidl_Loader_addSearchPath_f('/try/looking/here', except)
      

Your FORTRAN 77 must manage any object references created by the calls you make. This means you must call either deleteRef on any object references returned by a subroutine call or give the object reference to another part of the code that will take responsibility for deleteRef'ing it. For example, you can return an object reference to your caller, and they will assume responsibility for the object reference.


next up previous contents index
Next: Catching and Throwing Exceptions Up: FORTRAN 77 Bindings Previous: Basic Types   Contents   Index


babel-0.99.0
users_guide Last Modified 2006-06-27

http://www.llnl.gov/CASC/components
components@llnl.gov