On 06/25/2011 11:40 AM, Jay Riley wrote:
I figured I might be able to expose the tuple by some variation on the
below:

class_<ActionTargetTuple>("ActionTargetTuple")
.def("get", &ActionTargetTuple::get<int>,
return_value_policy<reference_existing_object>())
;

then use get from python, but if it is doable in this way, I'm not sure
what the set up needs to be. Does anyone know how to do this/could
suggest an alternative?

tuple::get is templated on the number you want - it doesn't take that as an argument. I don't think there's a way to do this without writing your own "get" with a switch statement or a lot of template metaprogramming (I don't think get<int> will compile):

object get(ActionTargetTuple & self, int n) {
    switch (n) {
    case 0:
        return object(self.get<0>());
    case 1:
        return object(self.get<1>());
    default:
        PyErr_SetString(PyExc_IndexError, "Index out of range");
        throw_error_already_set();
    }
}

class<ActionTargetTuple>("ActionTargetTuple")
    .def("get", &get);


I think that's roughly what you need.


Jim
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to