Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %module spam
- %{
- #include "spam.cpp"
- %}
- %wrapper
- %{
- static int vector3d_getbuffer(PyObject *exporter, Py_buffer *view, int flags)
- {
- vector3d* self = 0;
- void *argp1 = 0 ;
- int res1 = 0 ;
- static Py_ssize_t shape[1] = {3};
- static Py_ssize_t stride[1] = {sizeof(double)};
- res1 = SWIG_ConvertPtr(exporter, &argp1, SWIGTYPE_p_vector3d, 0 | 0 );
- self = reinterpret_cast< vector3d * >(argp1);
- view->buf = self->as_pointer();
- view->len = shape[0]*stride[0];
- view->itemsize = stride[0];
- view->readonly = 0;
- view->format="d\0";
- view->ndim = 1;
- view->shape = shape;
- view->strides = stride;
- view->suboffsets = NULL;
- view->internal = NULL;
- view->obj=(PyObject*) exporter;
- Py_INCREF(exporter);
- return 0;
- }
- static PyObject* vector3d_get_item(PyObject* self, Py_ssize_t i)
- {
- vector3d* arg1 = 0;
- void *argp1 = 0 ;
- int res1 = 0 ;
- res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_vector3d, 0 | 0 );
- arg1 = reinterpret_cast< vector3d * >(argp1);
- return (PyObject*) PyFloat_FromDouble(arg1->get_data_value(i));
- }
- static int vector3d_set_item(PyObject* self, Py_ssize_t i, PyObject *v)
- {
- vector3d * arg1 = 0;
- void *argp1 = 0 ;
- int res1 = 0 ;
- res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_vector3d, 0 | 0 );
- arg1 = reinterpret_cast< vector3d * >(argp1);
- arg1->set_data_value(i, PyFloat_AsDouble(v));
- return 0;
- }
- static long vector3d_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE;
- %}
- %init
- %{
- // hack! hack!
- SwigPyBuiltin__vector3d_type.ht_type.tp_flags = vector3d_flags;
- %}
- %feature("python:bf_getbuffer") vector3d "vector3d_getbuffer"
- %feature("python:sq_item") vector3d "vector3d_get_item"
- %feature("python:sq_ass_item") vector3d "vector3d_set_item"
- %include "spam.cpp"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement