logo       

Re: registering simple conversions from/to python: msg#00231

python.c++

Subject: Re: registering simple conversions from/to python

--- Brett Calcott <brett.calcott@xxxxxxxxxxxxxxx> wrote:
> Is there a simple recipe for registering these conversions?

I do something like this all the time, although I wouldn't claim that it is
"simple." There are some hints here:

http://www.boost.org/libs/python/doc/v2/faq.html#question2

Alternative 2 seem most appropriate in your case. I would use
boost:array<double, 2> as the vehicle for your data. Look here for a complete
example:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cctbx/scitbx/array_family/boost_python/regression_test_ext.cpp?rev=1.3&content-type=text/vnd.viewcvs-markup

Look for:

boost::python::to_python_converter<
boost::array<int, 2>,
scitbx::boost_python::container_conversions::to_tuple<
boost::array<int, 2> > >();

And:

scitbx::boost_python::container_conversions::from_python_sequence<
boost::array<double, 3>,
scitbx::boost_python::container_conversions::fixed_size_policy>();

To be able to use this copy the header file

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cctbx/scitbx/include/scitbx/boost_python/container_conversions.h?rev=1.10&content-type=text/vnd.viewcvs-markup

to your own project. There are no dependencies for this file other than boost.

Ralf


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise