0
votes

I'm creating wrappers using SWIG for python for my software library and I have the following function:

    template<class PR>
    boost::shared_ptr<JobT<PR> > Client::WaitForJob() {
        boost::shared_ptr<JobT<PR> > job;
        while (!job.get()) {
            list<boost::shared_ptr<Job> > jobs = GetJobs(p_jobName, p_jobID, "", JobT<PR>::New);
            while (jobs.size() > 0) {
                job = boost::dynamic_pointer_cast<JobT<PR> >(jobs.front());
                jobs.pop_front();
                if (ClaimJob(job)) return job;
                else job.reset();
            }
        }
        return job;
    }

In this case I'm able to create a class for the JobT and I also used the boos_pointer. Currently I have the following in my interface file:

%template(jobme) JobT; %include "boost_shared_ptr.i" %shared_ptr(jobme)

%template(waitforme) Client::WaitForJob;

The waitforme function template return a pointer to a swig python object. This is correct but i want it to be the same as a jobme pointer.

Can someone point out if this is possible ??

1

1 Answers

0
votes

The Swig object you get back is a proxy for the jobme. It should work just like a JobT wherever you need it.

Ah, I think I see the problem. You need to instantiate the JobT and Client::WaitForJob for each PR you have:

%include "boost_shared_ptr.i"
%shared_ptr(JobT<Foo>);

#include <JobT.hpp>
%template(Job##NAME) JobT<Foo>;
%template Client::WaitForJob<Foo>;

So %template instantiates a template, but it doesn't guess all the possible types you might use to instantiate it with.