From: abn Date: Thu, 3 Feb 2022 12:28:42 +0000 (+0100) Subject: Static members of CellModel and Units fix. X-Git-Tag: V9_9_0a1^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fd60001c56b50dfb9c243f74912bac8afc2dfd76;p=tools%2Fmedcoupling.git Static members of CellModel and Units fix. + static items moved into dedicated methods with local static variables + avoid strange crashes in complex code couplings on some compilers. --- diff --git a/src/INTERP_KERNEL/CellModel.cxx b/src/INTERP_KERNEL/CellModel.cxx index 96b97b2f5..60029b273 100644 --- a/src/INTERP_KERNEL/CellModel.cxx +++ b/src/INTERP_KERNEL/CellModel.cxx @@ -43,14 +43,11 @@ namespace INTERP_KERNEL "", "", "", "", "",//35->39 "NORM_ERROR"}; - std::map CellModel::_map_of_unique_instance; - const CellModel& CellModel::GetCellModel(NormalizedCellType type) { - if(_map_of_unique_instance.empty()) - buildUniqueInstance(); - const std::map::iterator iter=_map_of_unique_instance.find(type); - if(iter==_map_of_unique_instance.end()) + const std::map& map_unique = GetMapOfUniqueInstance(); + const std::map::const_iterator iter=map_unique.find(type); + if(iter==map_unique.end()) { std::ostringstream stream; stream << "no cellmodel for normalized type " << type; throw Exception(stream.str().c_str()); @@ -58,6 +55,14 @@ namespace INTERP_KERNEL return (*iter).second; } + const std::map& CellModel::GetMapOfUniqueInstance() + { + static std::map map_of_unique_instance; + if(map_of_unique_instance.empty()) + BuildUniqueInstance(map_of_unique_instance); + return map_of_unique_instance; + } + const char *CellModel::getRepr() const { return CELL_TYPES_REPR[(int)_type]; @@ -82,34 +87,34 @@ namespace INTERP_KERNEL return b1 || b2; } - void CellModel::buildUniqueInstance() + void CellModel::BuildUniqueInstance(std::map& map_unique) { - _map_of_unique_instance.insert(std::make_pair(NORM_POINT1,CellModel(NORM_POINT1))); - _map_of_unique_instance.insert(std::make_pair(NORM_SEG2,CellModel(NORM_SEG2))); - _map_of_unique_instance.insert(std::make_pair(NORM_SEG3,CellModel(NORM_SEG3))); - _map_of_unique_instance.insert(std::make_pair(NORM_SEG4,CellModel(NORM_SEG4))); - _map_of_unique_instance.insert(std::make_pair(NORM_TRI3,CellModel(NORM_TRI3))); - _map_of_unique_instance.insert(std::make_pair(NORM_QUAD4,CellModel(NORM_QUAD4))); - _map_of_unique_instance.insert(std::make_pair(NORM_TRI6,CellModel(NORM_TRI6))); - _map_of_unique_instance.insert(std::make_pair(NORM_TRI7,CellModel(NORM_TRI7))); - _map_of_unique_instance.insert(std::make_pair(NORM_QUAD8,CellModel(NORM_QUAD8))); - _map_of_unique_instance.insert(std::make_pair(NORM_QUAD9,CellModel(NORM_QUAD9))); - _map_of_unique_instance.insert(std::make_pair(NORM_TETRA4,CellModel(NORM_TETRA4))); - _map_of_unique_instance.insert(std::make_pair(NORM_HEXA8,CellModel(NORM_HEXA8))); - _map_of_unique_instance.insert(std::make_pair(NORM_PYRA5,CellModel(NORM_PYRA5))); - _map_of_unique_instance.insert(std::make_pair(NORM_PENTA6,CellModel(NORM_PENTA6))); - _map_of_unique_instance.insert(std::make_pair(NORM_TETRA10,CellModel(NORM_TETRA10))); - _map_of_unique_instance.insert(std::make_pair(NORM_HEXGP12,CellModel(NORM_HEXGP12))); - _map_of_unique_instance.insert(std::make_pair(NORM_PYRA13,CellModel(NORM_PYRA13))); - _map_of_unique_instance.insert(std::make_pair(NORM_PENTA15,CellModel(NORM_PENTA15))); - _map_of_unique_instance.insert(std::make_pair(NORM_PENTA18,CellModel(NORM_PENTA18))); - _map_of_unique_instance.insert(std::make_pair(NORM_HEXA20,CellModel(NORM_HEXA20))); - _map_of_unique_instance.insert(std::make_pair(NORM_HEXA27,CellModel(NORM_HEXA27))); - _map_of_unique_instance.insert(std::make_pair(NORM_POLYGON,CellModel(NORM_POLYGON))); - _map_of_unique_instance.insert(std::make_pair(NORM_POLYHED,CellModel(NORM_POLYHED))); - _map_of_unique_instance.insert(std::make_pair(NORM_QPOLYG,CellModel(NORM_QPOLYG))); - _map_of_unique_instance.insert(std::make_pair(NORM_POLYL,CellModel(NORM_POLYL))); - _map_of_unique_instance.insert(std::make_pair(NORM_ERROR,CellModel(NORM_ERROR))); + map_unique.insert(std::make_pair(NORM_POINT1,CellModel(NORM_POINT1))); + map_unique.insert(std::make_pair(NORM_SEG2,CellModel(NORM_SEG2))); + map_unique.insert(std::make_pair(NORM_SEG3,CellModel(NORM_SEG3))); + map_unique.insert(std::make_pair(NORM_SEG4,CellModel(NORM_SEG4))); + map_unique.insert(std::make_pair(NORM_TRI3,CellModel(NORM_TRI3))); + map_unique.insert(std::make_pair(NORM_QUAD4,CellModel(NORM_QUAD4))); + map_unique.insert(std::make_pair(NORM_TRI6,CellModel(NORM_TRI6))); + map_unique.insert(std::make_pair(NORM_TRI7,CellModel(NORM_TRI7))); + map_unique.insert(std::make_pair(NORM_QUAD8,CellModel(NORM_QUAD8))); + map_unique.insert(std::make_pair(NORM_QUAD9,CellModel(NORM_QUAD9))); + map_unique.insert(std::make_pair(NORM_TETRA4,CellModel(NORM_TETRA4))); + map_unique.insert(std::make_pair(NORM_HEXA8,CellModel(NORM_HEXA8))); + map_unique.insert(std::make_pair(NORM_PYRA5,CellModel(NORM_PYRA5))); + map_unique.insert(std::make_pair(NORM_PENTA6,CellModel(NORM_PENTA6))); + map_unique.insert(std::make_pair(NORM_TETRA10,CellModel(NORM_TETRA10))); + map_unique.insert(std::make_pair(NORM_HEXGP12,CellModel(NORM_HEXGP12))); + map_unique.insert(std::make_pair(NORM_PYRA13,CellModel(NORM_PYRA13))); + map_unique.insert(std::make_pair(NORM_PENTA15,CellModel(NORM_PENTA15))); + map_unique.insert(std::make_pair(NORM_PENTA18,CellModel(NORM_PENTA18))); + map_unique.insert(std::make_pair(NORM_HEXA20,CellModel(NORM_HEXA20))); + map_unique.insert(std::make_pair(NORM_HEXA27,CellModel(NORM_HEXA27))); + map_unique.insert(std::make_pair(NORM_POLYGON,CellModel(NORM_POLYGON))); + map_unique.insert(std::make_pair(NORM_POLYHED,CellModel(NORM_POLYHED))); + map_unique.insert(std::make_pair(NORM_QPOLYG,CellModel(NORM_QPOLYG))); + map_unique.insert(std::make_pair(NORM_POLYL,CellModel(NORM_POLYL))); + map_unique.insert(std::make_pair(NORM_ERROR,CellModel(NORM_ERROR))); } CellModel::CellModel(NormalizedCellType type):_type(type) @@ -413,7 +418,7 @@ namespace INTERP_KERNEL _sons_type[0]=NORM_QUAD9; _sons_type[1]=NORM_QUAD9; _sons_type[2]=NORM_QUAD9; _sons_type[3]=NORM_QUAD9; _sons_type[4]=NORM_QUAD9; _sons_type[5]=NORM_QUAD9; _sons_con[0][0]=0; _sons_con[0][1]=1; _sons_con[0][2]=2; _sons_con[0][3]=3; _sons_con[0][4]=8; _sons_con[0][5]=9; _sons_con[0][6]=10; _sons_con[0][7]=11; _sons_con[0][8]=20; _nb_of_sons_con[0]=9; _sons_con[1][0]=4; _sons_con[1][1]=7; _sons_con[1][2]=6; _sons_con[1][3]=5; _sons_con[1][4]=15; _sons_con[1][5]=14; _sons_con[1][6]=13; _sons_con[1][7]=12; _sons_con[1][8]=25; _nb_of_sons_con[1]=9; - _sons_con[2][0]=0; _sons_con[2][1]=4; _sons_con[2][2]=5; _sons_con[2][3]=1; _sons_con[2][4]=16; _sons_con[2][5]=12; _sons_con[2][6]=17; _sons_con[2][7]=8; _sons_con[2][8]=21; _nb_of_sons_con[2]=9; + _sons_con[2][0]=0; _sons_con[2][1]=4; _sons_con[2][2]=5; _sons_con[2][3]=1; _sons_con[2][4]=16; _sons_con[2][5]=12; _sons_con[2][6]=17; _sons_con[2][7]=8; _sons_con[2][8]=21; _nb_of_sons_con[2]=9; _sons_con[3][0]=1; _sons_con[3][1]=5; _sons_con[3][2]=6; _sons_con[3][3]=2; _sons_con[3][4]=17; _sons_con[3][5]=13; _sons_con[3][6]=18; _sons_con[3][7]=9; _sons_con[3][8]=22; _nb_of_sons_con[3]=9; _sons_con[4][0]=2; _sons_con[4][1]=6; _sons_con[4][2]=7; _sons_con[4][3]=3; _sons_con[4][4]=18; _sons_con[4][5]=14; _sons_con[4][6]=19; _sons_con[4][7]=10; _sons_con[4][8]=23; _nb_of_sons_con[4]=9; _sons_con[5][0]=3; _sons_con[5][1]=7; _sons_con[5][2]=4; _sons_con[5][3]=0; _sons_con[5][4]=19; _sons_con[5][5]=15; _sons_con[5][6]=16; _sons_con[5][7]=11; _sons_con[5][8]=24; _nb_of_sons_con[5]=9; @@ -475,7 +480,7 @@ namespace INTERP_KERNEL else//polyhedron return FromIdType(lgth-ToIdType(std::count(conn,conn+lgth,-1)/2)); } - + /*! * \sa fillMicroEdgeNodalConnectivity */ @@ -497,7 +502,7 @@ namespace INTERP_KERNEL else throw INTERP_KERNEL::Exception("CellModel::getNumberOfMacroEdges : not supported by dynamic type !"); } - + NormalizedCellType CellModel::getCorrespondingPolyType() const { switch(getDimension()) @@ -599,7 +604,7 @@ namespace INTERP_KERNEL throw INTERP_KERNEL::Exception("CellModel::fillSonCellNodalConnectivity2 : no sons on NORM_POLYL !"); } } - + /*! * Equivalent to CellModel::fillSonCellNodalConnectivity2 except for HEXA8 where the order of sub faces is not has MED file numbering for transformation HEXA8->HEXA27 */ @@ -635,7 +640,7 @@ namespace INTERP_KERNEL } } else - throw INTERP_KERNEL::Exception("CellModel::fillSonEdgesNodalConnectivity3D : not implemented yet for NORM_POLYHED !"); + throw INTERP_KERNEL::Exception("CellModel::fillSonEdgesNodalConnectivity3D : not implemented yet for NORM_POLYHED !"); } /*! @@ -826,7 +831,7 @@ namespace INTERP_KERNEL } } } - + DiameterCalculator *CellModel::buildInstanceOfDiameterCalulator(int spaceDim) const { switch(_type) diff --git a/src/INTERP_KERNEL/CellModel.hxx b/src/INTERP_KERNEL/CellModel.hxx index 5881426ae..786f5e664 100644 --- a/src/INTERP_KERNEL/CellModel.hxx +++ b/src/INTERP_KERNEL/CellModel.hxx @@ -38,7 +38,7 @@ namespace INTERP_KERNEL { class DiameterCalculator; class OrientationInverter; - + /*! * This class describes all static elements (different from polygons and polyhedron) 3D, 2D and 1D. */ @@ -50,9 +50,10 @@ namespace INTERP_KERNEL static const unsigned MAX_NB_OF_LITTLE_SONS=12; private: CellModel(NormalizedCellType type); - static void buildUniqueInstance(); + static void BuildUniqueInstance(std::map& map); public: INTERPKERNEL_EXPORT static const CellModel& GetCellModel(NormalizedCellType type); + INTERPKERNEL_EXPORT static const std::map& GetMapOfUniqueInstance(); INTERPKERNEL_EXPORT NormalizedCellType getEnum() const { return _type; } INTERPKERNEL_EXPORT const char *getRepr() const; INTERPKERNEL_EXPORT bool isExtruded() const { return _is_extruded; } @@ -108,7 +109,6 @@ namespace INTERP_KERNEL unsigned _little_sons_con[MAX_NB_OF_LITTLE_SONS][3]; unsigned _nb_of_sons_con[MAX_NB_OF_SONS]; NormalizedCellType _sons_type[MAX_NB_OF_SONS]; - static std::map _map_of_unique_instance; static const char *CELL_TYPES_REPR[]; }; } diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx index 785461f44..f27062347 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx @@ -29,7 +29,11 @@ using namespace INTERP_KERNEL; -UnitDataBase UnitDataBase::_uniqueMapForExpr; +const UnitDataBase& UnitDataBase::GetUniqueMapForExpr() +{ + static UnitDataBase db; + return db; +} static const char InterpKernelMuAscii[2]={-0x4B,0x0}; diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.hxx b/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.hxx index e75ed09a9..40c1466a5 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.hxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.hxx @@ -34,7 +34,7 @@ namespace INTERP_KERNEL public: INTERPKERNEL_EXPORT UnitDataBase(); INTERPKERNEL_EXPORT const short *getInfoForUnit(const std::string& unit, double& addFact, double& mFact) const; - INTERPKERNEL_EXPORT static UnitDataBase _uniqueMapForExpr; + INTERPKERNEL_EXPORT static const UnitDataBase& GetUniqueMapForExpr(); INTERPKERNEL_EXPORT static const int SIZE_OF_UNIT_BASE=5; private: std::map _prefix_pow_10; diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx index eb29f17bc..e7d264a60 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx @@ -226,7 +226,7 @@ void ValueUnit::setDouble(double val) void ValueUnit::setVarname(int fastPos, const std::string& var) { double add,mul; - const short *projInBase=UnitDataBase::_uniqueMapForExpr.getInfoForUnit(var,add,mul); + const short *projInBase=UnitDataBase::GetUniqueMapForExpr().getInfoForUnit(var,add,mul); _data.setInfo(projInBase,add,mul); } @@ -567,7 +567,7 @@ Value *ValueDoubleExpr::pow(const Value *other) const if(it!=_dest_data+_sz_dest_data) throw INTERP_KERNEL::Exception("Trying to operate pow(a,b) with a<0. !"); ValueDoubleExpr *ret=new ValueDoubleExpr(_sz_dest_data,_src_data); - std::transform(_dest_data,_dest_data+_sz_dest_data,ret->getData(),std::bind([](double x, double y){return std::pow(x,y);},std::placeholders::_1,p)); + std::transform(_dest_data,_dest_data+_sz_dest_data,ret->getData(),std::bind([](double x, double y){return std::pow(x,y);},std::placeholders::_1,p)); return ret; }