wrapping a list of structs with boost.python

前端 未结 2 463
离开以前
离开以前 2021-01-03 04:09

I have a C++ function that returns a list of structs. Inside the struct, there are more lists of structs.

struct CameraInfo {
    CamName                              


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 04:57

    If one-way (from c++ to python) wrapping is enough, then you can define a direct converter from list > -- see my vector > converter -- just change types as you need, and don't forget to register the converter.

    You could also have a method returning python::list (which would itself contain python::list's with your objects) which would iterate over c++ nested list and build native python list out of it, but it would only work in one case you have.

    For two-way conversions, either have a look at my file (which contains both-way converters for different types) -- advantage being you get native python lists, disadvatage is copying the objects. For two-way conversion of large collections, indexing_suite is definitely the way to go.

    There is indexing_suite_v2, which is allegedly much better, including direct support for std::list and std::map, though unfortunately quite badly documented (last time I looked, about 1.5 years ago) and not official part of boost::python.

提交回复
热议问题