From acd9d926e977721550e68f2df27c3621a74d562e Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 25 Aug 2011 09:23:17 +0000 Subject: [PATCH] Low level method to have access of arrays by type. --- src/MEDCoupling/MEDCouplingMemArray.cxx | 46 +++++++++++++++---------- src/MEDCoupling/MEDCouplingMemArray.hxx | 2 ++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 2933769e5..9c62cd09c 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -131,17 +131,7 @@ std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Excep { if(i<(int)_info_on_compo.size()) { - std::string st0=_info_on_compo[i]; - std::size_t p1=st0.find_last_of('['); - std::size_t p2=st0.find_last_of(']'); - if(p1==std::string::npos || p2==std::string::npos) - return st0; - if(p1>p2) - return st0; - if(p1==0) - return std::string(); - std::size_t p3=st0.find_last_not_of(' ',p1-1); - return st0.substr(0,p3+1); + return GetVarNameFromInfo(_info_on_compo[i]); } else { @@ -158,14 +148,7 @@ std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exce { if(i<(int)_info_on_compo.size()) { - std::string st0=_info_on_compo[i]; - std::size_t p1=st0.find_last_of('['); - std::size_t p2=st0.find_last_of(']'); - if(p1==std::string::npos || p2==std::string::npos) - return std::string(); - if(p1>p2) - return std::string(); - return st0.substr(p1+1,p2-p1-1); + return GetUnitFromInfo(_info_on_compo[i]); } else { @@ -174,6 +157,31 @@ std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exce } } +std::string DataArray::GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception) +{ + std::size_t p1=info.find_last_of('['); + std::size_t p2=info.find_last_of(']'); + if(p1==std::string::npos || p2==std::string::npos) + return info; + if(p1>p2) + return info; + if(p1==0) + return std::string(); + std::size_t p3=info.find_last_not_of(' ',p1-1); + return info.substr(0,p3+1); +} + +std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception) +{ + std::size_t p1=info.find_last_of('['); + std::size_t p2=info.find_last_of(']'); + if(p1==std::string::npos || p2==std::string::npos) + return std::string(); + if(p1>p2) + return std::string(); + return info.substr(p1+1,p2-p1-1); +} + void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception) { if(i<(int)_info_on_compo.size()) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 2873a04c6..8603cfda0 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -108,6 +108,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static int GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); protected: DataArray():_nb_of_tuples(-1) { } protected: -- 2.39.2