Advertisement
Guest User

Untitled

a guest
Jul 6th, 2012
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. %module spam
  2. %{
  3. #include "spam.cpp"
  4. %}
  5.  
  6. %wrapper
  7. %{
  8.  
  9. static int vector3d_getbuffer(PyObject *exporter, Py_buffer *view, int flags)
  10. {
  11.     vector3d* self = 0;
  12.     void *argp1 = 0 ;
  13.     int res1 = 0 ;
  14.  
  15.     static Py_ssize_t shape[1] = {3};
  16.     static Py_ssize_t stride[1] = {sizeof(double)};
  17.  
  18.     res1 = SWIG_ConvertPtr(exporter, &argp1, SWIGTYPE_p_vector3d, 0 |  0 );
  19.     self = reinterpret_cast< vector3d * >(argp1);
  20.  
  21.     view->buf = self->as_pointer();
  22.     view->len = shape[0]*stride[0];
  23.     view->itemsize = stride[0];
  24.     view->readonly = 0;
  25.     view->format="d\0";
  26.     view->ndim = 1;
  27.     view->shape = shape;
  28.     view->strides = stride;
  29.     view->suboffsets = NULL;
  30.     view->internal = NULL;
  31.  
  32.     view->obj=(PyObject*) exporter;
  33.     Py_INCREF(exporter);
  34.     return 0;
  35. }
  36.  
  37. static PyObject* vector3d_get_item(PyObject* self, Py_ssize_t i)
  38. {
  39.     vector3d* arg1 = 0;
  40.     void *argp1 = 0 ;
  41.     int res1 = 0 ;
  42.  
  43.     res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_vector3d, 0 |  0 );
  44.     arg1 = reinterpret_cast< vector3d * >(argp1);
  45.  
  46.     return (PyObject*) PyFloat_FromDouble(arg1->get_data_value(i));
  47. }
  48.  
  49. static int vector3d_set_item(PyObject* self, Py_ssize_t i, PyObject *v)
  50. {
  51.     vector3d * arg1 = 0;
  52.     void *argp1 = 0 ;
  53.     int res1 = 0 ;
  54.  
  55.     res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_vector3d, 0 |  0 );
  56.     arg1 = reinterpret_cast< vector3d * >(argp1);
  57.     arg1->set_data_value(i, PyFloat_AsDouble(v));
  58.  
  59.     return 0;
  60. }
  61.  
  62. static long vector3d_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE;
  63.  
  64. %}
  65.  
  66. %init
  67. %{
  68. // hack! hack!
  69. SwigPyBuiltin__vector3d_type.ht_type.tp_flags = vector3d_flags;
  70. %}
  71.  
  72. %feature("python:bf_getbuffer") vector3d "vector3d_getbuffer"
  73. %feature("python:sq_item") vector3d "vector3d_get_item"
  74. %feature("python:sq_ass_item") vector3d "vector3d_set_item"
  75. %include "spam.cpp"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement