From: Anthony Geay Date: Tue, 27 Apr 2021 09:56:14 +0000 (+0200) Subject: implementation of useful DataArray::SplitStringInChuncks for SMESH 2 MC layer X-Git-Tag: V9_8_0a1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f34bf2d8cdd2f3da5b46988f59d39e2d897e9104;p=tools%2Fmedcoupling.git implementation of useful DataArray::SplitStringInChuncks for SMESH 2 MC layer --- diff --git a/src/INTERP_KERNEL/Bases/InterpKernelException.hxx b/src/INTERP_KERNEL/Bases/InterpKernelException.hxx index 472a6c7de..a73c6b904 100644 --- a/src/INTERP_KERNEL/Bases/InterpKernelException.hxx +++ b/src/INTERP_KERNEL/Bases/InterpKernelException.hxx @@ -41,4 +41,10 @@ namespace INTERP_KERNEL }; } +#define THROW_IK_EXCEPTION(text) \ +{ \ + std::ostringstream oss; oss << text; \ + throw INTERP_KERNEL::Exception(oss.str()); \ +} + #endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 9468ef0c0..da3cfcc9a 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -423,6 +423,29 @@ std::string DataArray::getUnitOnComponent(std::size_t i) const } } +/*! + * Split \a st string into chunks of sz characters each. + * Size of input \a st must a be a multiple of \a sz. If not an exception is thrown. + */ +std::vector DataArray::SplitStringInChuncks(const std::string st, std::size_t sz) +{ + std::size_t len = st.length(); + std::size_t nbOfCompo(len/sz); + if( nbOfCompo*sz != len) + { + THROW_IK_EXCEPTION("DataArray::SplitStringInChuncks : Length of input string (" << len << ") is not equal to " << nbOfCompo << "*" << sz << " !"); + } + std::vector ret(nbOfCompo); + for(std::size_t i = 0 ; i < nbOfCompo ; ++i) + { + std::string part = st.substr(i*sz,sz); + std::size_t p3=part.find_last_not_of(" \t"); + part = part.substr(0,p3+1); + ret[i] = part; + } + return ret; +} + /*! * Returns the var part of the full component information. * For example, if \a info == "SIGXY [N/m^2]", then this method returns "SIGXY". diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index b5f121415..74d08f0d9 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -197,6 +197,7 @@ namespace MEDCoupling static mcIdType GetNumberOfItemGivenBES(mcIdType begin, mcIdType end, mcIdType step, const std::string& msg); static mcIdType GetNumberOfItemGivenBESRelative(mcIdType begin, mcIdType end, mcIdType step, const std::string& msg); static mcIdType GetPosOfItemGivenBESRelativeNoThrow(mcIdType value, mcIdType begin, mcIdType end, mcIdType step); + static std::vector SplitStringInChuncks(const std::string st, std::size_t sz); static std::string GetVarNameFromInfo(const std::string& info); static std::string GetUnitFromInfo(const std::string& info); static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit); diff --git a/src/MEDLoader/MEDMESHConverterUtilities.hxx b/src/MEDLoader/MEDMESHConverterUtilities.hxx index 50ed5baee..c4881f82f 100644 --- a/src/MEDLoader/MEDMESHConverterUtilities.hxx +++ b/src/MEDLoader/MEDMESHConverterUtilities.hxx @@ -28,14 +28,6 @@ # include #include - - -#define THROW_IK_EXCEPTION(text) \ -{ \ - std::ostringstream oss; oss << text; \ - throw INTERP_KERNEL::Exception(oss.str().c_str()); \ -} - namespace MeshFormat { bool isMeshExtensionCorrect( const std::string& fileName ); diff --git a/src/MEDLoader/SauvUtilities.hxx b/src/MEDLoader/SauvUtilities.hxx index ed9e25c95..0be627bf6 100644 --- a/src/MEDLoader/SauvUtilities.hxx +++ b/src/MEDLoader/SauvUtilities.hxx @@ -30,12 +30,6 @@ #include #include -#define THROW_IK_EXCEPTION(text) \ - { \ - std::ostringstream oss; oss << text; \ - throw INTERP_KERNEL::Exception(oss.str().c_str()); \ - } - namespace SauvUtilities { INTERP_KERNEL::NormalizedCellType MEDLOADER_EXPORT gibi2medGeom( size_t gibiType );