From: ageay Date: Fri, 4 Jan 2013 13:21:45 +0000 (+0000) Subject: MEDFileMesh::deepCpy and shallowCpy X-Git-Tag: V6_main_FINAL~430 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0da9276022fa07b5832eefea5c35bae0ea1a0e81;p=tools%2Fmedcoupling.git MEDFileMesh::deepCpy and shallowCpy --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index fc0461d03..3ecacfe39 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1342,6 +1342,32 @@ MEDFileUMesh *MEDFileUMesh::New() return new MEDFileUMesh; } +MEDFileMesh *MEDFileUMesh::shallowCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMesh(*this); + return ret.retn(); +} + +MEDFileMesh *MEDFileUMesh::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMesh(*this); + if((const DataArrayDouble*)_coords) + ret->_coords=_coords->deepCpy(); + if((const DataArrayInt*)_fam_coords) + ret->_fam_coords=_fam_coords->deepCpy(); + if((const DataArrayInt*)_num_coords) + ret->_num_coords=_num_coords->deepCpy(); + if((const DataArrayInt*)_rev_num_coords) + ret->_rev_num_coords=_rev_num_coords->deepCpy(); + std::size_t i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++) + { + if((const MEDFileUMeshSplitL1 *)(*it)) + ret->_ms[i]=(*it)->deepCpy(); + } + return ret.retn(); +} + bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const { if(!MEDFileMesh::isEqual(other,eps,what)) @@ -1424,7 +1450,6 @@ bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& wh return false; } } - //std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; return true; } @@ -2446,6 +2471,32 @@ std::string MEDFileCMesh::advancedRepr() const return simpleRepr(); } +MEDFileMesh *MEDFileCMesh::shallowCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + return ret.retn(); +} + +MEDFileMesh *MEDFileCMesh::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + if((const MEDCouplingCMesh*)_cmesh) + ret->_cmesh=static_cast(_cmesh->deepCpy()); + if((const DataArrayInt*)_fam_nodes) + ret->_fam_nodes=_fam_nodes->deepCpy(); + if((const DataArrayInt*)_num_nodes) + ret->_num_nodes=_num_nodes->deepCpy(); + if((const DataArrayInt*)_fam_cells) + ret->_fam_cells=_fam_cells->deepCpy(); + if((const DataArrayInt*)_num_cells) + ret->_num_cells=_num_cells->deepCpy(); + if((const DataArrayInt*)_rev_num_nodes) + ret->_rev_num_nodes=_rev_num_nodes->deepCpy(); + if((const DataArrayInt*)_rev_num_cells) + ret->_rev_num_cells=_rev_num_cells->deepCpy(); + return ret.retn(); +} + bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const { if(!MEDFileMesh::isEqual(other,eps,what)) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 02df40ac6..c4133be4f 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -34,6 +34,8 @@ namespace ParaMEDMEM public: static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + virtual MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception) = 0; + virtual MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception) = 0; virtual bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; virtual void clearNonDiscrAttributes() const; void setName(const char *name) { _name=name; } @@ -156,6 +158,8 @@ namespace ParaMEDMEM static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileUMesh *New(); + MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception); + MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; void clearNonDiscrAttributes() const; ~MEDFileUMesh(); @@ -235,6 +239,8 @@ namespace ParaMEDMEM static MEDFileCMesh *New(); static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception); + MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; int getMeshDimension() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 3774a0516..66e18f5c1 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -378,27 +378,20 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const if((MEDCouplingUMesh *)_m==0) { updateTime(); - MEDCouplingUMesh *ret=(MEDCouplingUMesh *)_st->_m_by_types->deepCpy(); - _m=ret; + _m=static_cast(_st->_m_by_types->deepCpy()); _m->renumberCells(_st->_num->getConstPointer(),true); - ret->incrRef(); - return ret; + return _m.retn(); } else { if(_mpt_time==_st->_m_by_types->getTimeOfThis() && _num_time==_st->_num->getTimeOfThis()) - { - _m->incrRef(); - return _m; - } + return _m.retn(); else { updateTime(); - MEDCouplingUMesh *ret=(MEDCouplingUMesh *)_st->_m_by_types->deepCpy(); - _m=ret; + _m=static_cast(_st->_m_by_types->deepCpy()); _m->renumberCells(_st->_num->getConstPointer(),true); - ret->incrRef(); - return ret; + return _m.retn(); } } } @@ -414,6 +407,10 @@ void MEDFileUMeshPermCompute::updateTime() const _num_time=_st->_num->getTimeOfThis(); } +MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):_m_by_types(other._m_by_types),_fam(other._fam),_num(other._num),_rev_num(other._rev_num),_m(this) +{ +} + MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id):_m(this) { const std::vector< MEDCouplingAutoRefCountObjectPtr >& v=l2.getLev(id); @@ -463,6 +460,20 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m( assignMesh(m,newOrOld); } +MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy() const +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMeshSplitL1(*this); + if((const MEDCouplingUMesh*)_m_by_types) + ret->_m_by_types=static_cast(_m_by_types->deepCpy()); + if((const DataArrayInt *)_fam) + ret->_fam=_fam->deepCpy(); + if((const DataArrayInt *)_num) + ret->_num=_num->deepCpy(); + if((const DataArrayInt *)_rev_num) + ret->_rev_num=_rev_num->deepCpy(); + return ret.retn(); +} + bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const { const MEDCouplingUMesh *m1=_m_by_types; diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 263f77d41..19dddd9bd 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -116,9 +116,11 @@ namespace ParaMEDMEM { friend class MEDFileUMeshPermCompute; public: + MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other); MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id); MEDFileUMeshSplitL1(MEDCouplingUMesh *m); MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld); + MEDFileUMeshSplitL1 *deepCpy() const; bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const; void clearNonDiscrAttributes() const; void synchronizeTinyInfo(const MEDFileMesh& master) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 8dab91281..51cc4c8fc 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -55,6 +55,8 @@ using namespace ParaMEDMEM; %newobject MEDLoader::ReadFieldGauss; %newobject MEDLoader::ReadFieldGaussNE; %newobject ParaMEDMEM::MEDFileMesh::New; +%newobject ParaMEDMEM::MEDFileMesh::deepCpy; +%newobject ParaMEDMEM::MEDFileMesh::shallowCpy; %newobject ParaMEDMEM::MEDFileMesh::getGenMeshAtLevel; %newobject ParaMEDMEM::MEDFileMesh::getGroupArr; %newobject ParaMEDMEM::MEDFileMesh::getGroupsArr; @@ -329,6 +331,8 @@ namespace ParaMEDMEM public: static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1); + virtual MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception); virtual void clearNonDiscrAttributes() const; void setName(const char *name); const char *getName(); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index aee3876cb..079d95077 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -164,7 +164,9 @@ class MEDLoaderTest(unittest.TestCase): t=mm.getGroupArr(0,"GrpOnAllCell") self.assertTrue(t.getValues()==range(5)) # - mm.write(outFileName,2); + mmCpy=mm.deepCpy() + self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm + mmCpy.write(outFileName,2); # mm=MEDFileMesh.New(outFileName) mbis=mm.getMeshAtLevel(0)