Salome HOME
implementation of useful DataArray::SplitStringInChuncks for SMESH 2 MC layer
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 27 Apr 2021 09:56:14 +0000 (11:56 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 27 Apr 2021 09:56:14 +0000 (11:56 +0200)
src/INTERP_KERNEL/Bases/InterpKernelException.hxx
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDLoader/MEDMESHConverterUtilities.hxx
src/MEDLoader/SauvUtilities.hxx

index 472a6c7de3ba0c66d9f9263b60edf17cfdc0d75f..a73c6b9040c2fc8bb5a85d035062fd547f41e63b 100644 (file)
@@ -41,4 +41,10 @@ namespace INTERP_KERNEL
   };
 }
 
+#define THROW_IK_EXCEPTION(text)               \
+{                                              \
+    std::ostringstream oss; oss << text;       \
+    throw INTERP_KERNEL::Exception(oss.str()); \
+}
+
 #endif
index 9468ef0c0757e2496e096508ebae907a430ab112..da3cfcc9a3c28142d7138a20ba03c1c8152f1212 100755 (executable)
@@ -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<std::string> 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<std::string> 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".
index b5f121415d1cfd75b4cc37c4a8cd26523917c89c..74d08f0d908b9ed9fee81548f1fe8b53b3e190f3 100755 (executable)
@@ -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<std::string> 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);
index 50ed5baee118cb0ae0349ffbca403988696b1db2..c4881f82fdaace4750f7eeb063df7b1bce313329 100644 (file)
 # include <vector>
 #include <cstring>
 
-
-
-#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 );
index ed9e25c951a64c8d17ec09db7f949ba57306646a..0be627bf6e0ecc3aee3ee630d791b43279b8bcc7 100644 (file)
 #include <string>
 #include <sstream>
 
-#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 );