Salome HOME
Merge branch 'V8_2_BR'
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderCommon.i
index 3602338fbd40248fdf88cde45383c99c3a0b6db8..b5d3561289db76cec6d1263cab263fdfbc42d6a4 100644 (file)
@@ -153,6 +153,7 @@ using namespace MEDCoupling;
 %newobject MEDCoupling::MEDFileFields::__iter__;
 %newobject MEDCoupling::MEDFileFields::extractPart;
 
+%newobject MEDCoupling::MEDFileWritableStandAlone::serialize;
 %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::New;
 %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::deepCopy;
 %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::shallowCpy;
@@ -298,7 +299,8 @@ using namespace MEDCoupling;
 namespace MEDCoupling
 {
   bool HasXDR();
-  std::string MEDFileVersionStr();
+  std::string MEDFileVersionStr() throw(INTERP_KERNEL::Exception);
+  std::string MEDFileVersionOfFileStr(const std::string& fileName) throw(INTERP_KERNEL::Exception);
   void SetEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception);
   void SetCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception);
   void SetTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception);
@@ -351,7 +353,7 @@ namespace MEDCoupling
 
 %inline
 {
-  PyObject *MEDFileVersionSwig()
+  PyObject *MEDFileVersionSwig() throw(INTERP_KERNEL::Exception)
   {
     int major,minor,release;
     MEDCoupling::MEDFileVersion(major,minor,release);
@@ -362,7 +364,7 @@ namespace MEDCoupling
     return ret;
   }
 
-  PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
+  PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName) throw(INTERP_KERNEL::Exception)
   {
     std::vector< std::pair<int,int> > res=MEDCoupling::GetFieldIterations(type,fileName,meshName,fieldName);
     PyObject *ret=PyList_New(res.size());
@@ -536,6 +538,43 @@ namespace MEDCoupling
   {
   public:
     void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception);
+    void write30(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception);
+    %extend
+       {
+         DataArrayByte *serialize() const throw(INTERP_KERNEL::Exception)
+         {
+           MCAuto<DataArrayByte> ret(self->serialize());
+           return ret.retn();
+         }
+
+         PyObject *__getstate__() throw(INTERP_KERNEL::Exception)
+         {
+           PyObject *ret(PyList_New(0));
+           return ret;
+         }
+
+         void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+         {
+         }
+
+         PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+         {
+#ifdef WITH_NUMPY
+           PyObject *ret(PyTuple_New(1));
+           PyObject *ret0(PyDict_New());
+           DataArrayByte *retCpp(MEDCoupling_MEDFileWritableStandAlone_serialize(self));
+           PyObject *numpyArryObj=SWIG_NewPointerObj(SWIG_as_voidptr(retCpp),SWIGTYPE_p_MEDCoupling__DataArrayByte, SWIG_POINTER_OWN | 0 );
+           {// create a dict to discriminite in __new__ if __init__ should be called. Not beautiful but not idea ...
+             PyObject *tmp1(PyInt_FromLong(0));
+             PyDict_SetItem(ret0,tmp1,numpyArryObj); Py_DECREF(tmp1); Py_DECREF(numpyArryObj);
+             PyTuple_SetItem(ret,0,ret0);
+           }
+           return ret;
+#else
+           throw INTERP_KERNEL::Exception("PyWrap of MEDFileData.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !");
+#endif
+         }
+       }
   };
   
   class MEDFileMeshReadSelector
@@ -776,7 +815,7 @@ namespace MEDCoupling
     }
   };
   
-  class MEDFileEquivalenceBase : public RefCountObject
+  class MEDFileEquivalenceBase : public RefCountObject, public MEDFileWritableStandAlone
   {
   private:
     MEDFileEquivalenceBase();
@@ -835,7 +874,7 @@ namespace MEDCoupling
     }
   };
 
-  class MEDFileEquivalencePair : public RefCountObject
+  class MEDFileEquivalencePair : public RefCountObject, public MEDFileWritableStandAlone
   {
   private:
     MEDFileEquivalencePair();
@@ -877,7 +916,7 @@ namespace MEDCoupling
     }
   };
   
-  class MEDFileEquivalences : public RefCountObject
+  class MEDFileEquivalences : public RefCountObject, public MEDFileWritableStandAlone
   {
   private:
     MEDFileEquivalences();
@@ -916,6 +955,7 @@ namespace MEDCoupling
   public:
     static MEDFileMesh *New(const std::string& fileName, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     static MEDFileMesh *New(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
+    static MEDFileMesh *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     virtual MEDFileMesh *createNewEmpty() const throw(INTERP_KERNEL::Exception);
     virtual MEDFileMesh *deepCopy() const throw(INTERP_KERNEL::Exception);
     virtual MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception);
@@ -1228,6 +1268,7 @@ namespace MEDCoupling
     static MEDFileUMesh *New(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     static MEDFileUMesh *New(const std::string& fileName, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     static MEDFileUMesh *New(const MEDCouplingMappedExtrudedMesh *mem) throw(INTERP_KERNEL::Exception);
+    static MEDFileUMesh *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileUMesh *New();
     static const char *GetSpeStr4ExtMesh();
     ~MEDFileUMesh();
@@ -1280,6 +1321,11 @@ namespace MEDCoupling
            return MEDFileUMesh::New(mem);
          }
 
+         MEDFileUMesh(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileUMesh::New(db);
+         }
+
          MEDFileUMesh()
          {
            return MEDFileUMesh::New();
@@ -1543,6 +1589,7 @@ namespace MEDCoupling
   {
   public:
     static MEDFileCMesh *New();
+    static MEDFileCMesh *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileCMesh *New(const std::string& fileName, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     static MEDFileCMesh *New(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception);
@@ -1563,6 +1610,17 @@ namespace MEDCoupling
          {
            return MEDFileCMesh::New(fileName,mName,dt,it,mrs);
          }
+
+         MEDFileCMesh(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileCMesh::New(db);
+         }
+
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileCMesh");
+         }
          
          PyObject *getMesh() const throw(INTERP_KERNEL::Exception)
          {
@@ -1578,6 +1636,7 @@ namespace MEDCoupling
   {
   public:
     static MEDFileCurveLinearMesh *New();
+    static MEDFileCurveLinearMesh *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileCurveLinearMesh *New(const std::string& fileName, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     static MEDFileCurveLinearMesh *New(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception);
     void setMesh(MEDCouplingCurveLinearMesh *m) throw(INTERP_KERNEL::Exception);
@@ -1597,6 +1656,17 @@ namespace MEDCoupling
          {
            return MEDFileCurveLinearMesh::New(fileName,mName,dt,it,mrs);
          }
+
+         MEDFileCurveLinearMesh(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileCurveLinearMesh::New(db);
+         }
+
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileCurveLinearMesh");
+         }
          
          PyObject *getMesh() const throw(INTERP_KERNEL::Exception)
          {
@@ -1671,7 +1741,7 @@ namespace MEDCoupling
   {
   public:
     static MEDFileMeshes *New();
-    static MEDFileMeshes *New(const std::string& fileName) throw(INTERP_KERNEL::Exception);
+    static MEDFileMeshes *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     MEDFileMeshes *deepCopy() const throw(INTERP_KERNEL::Exception);
     int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
     std::vector<std::string> getMeshesNames() const throw(INTERP_KERNEL::Exception);
@@ -1693,6 +1763,17 @@ namespace MEDCoupling
            return MEDFileMeshes::New(fileName);
          }
 
+         MEDFileMeshes(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileMeshes::New(db);
+         }
+
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileMeshes");
+         }
+
          std::string __str__() const throw(INTERP_KERNEL::Exception)
            {
              return self->simpleRepr();
@@ -2058,6 +2139,7 @@ namespace MEDCoupling
     static MEDFileField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception);
     static MEDFileField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
     static MEDFileField1TS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+    static MEDFileField1TS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileField1TS *New();
     MEDCoupling::MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception);
@@ -2088,11 +2170,22 @@ namespace MEDCoupling
            return MEDFileField1TS::New(fileName,fieldName,iteration,order,loadAll);
          }
 
+         MEDFileField1TS(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileField1TS::New(db);
+         }
+
          MEDFileField1TS()
          {
            return MEDFileField1TS::New();
          }
 
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileField1TS");
+         }
+         
          void copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
          {
            const DataArrayDouble *arr=0;
@@ -2192,6 +2285,7 @@ namespace MEDCoupling
   public:
     static MEDFileIntField1TS *New();
     static MEDFileIntField1TS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+    static MEDFileIntField1TS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
     static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception);
     MEDCoupling::MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception);
@@ -2226,6 +2320,17 @@ namespace MEDCoupling
         return MEDFileIntField1TS::New(fileName,fieldName,iteration,order,loadAll);
       }
 
+      MEDFileIntField1TS(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+      {
+        return MEDFileIntField1TS::New(db);
+      }
+
+      // serialization
+      static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+      {
+        return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileIntField1TS");
+      }
+
       std::string __str__() const throw(INTERP_KERNEL::Exception)
       {
         return self->simpleRepr();
@@ -2647,6 +2752,7 @@ namespace MEDCoupling
     static MEDFileFieldMultiTS *New() throw(INTERP_KERNEL::Exception);
     static MEDFileFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
     static MEDFileFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+    static MEDFileFieldMultiTS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     //
     MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
@@ -2674,6 +2780,17 @@ namespace MEDCoupling
          {
            return MEDFileFieldMultiTS::New(fileName,fieldName,loadAll);
          }
+         
+         MEDFileFieldMultiTS(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileFieldMultiTS::New(db);
+         }
+         
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileFieldMultiTS");
+         }
 
          static MEDFileFieldMultiTS *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, PyObject *entities, bool loadAll=true)
          {
@@ -2798,6 +2915,7 @@ namespace MEDCoupling
     static MEDFileIntFieldMultiTS *New();
     static MEDFileIntFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
     static MEDFileIntFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+    static MEDFileIntFieldMultiTS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     //
     void appendFieldNoProfileSBT(const MEDCouplingFieldInt *field) throw(INTERP_KERNEL::Exception);
     void appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception);
@@ -2825,6 +2943,17 @@ namespace MEDCoupling
         return MEDFileIntFieldMultiTS::New(fileName,fieldName,loadAll);
       }
 
+      MEDFileIntFieldMultiTS(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+      {
+        return MEDFileIntFieldMultiTS::New(db);
+      }
+      
+      // serialization
+      static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+      {
+        return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileIntFieldMultiTS");
+      }
+      
       static MEDFileIntFieldMultiTS *LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, PyObject *entities, bool loadAll=true)
       {
         std::vector<std::pair<int,int> > tmp(convertTimePairIdsFromPy(entities));
@@ -2868,6 +2997,7 @@ namespace MEDCoupling
   public:
     static MEDFileFields *New() throw(INTERP_KERNEL::Exception);
     static MEDFileFields *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+    static MEDFileFields *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileFields *LoadPartOf(const std::string& fileName, bool loadAll=true, const MEDFileMeshes *ms=0) throw(INTERP_KERNEL::Exception);
     MEDFileFields *deepCopy() const throw(INTERP_KERNEL::Exception);
     MEDFileFields *shallowCpy() const throw(INTERP_KERNEL::Exception);
@@ -2899,6 +3029,17 @@ namespace MEDCoupling
          {
            return MEDFileFields::New(fileName,loadAll);
          }
+
+         MEDFileFields(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileFields::New(db);
+         }
+         
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileFields");
+         }
          
          std::string __str__() const throw(INTERP_KERNEL::Exception)
          {
@@ -3345,8 +3486,8 @@ namespace MEDCoupling
   public:
     static MEDFileParameters *New();
     static MEDFileParameters *New(const std::string& fileName) throw(INTERP_KERNEL::Exception);
+    static MEDFileParameters *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     MEDFileParameters *deepCopy() const throw(INTERP_KERNEL::Exception);
-    void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception);
     std::vector<std::string> getParamsNames() const throw(INTERP_KERNEL::Exception);
     std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
     void resize(int newSize) throw(INTERP_KERNEL::Exception);
@@ -3367,6 +3508,17 @@ namespace MEDCoupling
         return MEDFileParameters::New(fileName);
       }
 
+      MEDFileParameters(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+      {
+        return MEDFileParameters::New(db);
+      }
+
+      // serialization
+      static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+      {
+        return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileParameters");
+      }
+      
       std::string __str__() const throw(INTERP_KERNEL::Exception)
       {
         return self->simpleRepr();
@@ -3430,6 +3582,7 @@ namespace MEDCoupling
   class MEDFileData : public RefCountObject, public MEDFileWritableStandAlone
   {
   public:
+    static MEDFileData *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception);
     static MEDFileData *New(const std::string& fileName) throw(INTERP_KERNEL::Exception);
     static MEDFileData *New();
     MEDFileData *deepCopy() const throw(INTERP_KERNEL::Exception);
@@ -3450,6 +3603,11 @@ namespace MEDCoupling
            return MEDFileData::New(fileName);
          }
 
+         MEDFileData(DataArrayByte *db) throw(INTERP_KERNEL::Exception)
+         {
+           return MEDFileData::New(db);
+         }
+
          MEDFileData()
          {
            return MEDFileData::New();
@@ -3497,6 +3655,12 @@ namespace MEDCoupling
            MCAuto<MEDFileData> ret(MEDFileData::Aggregate(mfdsCpp));
            return ret.retn();
          }
+
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+         {
+           return NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(cls,args,"MEDFileData");
+         }
        }
   };