%factory and templates

<[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
Hi

 

We are trying to use %factory (see https://github.com/swig/swig/blob/master/Lib/typemaps/factory.swg) to let SWIG do automatic downcasting to the actual types, as opposed to just returning the base class. However, at present it isn’t working for us. Our hunch is that this is due to templates and typemaps (which I don’t understand well enough). We haven’t boiled it down to a simple example yet, but I thought maybe would know the answer straight-away 😊

 

We have a hierarchy like this (apologies for long names, but I kept the ones in our actual code)

 

stir::GeneralisedPrior<TargetT >

stir::QuadraticPrior<elemT> : public stir::GeneralisedPrior<DiscretisedDensity<3,elemT> >

stir::RelativeDifferencePrior<elemT> : public stir::GeneralisedPrior<DiscretisedDensity<3,elemT> >

 

(cutting out some intermediate classes)

 

We then have some other templated class that has a member

 

stir::GeneralisedPrior<TargetT > *GeneralisedObjectiveFunction<TargetT>::get_prior_ptr()

 

So, in our SWIG interface file we say

 

%newobject *::get_prior_ptr;

%factory(stir::GeneralisedPrior *stir::GeneralisedObjectiveFunction::get_prior_ptr, stir::QuadraticPrior, stir::PLSPrior, stir::RelativeDifferencePrior);

 

i.e. without any template stuff at all, but it seems that the typemap generated by %factory isn’t picked up.

 

Anyone any suggestions?

 

Thanks!

 

Kris

 

PS: You can find the PR to our code here https://github.com/UCL/STIR/pull/709

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.