Salome HOME
0022875: EDF 7690 MED: Creating joints with medpartitioner in the MEDCoupling API
[tools/medcoupling.git] / src / MEDLoader / MEDFileData.cxx
index 8a97c37548d3aebff4116e4b9bcddfd9dcc177c2..a979b38f503a22e2f763c2a1dddf60db46b5f6cc 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  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
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// Author : Anthony Geay (CEA/DEN)
 
 #include "MEDFileData.hxx"
 
 using namespace ParaMEDMEM;
 
-MEDFileData *MEDFileData::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+MEDFileData *MEDFileData::New(const std::string& fileName)
 {
   return new MEDFileData(fileName);
 }
@@ -31,33 +32,78 @@ MEDFileData *MEDFileData::New()
   return new MEDFileData;
 }
 
+MEDFileData *MEDFileData::deepCpy() const
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDFileFields> fields;
+  if((const MEDFileFields *)_fields)
+    fields=_fields->deepCpy();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> meshes;
+  if((const MEDFileMeshes *)_meshes)
+    meshes=_meshes->deepCpy();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileParameters> params;
+  if((const MEDFileParameters *)_params)
+    params=_params->deepCpy();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileJoints> joints;
+  MEDCouplingAutoRefCountObjectPtr<MEDFileData> ret=MEDFileData::New();
+  ret->_fields=fields; ret->_meshes=meshes; ret->_params=params;
+  return ret.retn();
+}
+
+std::size_t MEDFileData::getHeapMemorySizeWithoutChildren() const
+{
+  return 0;
+}
+
+std::vector<const BigMemoryObject *> MEDFileData::getDirectChildrenWithNull() const
+{
+  std::vector<const BigMemoryObject *> ret;
+  ret.push_back((const MEDFileFields *)_fields);
+  ret.push_back((const MEDFileMeshes *)_meshes);
+  ret.push_back((const MEDFileParameters *)_params);
+  return ret;
+
+}
+
+/** Return a borrowed reference (caller is not responsible for object destruction) */
 MEDFileFields *MEDFileData::getFields() const
 {
   return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
 }
 
+/** Return a borrowed reference (caller is not responsible for object destruction) */
 MEDFileMeshes *MEDFileData::getMeshes() const
 {
   return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
 }
 
-void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception)
+/** Return a borrowed reference (caller is not responsible for object destruction) */
+MEDFileParameters *MEDFileData::getParams() const
 {
-  if(!fields)
-    throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !");
-  fields->incrRef();
+  return const_cast<MEDFileParameters *>(static_cast<const MEDFileParameters *>(_params));
+}
+
+void MEDFileData::setFields(MEDFileFields *fields)
+{
+  if(fields)
+    fields->incrRef();
   _fields=fields;
 }
 
-void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception)
+void MEDFileData::setMeshes(MEDFileMeshes *meshes)
 {
-  if(!meshes)
-    throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !");
-  meshes->incrRef();
+  if(meshes)
+    meshes->incrRef();
   _meshes=meshes;
 }
 
-int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception)
+void MEDFileData::setParams(MEDFileParameters *params)
+{
+  if(params)
+    params->incrRef();
+  _params=params;
+}
+
+int MEDFileData::getNumberOfFields() const
 {
   const MEDFileFields *f=_fields;
   if(!f)
@@ -65,7 +111,7 @@ int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception)
   return f->getNumberOfFields();
 }
 
-int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
+int MEDFileData::getNumberOfMeshes() const
 {
   const MEDFileMeshes *m=_meshes;
   if(!m)
@@ -73,6 +119,14 @@ int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
   return m->getNumberOfMeshes();
 }
 
+int MEDFileData::getNumberOfParams() const
+{
+  const MEDFileParameters *p=_params;
+  if(!p)
+    throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfParams : no params set !");
+  return p->getNumberOfParams();
+}
+
 std::string MEDFileData::simpleRepr() const
 {
   std::ostringstream oss;
@@ -92,11 +146,19 @@ std::string MEDFileData::simpleRepr() const
       tmp2->simpleReprWithoutHeader(oss);
     }
   else
-    oss << "No meshes set !!!\n";
+    oss << "No meshes set !!!\n\n";
+  oss << "Params part :\n*************\n\n";
+  const MEDFileParameters *tmp3=_params;
+  if(tmp3)
+    {
+      tmp3->simpleReprWithoutHeader(oss);
+    }
+  else
+    oss << "No params set !!!\n";
   return oss.str();
 }
 
-bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
+bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
 {
   bool ret=false;
   MEDFileFields *fields=_fields;
@@ -108,7 +170,7 @@ bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::
   return ret;
 }
 
-bool MEDFileData::changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception)
+bool MEDFileData::changeMeshName(const std::string& oldMeshName, const std::string& newMeshName)
 {
   std::string oldName(oldMeshName);
   std::vector< std::pair<std::string,std::string> > v(1);
@@ -123,12 +185,11 @@ bool MEDFileData::changeMeshName(const char *oldMeshName, const char *newMeshNam
  * \return If true is returned it means that some meshes in \a this has been modified and eventually fields have been renumbered.
  *         \n If false \a this remains unchanged.
  */
-bool MEDFileData::unPolyzeMeshes() throw(INTERP_KERNEL::Exception)
+bool MEDFileData::unPolyzeMeshes()
 {
   MEDFileMeshes *ms=_meshes;
   if(!ms)
     return false;
-  bool ret=false;
   std::vector< MEDFileMesh * > meshesImpacted;
   std::vector< DataArrayInt * > renumParamsOfMeshImpacted;//same size as meshesImpacted
   std::vector< std::vector<int> > oldCodeOfMeshImpacted,newCodeOfMeshImpacted;//same size as meshesImpacted
@@ -163,25 +224,29 @@ MEDFileData::MEDFileData()
 {
 }
 
-MEDFileData::MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception)
+MEDFileData::MEDFileData(const std::string& fileName)
 try
-  {
+{
     _fields=MEDFileFields::New(fileName);
     _meshes=MEDFileMeshes::New(fileName);
-  }
+    _params=MEDFileParameters::New(fileName);
+}
 catch(INTERP_KERNEL::Exception& e)
-  {
+{
     throw e;
-  }
+}
 
-void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+void MEDFileData::write(const std::string& fileName, int mode) const
 {
   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
-  MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
+  MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
   const MEDFileMeshes *ms=_meshes;
   if(ms)
     ms->write(fid);
   const MEDFileFields *fs=_fields;
   if(fs)
     fs->writeLL(fid);
+  const MEDFileParameters *ps=_params;
+  if(ps)
+    ps->writeLL(fid);
 }