Interrogate and STL

Hi everyone,

I’m looking for a way to export the methods returning a STL class, like vector, pair, etc…
Is there a way to enable easily this kind of interface between C++ and Python?

Thanks

No, but we usually implement a vector by wrapping it in a (non-template) class that provides operator [](int n) and size(). Interrogate will notice this and create the Python interfaces to make the wrapped object a sequence object, so that you can treat it just like a Python list.

You might even be able to expose a vector directly, but good luck with that–the template nonsense makes everything tricky, not just for interrogate but also for Windows. It’s usually best to wrap it inside some innocuous class, like NodePathCollection for instance.

Or, you can simply define get_item(n) and get_num_items() in your class, then use the MAKE_SEQ macro to synthesize a get_items() method, which will automatically return a Python list. Plenty of examples of this in the Panda source code.

David

I could see it would be difficult in one of your previous replies : [url]CEGUI in Panda3d (WIP)]
Thanks I will try to manage this issue by wrapping.
Thanks for your answers

Don’t we have many of the PTA classes exposed to Python, which are implemented using vectors?

Yes, but there are limitations. In particular, since we can’t expose the iterators, you can’t really do most of the interesting things that STL is good at.

David