[C++-sig] passing wrapped c++ objects to boost wrapped function

Kim Branson kim.branson at gmail.com
Thu Jan 4 09:11:49 CET 2007


Hi,

i'm trying to glue together some c++ code using python as an  
intermediate layer.

i have python bindings for a library, and i can create python wrapped  
instances of this object in python

mol = OEMol()
in python this is a proxy of the C++ instance.
  <openeye.oechem.OEMol; proxy of C++ OEMolWrapper instance at  
_0030dfd0_p_OEMolWrapper>

I have other c++ code  that uses an OEMol interface like so.

int numberOfAtoms(OEMol &mol)
{
     int numAtoms = 0 ;
     numAtoms = mol.NumAtoms();
     return numAtoms;
}

i created a simple wrapper for it.

#include "functions.cpp"
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(test)
{
     def("numberOfAtoms", numberOfAtoms);
     def("finalBondIndex",finalBondIndex);
}

trying to pass a mol object into it from python produces the  
following result.

Traceback (most recent call last):
   File "functionsTest.py", line 35, in ?
     numatoms = test.numberOfAtoms(mol);
Boost.Python.ArgumentError: Python argument types in
     test.numberOfAtoms(OEMol)
did not match C++ signature:
     numberOfAtoms(OEChem::OEMol {lvalue})

I assume this is failing because the boost wrapped function does not  
get OEChem::OEMol, but the python object PyObject?

How can i wrap the function to solve this?   I'm unsure on what  
exactly is being passed in.

cheers

Kim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070104/2f6e96c6/attachment.htm>


More information about the Cplusplus-sig mailing list