Converts a pointer to a Fortran integer so it can passed to a Fortran routine. Intended for use where the Fortran code does not directly look at what the pointer references but simply passes it to library routines to do the manipulations.
#include "ive_fortran.h"
ftn_int_t IVEPtrToFtnId(void* ptr);
There is no Fortran interface.
Returns a non-zero integer if successful and ptr is not 0. Returns zero if the call failed (could not allocate the resources to store the pointer to ID mapping) or if ptr was 0.
Fortran has no direct way to manipulate C++ objects, but as shown below, IVEPtrToFtnId and IVEFtnIdToPtr could be used to write a set of interface routines to perform the manipulation.
#include "ive_fortran.h"
class X {
public:
X();
~X();
void manipulate();
};
extern "C" {
#ifdef FTN_MANGLE_LOWERCASE
#define CREATE_X_OBJECT_FTN createxobject_
#define DELETE_X_OBJECT_FTN deletexobject_
#define MANIPULATE_X_OBJECT_FTN manipulatexobject_
#else
#error "Do not know how to mangle names for Fortran interface"
#endif /* else clause FTN_MANGLE_LOWERCASE */
ftn_int_t
CREATE_X_OBJECT_FTN (void)
{
X* p_x = new X;
return IVEPtrToFtnId(p_x);
}
void
DELETE_XOBJECT_FTN (ftn_int_t* p_id)
{
X* p_x = (X*) IVEFtnIdToPtr(*p_id);
delete p_x;
}
void
MANIPULATE_X_OBJECT_FTN (ftn_int_t* p_id)
{
X* p_x = (X*) IVEFtnIdToPtr(*p_id);
if (p_x != 0) {
p_x->manipulate();
}
}
}
IVEFtnIdToPtr and fortran_types.h
| categories | alphabetical |
modified June 30, 2001
Eric Branlund (eric@msg.ucsf.edu)