From: Anthony Geay Date: Thu, 10 Nov 2016 15:54:21 +0000 (+0100) Subject: For med file version, no more use of static macro but use dynamic lib for users using... X-Git-Tag: V8_2_0b1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e06e68af6c867aac8709258fad1bf8f4e7567721;p=tools%2Fmedcoupling.git For med file version, no more use of static macro but use dynamic lib for users using different medfile version without compilation. --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index c8248fd11..61ee8bbc2 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -289,7 +289,21 @@ bool MEDCoupling::HasXDR() std::string MEDCoupling::MEDFileVersionStr() { - return std::string(MED_VERSION_STR); + const int SZ=20; + char buf[SZ]; + std::fill(buf,buf+SZ,'\0'); + const char START_EXPECTED[]="MED-"; + med_err ret(MEDlibraryStrVersion(buf)); + if(ret!=0) + throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !"); + std::string zeRet(buf); + std::size_t pos(zeRet.find(START_EXPECTED,0)); + if(pos!=0) + { + std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos); } std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName) @@ -317,9 +331,13 @@ std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName) void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release) { - major=MED_NUM_MAJEUR; - minor=MED_NUM_MINEUR; - release=MED_NUM_RELEASE; + med_int majj,minn,rell; + med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell)); + if(ret!=0) + throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !"); + major=majj; + minor=minn; + release=rell; } /*! diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 8950a3f78..b5d356128 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -299,7 +299,7 @@ using namespace MEDCoupling; namespace MEDCoupling { bool HasXDR(); - std::string MEDFileVersionStr(); + std::string MEDFileVersionStr() throw(INTERP_KERNEL::Exception); std::string MEDFileVersionOfFileStr(const std::string& fileName) throw(INTERP_KERNEL::Exception); void SetEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception); void SetCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception); @@ -353,7 +353,7 @@ namespace MEDCoupling %inline { - PyObject *MEDFileVersionSwig() + PyObject *MEDFileVersionSwig() throw(INTERP_KERNEL::Exception) { int major,minor,release; MEDCoupling::MEDFileVersion(major,minor,release); @@ -364,7 +364,7 @@ namespace MEDCoupling return ret; } - PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName) + PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > res=MEDCoupling::GetFieldIterations(type,fileName,meshName,fieldName); PyObject *ret=PyList_New(res.size());