Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-10-20 21:05:15


----- Original Message -----
From: <rwgk_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, October 20, 2000 8:44 PM
Subject: [boost] py_cpp & passing tuples from Python to C++

> I am trying to expose this member function to Python:
>
> void UnitCell::set_len(const double Len[3]) {
> for (int i = 0; i < 3; i++) this->Len[i] = Len[i];
> }
>
> This is my idea for the hook in the module init function:
>
> UnitCell_class.def(&UCTbx::UnitCell::set_len, "set_len");
>
> The compiler spits out a very verbose error message starting
> with:
>
> cxx: Error: ../py_cpp/caller.h, line 275: #304 no instance of
> overloaded function "py::from_python" matches the argument
> list
> argument types are: (PyObject *, py::Type<const double *>)
>
> Of course, I really want to get the three floating point values
> from a Python tuple (or list). Is this possible?

Yes, but it hasn't made it into the documentation yet.

>How?

You could expose a function like this one to get the desired effect:

#include <py_cpp/objects.h>
void set_len(UnitCell& x, py::Tuple tuple)
{
    double len[3];
    for (std::size_t i =0; i < 3; ++i)
        len[i] = py::from_python(tuple[i].get(), py::Type<double>());
    x.set_len(len);
}

> I also noticed that there are several places where a maximum of five
> arguments is hardwired. What would be involved in increasing the
> number of arguments (I need at least six), or removing the
> limitation altogether?

Sure (also slated for documentation). In the py_cpp folder, run gen_all.py
with an argument of 6.

/boost/development/py_cpp>python gen_all.py 6

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk