[C++-sig] registering simple conversions from/to python

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Mon May 26 18:35:24 CEST 2003


--- Brett Calcott <brett.calcott at paradise.net.nz> 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




More information about the Cplusplus-sig mailing list