Note that there are some explanatory texts on larger screens.

plurals
  1. POwrapping a list of structs with boost.python
    text
    copied!<p>I have a C++ function that returns a list of structs. Inside the struct, there are more lists of structs.</p> <pre><code>struct CameraInfo { CamName name; std::list&lt;CamImageFormat&gt; lImgFormats; std::list&lt;CamControls&gt; lCamControls; }; std::list&lt;CameraInfo&gt; getCameraInfo() { std::list&lt;CameraInfo&gt; lCamerasInfo; // fill lCamerasInfo return lCamerasInfo; } </code></pre> <p>then for exporting it I was using:</p> <pre><code>class_&lt;CameraNode....&gt; &gt;("CameraNode", no_init) ... ... .def("listCameraInfo", make_function(&amp;CameraNode::listCameraInfo)) .staticmethod("listCameraInfo") ... ; </code></pre> <p>And it was OK since I was using cout to print the data on screen... I would like now to use the return value and it's content from python like properties, this way:</p> <pre><code>cameras = [] cameras = CameraNode.getCameraInfo() print cameras[0].name print cameras[0].lImgFormats[0] and so on... </code></pre> <p>Is this even possible?? Should I be using add_property instead? I don't think I can create a class for every struct. This design made sense while I was working on C++ only but now that I would have to wrap it, I'm getting more and more confused.</p> <p>Any advice on wrapping std::list with boost.python in a general way would be very well accepted.</p> <h1>Edit:</h1> <p>I will add here links that I've found useful: <a href="http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/python/iterators.html" rel="nofollow">Iterators</a> <a href="http://wiki.python.org/moin/boost.python/StlContainers" rel="nofollow">StlContainers</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload