Open KrisThielemans opened 6 years ago
This is possible using swigs factory feature, see example https://github.com/DLR-SC/tigl/blob/c62f4e0ebbc3ed9accbf46a2a51f21421ce590ed/bindings/python_internal/configuration.i#L406
Thanks for the suggestion! I had a look at swig source. This looks really useful. However, it is not clear to me if this only applies to actual factories (i.e. method that create a new object), or also to other methods that just return a (shared) ptr, as in the example above. I have the impression it's only the former (but my SWIG is rusty). Maybe this is a question for the SWIG list though.
It's both, object generation and object dispatch.
Here's the SWIG code https://github.com/swig/swig/blob/master/Lib/typemaps/factory.swg
confusingly, the SWIG FAQ makes it look much harder.
Possibly this might be as simple as include something like
%factory(stir::ExamData& stir::Reconstruction::get_input_data, stir::ListmodeData, stir::ProjData)
although how that will work templates I don't know.
probably we'd have to list CListmodeData
, SPECTListmodeData
. or even ideally all their derived classes, which becomes rather hard to maintain.
A difficulty is that some members return a base class ptr, which cannot be downcasted in python. Example
Then
input
is of typeExamData
and there's no way to get at members of aProjData
(or whatever it is).This might be possible as mentioned for instance at https://github.com/tpaviot/pythonocc-generator/issues/28