Salome HOME
on the road of full remapper fine to fine + debug on MEDCouplingIMesh::getBoundingBox
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
index 46527b8234a74a66a00224005d5e310acace7e53..7b76dd62ec8381fd32c575429fca5017fed6b574 100644 (file)
@@ -318,7 +318,7 @@ MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype
           ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
           PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
           typename ParaMEDMEM::MemArray<T>::Deallocator tmp(ParaMEDMEM::MemArray<T>::CDeallocator);
-          void **tmp2(reinterpret_cast<void**>(&tmp));
+          void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
           void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
           mma.setParameterForDeallocator(objs);
           mma.setSpecificDeallocator(numarrdeal);
@@ -399,7 +399,7 @@ int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
 }
 
 template<class MCData, class T>
-PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
+PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
 {
   if(!self->isAllocated())
     {
@@ -407,7 +407,6 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
   ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
-  int nbComp=self->getNumberOfComponents();
   if(nbComp==0)
     {
       std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !"; 
@@ -415,7 +414,7 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
     }
   int nbDims=nbComp==1?1:2;
   npy_intp dim[2];
-  dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp;
+  dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
   const T *bg=self->getConstPointer();
   PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
   if(mem.isDeallocatorCalled())
@@ -424,7 +423,7 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
         {// case for the first call of toNumPyArray
           PyObject *ref(PyWeakref_NewRef(ret,NULL));
           typename ParaMEDMEM::MemArray<T>::Deallocator tmp(mem.getDeallocator());
-          void **tmp2(reinterpret_cast<void**>(&tmp));
+          void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
           void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
           mem.setParameterForDeallocator(objs);
           mem.setSpecificDeallocator(numarrdeal);
@@ -451,6 +450,12 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
   return ret;
 }
 
+template<class MCData, class T>
+PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
+{
+  return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
+}
+
 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
 
@@ -624,6 +629,19 @@ static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL
     }
 }
 
+static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
+{
+  PyObject *ret=PyList_New(arr.size());
+  for(std::size_t i=0;i<arr.size();i++)
+    {
+      PyObject *t=PyTuple_New(2);
+      PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
+      PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
+      PyList_SetItem(ret,i,t);
+    }
+  return ret;
+}
+
 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
 {
   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";