Login  Register

swig interface extension problem

Posted by Tinus Rautenbach on Dec 10, 2005; 8:53am
URL: http://quantlib.414.s1.nabble.com/swig-interface-extension-problem-tp10954.html

Hi All
This is my first post, and hopefully not my last, I've been working with
quantlib for a while now, and want to use it from Java in a project.
 
The problem is that I have now spent 2 solid days trying to change the
termstructures.i interface to work for interpolatedzerocurve.
 
The problem is an intermediate class ZeroYieldStructure.  I can't seem to
get swig to generate this class because of it's virtual methods.

I was hoping that someone with a bit more experience with swig and quantlib
could give me some pointers.

Here is what I have at the moment (I have tried man different iterations of
this..) but it complains when trying to compile the cpp wrappers:

//%feature("notabstract") ZeroYieldStructure;
%{
using QuantLib::ZeroYieldStructure;
typedef boost::shared_ptr<ZeroYieldStructure> ZeroYieldStructurePtr;
%}
%rename(ZeroYieldStructure) ZeroYieldStructurePtr;
class ZeroYieldStructurePtr : public boost::shared_ptr<YieldTermStructure> {
        public:
        // ZeroYieldStructure();
 //       ZeroYieldStructure(const Date& referenceDate);
 //       ZeroYieldStructure(Integer settlementDays, const Calendar&);
//   Rate zeroYieldImpl(Time) const = 0;
//   Date maxDate() const;
//   DayCounter dayCounter() const = 0;
               
  };


// flat forward curve
%feature("notabstract") InterpolatedZeroCurve;

%{
using QuantLib::InterpolatedZeroCurve;
using QuantLib::Linear;
%}
 template <class Interpolator>
   class InterpolatedZeroCurve : public ZeroYieldStructure {
      public:
        InterpolatedZeroCurve(const std::vector<Date>& dates,
                              const std::vector<Rate>& yields,
                              const DayCounter& dayCounter,
                              const Interpolator& interpolator =
Interpolator());
        DayCounter dayCounter() const;
        Date maxDate() const;
        Time maxTime() const;
        const std::vector<Time>& times() const;
        const std::vector<Date>& dates() const;
};

%template(LinearInterpolatedZeroCurve) InterpolatedZeroCurve<Linear>;


The erros is as follows:
../quantlib.cxx: In function `jlong
Java_org_quantlib_quantlibJNI_SWIGZeroYieldStructureUpcast(JNIEnv*,
_jclass*, long long int)':
../quantlib.cxx:70529: cannot convert `ZeroYieldStructurePtr*' to
`boost::shared_ptr<QuantLib::YieldTermStructure>*' in assignment


Any help would be appreciated, and hopefully I could get the swing of this
soon to start contributing back.
Regards
Tinus