swig-fortran / swig

This fork of SWIG creates Fortran wrapper code from C++ headers.
http://www.swig.org
Other
42 stars 11 forks source link

How do I change the SWIGPOLICY for assignment? #188

Open hbivens opened 3 months ago

hbivens commented 3 months ago

In fortran.cxx there's this code:

// Define policy
if (CPlusPlus) {
  if (SwigType *name = Getattr(n, "name")) {
    String *policystr = Swig_name_mangle_string(name);
    Insert(policystr, 0, "SWIGPOLICY_");
    Setattr(n, "fortran:policy", policystr);

    // Define policies for the class
    const char *policy = "swig::ASSIGNMENT_DEFAULT";
    if (Getattr(n, "feature:smartptr")) {
      policy = "swig::ASSIGNMENT_SMARTPTR";
    } else if (!GetFlag(n, "allocate:default_destructor")) {
      policy = "swig::ASSIGNMENT_NODESTRUCT";
    }
    Printv(f_policies, "#define ", policystr, " ", policy, "\n", NULL);
  }
}

How do I set the policy to swig::ASSIGNMENT_SMARTPTR in the interface file?

This works, but I think there's a better way using features?

%{
#include "MyClass.h"

#undef SWIGPOLICY_MyClass
#define SWIGPOLICY_MyClass swig::ASSIGNMENT_SMARTPTR
%}