From: geay Date: Thu, 17 Apr 2014 11:09:30 +0000 (+0200) Subject: Addition off DynamicCast for DaVinci C++ style coders :-) X-Git-Tag: V7_4_0rc1~2^2~15^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d4a4da93bbf68b0daa576855867ff1da5fd9c12f;p=tools%2Fmedcoupling.git Addition off DynamicCast for DaVinci C++ style coders :-) --- diff --git a/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx b/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx index d80ca915c..7e097ff57 100644 --- a/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx +++ b/src/MEDCoupling/MEDCouplingAutoRefCountObjectPtr.hxx @@ -22,6 +22,7 @@ #define __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__ #include "MEDCouplingRefCountObject.hxx" +#include "InterpKernelException.hxx" namespace ParaMEDMEM { @@ -48,6 +49,30 @@ namespace ParaMEDMEM private: T *_ptr; }; + + template + typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr DynamicCast(typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr& autoSubPtr) throw() + { + T *subPtr(autoSubPtr); + U *ptr(dynamic_cast(subPtr)); + typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret(ptr); + if(ptr) + ptr->incrRef(); + return ret; + } + + template + typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr DynamicCastSafe(typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr& autoSubPtr) + { + T *subPtr(autoSubPtr); + U *ptr(dynamic_cast(subPtr)); + if(subPtr && !ptr) + throw INTERP_KERNEL::Exception("DynamicCastSafe : U is not a subtype of T !"); + typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret(ptr); + if(ptr) + ptr->incrRef(); + return ret; + } } #endif diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index cdc710e03..7d30a60a1 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -166,7 +166,7 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int med_bool changement,transformation; med_int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1; _m=MEDCoupling1DGTUMesh::New(mName,geoElt==MED_POLYGON?INTERP_KERNEL::NORM_POLYGON:INTERP_KERNEL::NORM_QPOLYG); - MEDCoupling1DGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); + MEDCouplingAutoRefCountObjectPtr mc(DynamicCast(_m)); MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()); conn->alloc(arraySize,1); connI->alloc(curNbOfElem+1,1); MEDmeshPolygon2Rd(fid,mName,dt,it,MED_CELL,geoElt,MED_NODAL,connI->getPointer(),conn->getPointer()); @@ -183,7 +183,7 @@ void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int med_int indexFaceLgth=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation); int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1; _m=MEDCoupling1DGTUMesh::New(mName,INTERP_KERNEL::NORM_POLYHED); - MEDCoupling1DGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); + MEDCouplingAutoRefCountObjectPtr mc(DynamicCastSafe(_m)); INTERP_KERNEL::AutoPtr index=new int[curNbOfElem+1]; INTERP_KERNEL::AutoPtr indexFace=new int[indexFaceLgth]; INTERP_KERNEL::AutoPtr locConn=new int[connFaceLgth];