Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWIG: add downcasting #284

Open
KrisThielemans opened this issue Nov 6, 2018 · 6 comments · May be fixed by #709
Open

SWIG: add downcasting #284

KrisThielemans opened this issue Nov 6, 2018 · 6 comments · May be fixed by #709

Comments

@KrisThielemans
Copy link
Collaborator

A difficulty is that some members return a base class ptr, which cannot be downcasted in python. Example

input=recon.get_input_data()

Then input is of type ExamData and there's no way to get at members of a ProjData (or whatever it is).

This might be possible as mentioned for instance at tpaviot/pythonocc-generator#28

@rainman110
Copy link

@KrisThielemans
Copy link
Collaborator Author

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.

@rainman110
Copy link

It's both, object generation and object dispatch.

@KrisThielemans
Copy link
Collaborator Author

KrisThielemans commented Jun 15, 2019

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.

@KrisThielemans
Copy link
Collaborator Author

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.

@KrisThielemans
Copy link
Collaborator Author

probably we'd have to list CListmodeData, SPECTListmodeData. or even ideally all their derived classes, which becomes rather hard to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants