Salome HOME
RNV: Porting to swig-3
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderTypemaps.i
index be6d74b2d222a089f13ce6c1dc7fa35ef197c288..9df1cb801a82838371eeb58baf06ea15a9cdad2a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -197,6 +197,20 @@ static PyObject *convertFieldDoubleVecToPy(const std::vector<MEDCoupling::MEDCou
   return ret;
 }
 
+PyObject *convertVecPairIntToPy(const std::vector< std::pair<int,int> >& vec)
+{
+  PyObject *ret(PyList_New(vec.size()));
+  int rk=0;
+  for(std::vector< std::pair<int,int> >::const_iterator iter=vec.begin();iter!=vec.end();iter++,rk++)
+    {
+      PyObject *elt=PyTuple_New(2);
+      PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first));
+      PyTuple_SetItem(elt,1,SWIG_From_int((*iter).second));
+      PyList_SetItem(ret,rk,elt);
+    }
+  return ret;
+}
+
 PyObject *convertVecPairVecStToPy(const std::vector< std::pair<std::vector<std::string>, std::string > >& vec)
 {
   int sz=(int)vec.size();
@@ -356,3 +370,31 @@ int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) thr
   else
     throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !");
 }
+
+void convertToMapIntDataArrayInt(PyObject *pyMap, std::map<int, MCAuto<DataArrayInt> >& cppMap)
+{
+  if(!PyDict_Check(pyMap))
+    throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : input is not a python map !");
+  PyObject *key, *value;
+  Py_ssize_t pos(0);
+  cppMap.clear();
+  while (PyDict_Next(pyMap,&pos,&key,&value))
+    {
+      if(!PyInt_Check(key))
+        throw INTERP_KERNEL::Exception("convertToMapIntDataArrayInt : keys in map must be PyInt !");
+      long k(PyInt_AS_LONG(key));
+      void *argp(0);
+      int status(SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0));
+      if(!SWIG_IsOK(status))
+        {
+          std::ostringstream oss; oss << "convertToMapIntDataArrayInt : values in map must be DataArrayInt !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+      DataArrayInt *arg(reinterpret_cast<DataArrayInt*>(argp));
+      MCAuto<DataArrayInt> arg2(arg);
+      if(arg)
+        arg->incrRef();
+      cppMap[k]=arg2;
+    }
+}
+