]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Ready for DataArrayDouble objs.
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 2 Mar 2015 10:04:33 +0000 (11:04 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 2 Mar 2015 10:04:33 +0000 (11:04 +0100)
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i

index 0639745d32cd3a0dd1054f2f13155e4627357fa0..6c161e3ecd522b1182942e457f1534320806c7f2 100644 (file)
@@ -586,6 +586,7 @@ namespace ParaMEDMEM
     virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const throw(INTERP_KERNEL::Exception);
     virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const throw(INTERP_KERNEL::Exception);
     virtual DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception);
+    virtual void unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings) throw(INTERP_KERNEL::Exception);
     static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception);
     static bool IsStaticGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception);
     static bool IsLinearGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception);
@@ -976,6 +977,42 @@ namespace ParaMEDMEM
              PyList_SetItem(res,i,PyInt_FromLong(*iL));
            return res;
          }
+
+         virtual PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<double> a0;
+           std::vector<int> a1;
+           std::vector<std::string> a2;
+           self->getTinySerializationInformation(a0,a1,a2);
+           PyObject *ret(PyTuple_New(3));
+           PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
+           PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
+           int sz(a2.size());
+           PyObject *ret2(PyList_New(sz));
+           {
+             for(int i=0;i<sz;i++)
+               PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
+           }
+           PyTuple_SetItem(ret,2,ret2);
+           return ret;
+         }
+
+         virtual PyObject *serialize() const throw(INTERP_KERNEL::Exception)
+         {
+           DataArrayInt *a0Tmp(0);
+           DataArrayDouble *a1Tmp(0);
+           self->serialize(a0Tmp,a1Tmp);
+           PyObject *ret(PyTuple_New(2));
+           PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(a0Tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+           PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(a1Tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+           return ret;
+         }
+
+         void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2) const throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<std::string> littleStrings;
+           self->resizeForUnserialization(tinyInfo,a1,a2,littleStrings);
+         }
          
          static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception)
          {
index 104f463044bfac3bbec58a5c627f1c99ce33df1a..56087f7ee060dfe621cb74a3742e5a70ecfe97d8 100644 (file)
@@ -2174,6 +2174,60 @@ namespace ParaMEDMEM
         PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
         return ret;
       }
+
+      // serialization
+
+      PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+      {
+#ifdef WITH_NUMPY
+        if(!self->isAllocated())
+          throw INTERP_KERNEL::Exception("PyWrap of DataArrayDouble.__getnewargs__ : self is not allocated !");
+        PyObject *ret(PyTuple_New(1));
+        PyObject *ret0(PyDict_New());
+        PyObject *tmp1(PyInt_FromLong(0));
+        PyObject *kw1(ParaMEDMEM_DataArrayDouble_toNumPyArray(self));
+        PyDict_SetItem(ret0,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
+        PyTuple_SetItem(ret,0,ret0);
+        return ret;
+#else
+        throw INTERP_KERNEL::Exception("PyWrap of DataArrayDouble.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !");
+#endif
+      }
+      
+      PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
+      {
+        PyObject *ret(PyTuple_New(2));
+        std::string a0(self->getName());
+        const std::vector<std::string> &a1(self->getInfoOnComponents());
+        PyTuple_SetItem(ret,0,PyString_FromString(a0.c_str()));
+        //
+        int sz(a1.size());
+        PyObject *ret1(PyList_New(sz));
+        for(int i=0;i<sz;i++)
+          PyList_SetItem(ret1,i,PyString_FromString(a1[i].c_str()));
+        PyTuple_SetItem(ret,1,ret1);
+        //
+        return ret;
+      }
+
+      void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+      {
+        static const char MSG[]="DataArrayDouble.__setstate__ : expected input is a tuple of size 2 with string as 1st arg and list of string as 2nd arg !";
+        if(!PyTuple_Check(inp))
+          throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid input ! Invalid overwrite of __getstate__ ?");
+        int sz(PyTuple_Size(inp));
+        if(sz!=2)
+          throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid tuple in input ! Should be of size 2 ! Invalid overwrite of __getstate__ ?");
+        PyObject *a0(PyTuple_GetItem(inp,0));
+        if(!PyString_Check(a0))
+          throw INTERP_KERNEL::Exception(MSG);
+        PyObject *a1(PyTuple_GetItem(inp,1));
+        std::vector<std::string> a1cpp;
+        if(!fillStringVector(a1,a1cpp))
+          throw INTERP_KERNEL::Exception(MSG);
+        self->setName(PyString_AsString(a0));
+        self->setInfoOnComponents(a1cpp);
+      }
     }
   };