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

Brett Calcott brett.calcott at paradise.net.nz
Wed May 28 11:59:19 CEST 2003


"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> 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.
>

Thanks, that looks like it will do the job. I had looked at this code
actually but I needed you to point out the relevant bits :)

Thanks for letting me plunder the code -- is something like this
worth putting back into the boost-python library?

Cheers,
Brett







More information about the Cplusplus-sig mailing list