]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Low level method to have access of arrays by type.
authorageay <ageay>
Thu, 25 Aug 2011 09:23:17 +0000 (09:23 +0000)
committerageay <ageay>
Thu, 25 Aug 2011 09:23:17 +0000 (09:23 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx

index 2933769e527b629ebdc1f85ca521654f3a09d007..9c62cd09cef129d7356fc68fa4f50a1704a8ee7e 100644 (file)
@@ -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())
index 2873a04c6d9bb396479a3ae0e31f0e1ae41b8d56..8603cfda0fcc4f19c10b0b56d93acb5202673026 100644 (file)
@@ -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: