From 76eeb6dd79737c70172a945ad5d104619c76dbd5 Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 1 Jun 2006 14:59:35 +0000 Subject: [PATCH] for ALLIANCES: add in and out typemaps for vectors of fields with different interlaces --- src/MEDMEM_SWIG/libMEDMEM_Swig.i | 321 ++++++++++--------------------- 1 file changed, 101 insertions(+), 220 deletions(-) diff --git a/src/MEDMEM_SWIG/libMEDMEM_Swig.i b/src/MEDMEM_SWIG/libMEDMEM_Swig.i index 4910ae850..b41157dd0 100644 --- a/src/MEDMEM_SWIG/libMEDMEM_Swig.i +++ b/src/MEDMEM_SWIG/libMEDMEM_Swig.i @@ -123,222 +123,6 @@ typedef FIELD FIELDINTNOINTERLACE; %rename(assign) *::operator=; -/* - typemap for vector C++ object -*/ - -%typemap(python,in) vector< FAMILY * >, const vector< FAMILY * > -{ - /* typemap in for vector */ - /* Check if is a list */ - - if (PyList_Check($input)) { - int size = PyList_Size($input); - $1 = vector(size); - - for (int i=0; i < size; i++) - { - PyObject * tmp = PyList_GetItem($input,i); - FAMILY * f; - - int err = SWIG_ConvertPtr(tmp, (void **) &f, $descriptor(FAMILY *), - SWIG_POINTER_EXCEPTION); - - if (err == -1) - { - char * message = "Error in typemap(python,in) for vector each component should be a FAMILY pointer"; - PyErr_SetString(PyExc_RuntimeError, message); - return NULL; - } - // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper - // $1[i] = f; - $1.at(i) = f; - } - } - else - { - PyErr_SetString(PyExc_TypeError,"not a list"); - return NULL; - } -} - -%typemap(python,out) vector< FAMILY * > -{ - /* typemap out for vector */ - int size = $1.size(); - $result = PyList_New(size); - - for (int i=0;i C++ object -*/ - -%typemap(python,in) vector< SUPPORT * >, const vector< SUPPORT * > -{ - /* typemap in for vector */ - /* Check if is a list */ - - if (PyList_Check($input)) { - int size = PyList_Size($input); - $1 = vector(size); - - for (int i=0; i < size; i++) - { - PyObject * tmp = PyList_GetItem($input,i); - SUPPORT * s; - - int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(SUPPORT *), - SWIG_POINTER_EXCEPTION); - - if (err == -1) - { - char * message = "Error in typemap(python,in) for vector each component should be a SUPPORT pointer"; - PyErr_SetString(PyExc_RuntimeError, message); - return NULL; - } - // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper - //$1[i] = s; - $1.at(i) = s; - } - } - else - { - PyErr_SetString(PyExc_TypeError,"not a list"); - return NULL; - } -} - -%typemap(python,out) vector< SUPPORT * > -{ - /* typemap out for vector */ - int size = $1.size(); - $result = PyList_New(size); - - for (int i=0;i * >, const vector< FIELD< double > * > -{ - /* typemap in for vector *> */ - /* Check if is a list */ - - if (PyList_Check($input)) { - int size = PyList_Size($input); - $1.resize(size); - - for (int i=0; i < size; i++) - { - PyObject * tmp = PyList_GetItem($input,i); - FIELD * s; - - int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(FIELD *), - SWIG_POINTER_EXCEPTION); - - if (err == -1) - { - char * message = "Error in typemap(python,in) for vector *> each component should be a SUPPORT pointer"; - PyErr_SetString(PyExc_RuntimeError, message); - return NULL; - } - - // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper - //$1[i] = s; - $1.at(i) = s; - } - } - else - { - PyErr_SetString(PyExc_TypeError,"not a list"); - return NULL; - } -} - -%typemap(python,out) vector< FIELD< double > * > -{ - /* typemap out for vector *> */ - int size = $1.size(); - $result = PyList_New(size); - - for (int i=0;i *),0); - PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(FIELD *),0); - - PyList_SetItem($result,i,tmp); - } -} - -%typemap(python,in) vector< FIELD< int > * >, const vector< FIELD< int > * > -{ - /* typemap in for vector *> */ - /* Check if is a list */ - - if (PyList_Check($input)) { - int size = PyList_Size($input); - $1.resize(size); - - for (int i=0; i < size; i++) - { - PyObject * tmp = PyList_GetItem($input,i); - FIELD * s; - - int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(FIELD *), - SWIG_POINTER_EXCEPTION); - - if (err == -1) - { - char * message = "Error in typemap(python,in) for vector *> each component should be a SUPPORT pointer"; - PyErr_SetString(PyExc_RuntimeError, message); - return NULL; - } - - // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper - //$1[i] = s; - $1.at(i) = s; - } - } - else - { - PyErr_SetString(PyExc_TypeError,"not a list"); - return NULL; - } -} - -%typemap(python,out) vector< FIELD< int > * > -{ - /* typemap out for vector *> */ - int size = $1.size(); - $result = PyList_New(size); - - for (int i=0;i *),0); - PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(FIELD *),0); - - PyList_SetItem($result,i,tmp); - } -} - - /* typemap in for PyObject * fonction Python wrapping of a double or int fonction pointeur @@ -456,6 +240,103 @@ typedef FIELD FIELDINTNOINTERLACE; } %} +/************************************************** + IN typemaps for some std::vector's +**************************************************/ + +/* MACRO: IN typemap for std::vector C++ object */ +%define TYPEMAP_INPUT_VECTOR_BY_VALUE( TYPE ) +{ + /* typemap in for vector */ + /* Check if is a list */ + if (PyList_Check($input)) + { + int size = PyList_Size($input); + vector< TYPE > tmpVec(size); + + for (int i=0; i < size; i++) + { + PyObject * tmp = PyList_GetItem($input,i); + TYPE elem; + + int err = SWIG_ConvertPtr(tmp, (void **) &elem, $descriptor(TYPE), + SWIG_POINTER_EXCEPTION); + if (err == -1) + { + char * message = "Error in typemap(python,in) for vector" + "each component should be a TYPE"; + PyErr_SetString(PyExc_RuntimeError, message); + return NULL; + } + tmpVec[i] = elem; + } + $1 = tmpVec; + } + else + { + PyErr_SetString(PyExc_TypeError,"not a list"); + return NULL; + } +} +%enddef + +%typemap(python,in) vector< FAMILY* >, const vector< FAMILY* > +{ TYPEMAP_INPUT_VECTOR_BY_VALUE( FAMILY * ) } + +%typemap(python,in) vector< SUPPORT* >, const vector< SUPPORT* > +{ TYPEMAP_INPUT_VECTOR_BY_VALUE( SUPPORT * ) } + +%typemap(python,in) vector< FIELDDOUBLE* >, const vector< FIELDDOUBLE* > +{ TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDDOUBLE * ) } + +%typemap(python,in) vector< FIELDINT* >, const vector< FIELDINT* > +{ TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDINT * ) } + +%typemap(python,in) vector< FIELDDOUBLENOINTERLACE* >, const vector< FIELDDOUBLENOINTERLACE* > +{ TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDDOUBLENOINTERLACE * ) } + +%typemap(python,in) vector< FIELDINTNOINTERLACE* >, const vector< FIELDINTNOINTERLACE* > +{ TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDINTNOINTERLACE * ) } + + +/************************************************** + OUT typemaps for some std::vector's +**************************************************/ + +/* MACRO: OUT typemap for std::vector C++ object */ +%define TYPEMAP_OUTPUT_VECTOR_BY_VALUE( TYPE ) +{ + /* typemap out for vector */ + int size = $1.size(); + $result = PyList_New(size); + + for (int i=0;i +{ TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FAMILY * ) } + +%typemap(python,out) vector< SUPPORT* > +{ TYPEMAP_OUTPUT_VECTOR_BY_VALUE( SUPPORT * ) } + +%typemap(python,out) vector< FIELDDOUBLE* > +{ TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDDOUBLE * ) } + +%typemap(python,out) vector< FIELDINT* > +{ TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDINT * ) } + +%typemap(python,out) vector< FIELDDOUBLENOINTERLACE* > +{ TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDDOUBLENOINTERLACE * ) } + +%typemap(python,out) vector< FIELDINTNOINTERLACE* > +{ TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDINTNOINTERLACE * ) } + /* enum of the C++ MED used in the Python API @@ -1159,14 +1040,14 @@ public : return self->intersectSupports(Supports); } - %newobject mergeFieldsDouble(const vector< FIELD* > others); - FIELD * mergeFieldsDouble(const vector< FIELD* > others) + %newobject mergeFieldsDouble(const vector< FIELDDOUBLE* > others); + FIELD * mergeFieldsDouble(const vector< FIELDDOUBLE* > others) { return (FIELD *)self->mergeFields(others); } - %newobject mergeFieldsInt(const vector< FIELD* > others); - FIELD * mergeFieldsInt(const vector< FIELD* > others) + %newobject mergeFieldsInt(const vector< FIELDINT* > others); + FIELD * mergeFieldsInt(const vector< FIELDINT* > others) { return (FIELD *)self->mergeFields(others); } -- 2.39.2