From 5184c0c5ab9d4c4ddac845465a9223db6b86ff72 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 2 Mar 2020 16:47:26 +0100 Subject: [PATCH] Preparation of work --- src/MEDCoupling/MCAuto.hxx | 6 ++-- src/ParaMEDMEM/ParaMESH.cxx | 61 +++++++------------------------------ src/ParaMEDMEM/ParaMESH.hxx | 31 +++++++++---------- 3 files changed, 27 insertions(+), 71 deletions(-) diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index ff32e25a1..1a0c4038f 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -18,8 +18,7 @@ // // Author : Anthony Geay (CEA/DEN) -#ifndef __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__ +#pragma once #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" @@ -50,6 +49,7 @@ namespace MEDCoupling operator T *() { return _ptr; } operator const T *() const { return _ptr; } T *retn() { if(_ptr) _ptr->incrRef(); return _ptr; } + T *retnConstCast() const { if(_ptr) _ptr->incrRef(); return _ptr; } T *iAmATrollConstCast() const { return _ptr; } private: void referPtr(T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } @@ -121,5 +121,3 @@ namespace MEDCoupling const T *_ptr; }; } - -#endif diff --git a/src/ParaMEDMEM/ParaMESH.cxx b/src/ParaMEDMEM/ParaMESH.cxx index 1fe4ddf9c..f0ed51e75 100644 --- a/src/ParaMEDMEM/ParaMESH.cxx +++ b/src/ParaMEDMEM/ParaMESH.cxx @@ -36,37 +36,22 @@ namespace MEDCoupling ParaMESH::ParaMESH( MEDCouplingPointSet *subdomain_mesh, MEDCouplingPointSet *subdomain_face, DataArrayIdType *CorrespElt_local2global, DataArrayIdType *CorrespFace_local2global, DataArrayIdType *CorrespNod_local2global, const ProcessorGroup& proc_group ): - _cell_mesh(subdomain_mesh), - _face_mesh(subdomain_face), _my_domain_id(proc_group.myRank()), - _block_topology (new BlockTopology(proc_group, subdomain_mesh->getNumberOfCells())), - _explicit_topology(0), - _node_global(CorrespNod_local2global), - _face_global(CorrespFace_local2global), - _cell_global(CorrespElt_local2global) + _block_topology(new BlockTopology(proc_group, subdomain_mesh->getNumberOfCells())), + _explicit_topology(nullptr) { - if(_cell_mesh) - _cell_mesh->incrRef(); - if(_face_mesh) - _face_mesh->incrRef(); - if(CorrespElt_local2global) - CorrespElt_local2global->incrRef(); - if(CorrespFace_local2global) - CorrespFace_local2global->incrRef(); - if(CorrespNod_local2global) - CorrespNod_local2global->incrRef(); + _cell_mesh.takeRef(subdomain_mesh); + _face_mesh.takeRef(subdomain_face); + _node_global.takeRef(CorrespNod_local2global); + _face_global.takeRef(CorrespFace_local2global); + _cell_global.takeRef(CorrespElt_local2global); } ParaMESH::ParaMESH( MEDCouplingPointSet *mesh, const ProcessorGroup& proc_group, const std::string& name): - _cell_mesh(mesh), - _face_mesh(0), _my_domain_id(proc_group.myRank()), - _block_topology (new BlockTopology(proc_group, mesh->getNumberOfCells())), - _node_global(0), - _face_global(0) + _block_topology(new BlockTopology(proc_group, mesh->getNumberOfCells())) { - if(_cell_mesh) - _cell_mesh->incrRef(); + _cell_mesh.takeRef(mesh); mcIdType nb_elem=mesh->getNumberOfCells(); _explicit_topology=new BlockTopology(proc_group,nb_elem); mcIdType nbOfCells=mesh->getNumberOfCells(); @@ -82,41 +67,17 @@ namespace MEDCoupling void ParaMESH::setNodeGlobal(DataArrayIdType *nodeGlobal) { - if(nodeGlobal!=_node_global) - { - if(_node_global) - _node_global->decrRef(); - _node_global=nodeGlobal; - if(_node_global) - _node_global->incrRef(); - } + _node_global.takeRef(nodeGlobal); } void ParaMESH::setCellGlobal(DataArrayIdType *cellGlobal) { - if(cellGlobal!=_cell_global) - { - if(_cell_global) - _cell_global->decrRef(); - _cell_global=cellGlobal; - if(_cell_global) - _cell_global->incrRef(); - } + _cell_global.takeRef(cellGlobal); } ParaMESH::~ParaMESH() { - if(_cell_mesh) - _cell_mesh->decrRef(); - if(_face_mesh) - _face_mesh->decrRef(); delete _block_topology; - if(_node_global) - _node_global->decrRef(); - if(_cell_global) - _cell_global->decrRef(); - if(_face_global) - _face_global->decrRef(); delete _explicit_topology; } diff --git a/src/ParaMEDMEM/ParaMESH.hxx b/src/ParaMEDMEM/ParaMESH.hxx index eee91dfe9..f642a95fd 100644 --- a/src/ParaMEDMEM/ParaMESH.hxx +++ b/src/ParaMEDMEM/ParaMESH.hxx @@ -17,8 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef __PARAMESH_HXX__ -#define __PARAMESH_HXX__ +#pragma once #include "MEDCouplingPointSet.hxx" #include "ProcessorGroup.hxx" @@ -61,21 +60,21 @@ namespace MEDCoupling void setCellGlobal(DataArrayIdType *cellGlobal); Topology* getTopology() const { return _explicit_topology; } bool isStructured() const { return _cell_mesh->isStructured(); } - MEDCouplingPointSet *getCellMesh() const { return _cell_mesh; } - MEDCouplingPointSet *getFaceMesh() const { return _face_mesh; } + MEDCouplingPointSet *getCellMesh() const { return _cell_mesh.iAmATrollConstCast(); } + MEDCouplingPointSet *getFaceMesh() const { return _face_mesh.iAmATrollConstCast(); } BlockTopology* getBlockTopology() const { return _block_topology; } - DataArrayIdType* getGlobalNumberingNodeDA() const { if(_node_global) _node_global->incrRef(); return _node_global; } - DataArrayIdType* getGlobalNumberingFaceDA() const { if(_face_global) _face_global->incrRef(); return _face_global; } - DataArrayIdType* getGlobalNumberingCellDA() const { if(_cell_global) _cell_global->incrRef(); return _cell_global; } - const mcIdType* getGlobalNumberingNode() const { if(_node_global) return _node_global->getConstPointer(); return 0; } - const mcIdType* getGlobalNumberingFace() const { if(_face_global) return _face_global->getConstPointer(); return 0; } - const mcIdType* getGlobalNumberingCell() const { if(_cell_global) return _cell_global->getConstPointer(); return 0; } + DataArrayIdType* getGlobalNumberingNodeDA() const { return _node_global.retnConstCast(); } + DataArrayIdType* getGlobalNumberingFaceDA() const { return _face_global.retnConstCast(); } + DataArrayIdType* getGlobalNumberingCellDA() const { return _cell_global.retnConstCast(); } + const mcIdType* getGlobalNumberingNode() const { if(_node_global) return _node_global->getConstPointer(); return nullptr; } + const mcIdType* getGlobalNumberingFace() const { if(_face_global) return _face_global->getConstPointer(); return nullptr; } + const mcIdType* getGlobalNumberingCell() const { if(_cell_global) return _cell_global->getConstPointer(); return nullptr; } private: //mesh object underlying the ParaMESH object - MEDCouplingPointSet *_cell_mesh ; - MEDCouplingPointSet *_face_mesh ; + MCAuto _cell_mesh ; + MCAuto _face_mesh ; //id of the local grid int _my_domain_id; @@ -84,10 +83,8 @@ namespace MEDCoupling MEDCoupling::BlockTopology* _block_topology; Topology* _explicit_topology; // pointers to global numberings - DataArrayIdType* _node_global; - DataArrayIdType* _face_global; - DataArrayIdType* _cell_global; + MCAuto _node_global; + MCAuto _face_global; + MCAuto _cell_global; }; } - -#endif -- 2.39.2