Login  Register

SWIG interface files

Posted by Andre Louw-2 on Jun 05, 2002; 4:18am
URL: http://quantlib.414.s1.nabble.com/SWIG-interface-files-tp10103.html

Hi,

I have a cpp class in a library of my own that inherits off
QuantLib::Instrument. I now need to create a SWIG file for this.

I assumed that I would only need to "%import Instruments.i" to get the
needed definitions, this leads to all kinds of compile errors.
Using "%include Instruments.i" doesn't hack it either, redoing all the
needed "typedef" statements in my interface file solves the compile errors
but I get weird errors when using my library: accessing
DayCounter.yearFraction(d1,d2) for instance gives me an error saying it
needs 5 arguments (only 3 supplied) - it's as if it doesn't know the last 2
are default arguments.

This is my SWIG file:

#ifndef myinstr_i
#define myinstr_i

%include Instruments.i
%include TermStructures.i
%include String.i

%{
#include <myinstr.hpp>
using MyNameSpace::MyInstr;
typedef RelinkableHandle<QuantLib::TermStructure>
TermStructureRelinkableHandle;
typedef Handle<QuantLib::Instrument> InstrumentHandle;
typedef QuantLib::Handle<MyInstr> MyInstrHandle;
typedef std::string String;
%}

// fake inheritance between handles
%name(MyInstr) class MyInstrHandle
: public InstrumentHandle {
  public:
    // constructor redefined below
    ~MyInstrHandle();
};

%addmethods MyInstrHandle {
    MyInstrHandle(TermStructureRelinkableHandle tStruct,
        String isinCode, String description) {
            return new MyInstrHandle(
               new MyInstr(tStruct, isinCode, description));
    }
    double fairRate() {
       return (*self)->fairRate();
    }
}

#endif

What is the correct way of doing something like this (i.e using SWIG
interface-files from other projects)?

Any help appreciated.

Andre

 
-------------------------------------------------------------------------
This e-mail is intended only for the use of the individual or entity named
above and may contain information that is confidential and privileged,
proprietary to the company and protected by law. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of this e-mail is strictly prohibited. Opinions, conclusions and
other information in this message that do not relate to the official
business of our company shall be understood as neither given nor endorsed by
it.