[C++-sig] [boost::python] Exposing a pointer to a vector to Python.

Brandon bmiller at soe.sony.com
Wed May 13 23:43:27 CEST 2009


All,

I'm currently exposing much of our C++ API to Python and have had much success
with everything up to here.  I'm running into issues trying to expose a pointer
to a vector which holds pointers to instances of a class.

The question is:  is there more I have to do to export a pointer to a vector of
a class type we've defined?  Or is there something simpler that I'm not seeing?
 I've tried exposing a pointer to a vector, but that didn't turn out well.  I
was getting value_type undefined errors and could not find any postings on them.
 Perhaps that way was correct but I didn't not have the whole piece in place.

Thanks in advance!

CODE: (all of my code and sample types replace our actual data types)
-------------------------------------------------------------------------

C++
-------

class sample {
public:
   std::vector<Derived*> *vec;
};


class_<std::vector<Derived *> >("std_vector_Derived")
        .def(vector_indexing_suite<vector<Derived *>())
;

class_<sample>("sample")
   .def_readwrite("vec", &sample::vec)
;

Python
--------
inst = EXPOSED_MODULE.EXPOSED_FUNCT( )      
#EXPOSED_MODULE/FUNCT are replacements for the real name...
#inst is an instance of "sample" returned from a exposed c++ function after it
was populated it with data.

print inst.vec[0] 
#Assume vector was populated from C++ side and verified to be populated in C++.
#Problem occurs here because of type...

STDERR (PYTHON)
---------------
TypeError: No to_python(by-value) converter found for C++ type: class
std::vector<class Derived*, class std::allocator<class Derived*> > *










More information about the Cplusplus-sig mailing list