Search code examples
c++swigauto-generate

SWIG: How to change the autogenerated "delete_xxx" code


I have the following declarations in SWIG interface file and a class named Test :

 %extend qual_name {
 public:
    ~short_name() 
    {
        //Do something here
    };
 }

The above declarations generate a SWIGINTERN void delete_Test(Test* self) method in the swig generated CPP file. The problem is that I have a lot of classes and the same code gets generated for all delete_XXX methods. I want to modify the contents of this delete_XXX method for one particular class. How do I do it?

I tried the %ignore keyword but that just ignores the whole definition and even removes any calls to it. Not sure if %typedef can be used to modify a method content.


Solution

  • I resolved it by adding the following lines to the interface file:

     %ignore qual_name::~short_name;
     %extend Test {  
     public:  
        ~Test() { // custom code here };  
     }