Re: %factory and templates
William S Fulton <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftDckjMoym7tPX4jK_cxM7dfWQfFbifRRw2L3o-UcowAig@mail.gmail.com> |
On Fri, 9 Oct 2020 at 16:42, <[email protected]> wrote: > 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? > > > > > You need to instantiate your templates with %template if you aren't already. William _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user