[PySide] (shiboken) how to wrap template class?
matthew.woehlke at kitware.com
Thu Jul 11 23:04:09 CEST 2013
On 2013-07-11 14:23, John Ehresman wrote:
> On 7/11/13 1:27 PM, Matthew Woehlke wrote:
>> I'm trying to write shiboken bindings for some code that makes heavy use
>> of std[::tr1]::shared_ptr, but cannot figure out how to wrap the same.
>> I could've sworn I'd seen shiboken wrapping template stuff somewhere,
>> but can't seem to find any examples (besides the built-in container
>> types, anyway). Can someone recommend a course of action?
> I don't know if Qt makes use of templates like this; if it does, I would
> look at the PySide code for examples.
I couldn't find any; I was hoping someone on the list might be able to
point to one :-).
> I recently had some success using <inject-code> to inject manually
> written code rather than trying to get arguments to convert, but then
> I'm more familiar with the Python C api than most and didn't have very
> many methods to wrap.
So... I tried getting Shiboken to wrap a simple template class, and it
ended badly. I suspect Shiboken may not 'really' support template
classes at all except for known container types. I suppose if I was
feeling ambitious, I could add a pointer container type.
That said, what I got to work for me is to typedef all of the shared
pointer usages and to wrap the typedefs. This got me wrapped classes but
with no methods. However I was able to add:
<add-function signature="get" return-type="D*">
<inject-code class="target" position="beginning">
%RETURN_TYPE the_ptr = %CPPSELF->get();
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](the_ptr);
...which seems to be sufficient for something usable and to understand
generally how to get it working.
It's too bad I can't template away adding the method, or even the entire
wrapping of the pointer :-).
More information about the PySide