Salome HOME
[Intersect2D] Keep flexibility on orientation of mesh2
[tools/medcoupling.git] / src / MEDLoader / MEDLoaderBase.cxx
index dd69727dab25b17cc9474bbc304147e68cdbfb28..6ccae871b0449cbf2746237859894151de88b459 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,6 +16,7 @@
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// Author : Anthony Geay (CEA/DEN)
 
 #include "MEDLoaderBase.hxx"
 #include "InterpKernelException.hxx"
 
 const char MEDLoaderBase::WHITE_SPACES[]=" \n";
 
-int MEDLoaderBase::getStatusOfFile(const char *fileName)
+int MEDLoaderBase::getStatusOfFile(const std::string& fileName)
 {
   std::ifstream ifs;
-  ifs.open(fileName);
+  ifs.open(fileName.c_str());
   if((ifs.rdstate() & std::ifstream::failbit)!=0)
     {
       ifs.close();
       return NOT_EXIST;
     }
-  std::ofstream ofs(fileName,std::ios_base::app);
+  std::ofstream ofs(fileName.c_str(),std::ios_base::app);
   if((ofs.rdstate() & std::ofstream::failbit)!=0)
     {
       return EXIST_RDONLY;
@@ -44,7 +45,7 @@ int MEDLoaderBase::getStatusOfFile(const char *fileName)
   return EXIST_RW;
 }
 
-char *MEDLoaderBase::buildEmptyString(int lgth)
+char *MEDLoaderBase::buildEmptyString(std::size_t lgth)
 {
   char *ret=new char[lgth+1];
   std::fill(ret,ret+lgth,' ');
@@ -52,7 +53,7 @@ char *MEDLoaderBase::buildEmptyString(int lgth)
   return ret;
 }
 
-void MEDLoaderBase::getDirAndBaseName(const std::string& fullName, std::string& dirName, std::string& baseName) throw(INTERP_KERNEL::Exception)
+void MEDLoaderBase::getDirAndBaseName(const std::string& fullName, std::string& dirName, std::string& baseName)
 {
   std::size_t pos=fullName.find_last_of(getPathSep());
   if(pos!=std::string::npos)
@@ -67,7 +68,7 @@ void MEDLoaderBase::getDirAndBaseName(const std::string& fullName, std::string&
     }
 }
 
-std::string MEDLoaderBase::joinPath(const std::string& dirName, const std::string& baseName) throw(INTERP_KERNEL::Exception)
+std::string MEDLoaderBase::joinPath(const std::string& dirName, const std::string& baseName)
 {
   if(!dirName.empty())
     return dirName+getPathSep()+baseName;
@@ -75,7 +76,7 @@ std::string MEDLoaderBase::joinPath(const std::string& dirName, const std::strin
     return baseName;
 }
 
-std::string MEDLoaderBase::getPathSep() throw(INTERP_KERNEL::Exception)
+std::string MEDLoaderBase::getPathSep()
 {
 #ifndef WIN32
   return std::string("/");
@@ -88,7 +89,7 @@ std::string MEDLoaderBase::buildUnionUnit(const char *name, int nameLgth, const
 {
   std::string ret(buildStringFromFortran(name,nameLgth));
   std::string unitCpp(buildStringFromFortran(unit,unitLgth));
-  if(unitCpp[0]=='\0')
+  if(unitCpp.empty() || unitCpp[0]=='\0')
     return ret;
   ret+=" [";
   ret+=unitCpp;
@@ -129,11 +130,11 @@ void MEDLoaderBase::strip(std::string& s)
 
 /*!
  * This method operates a safe copy from 'src' to 'dest' by checking the size of 'src' before trying to copy.
- * If size of 'src' string is higher than 'maxLgth' the behaviour is dependant from 'behaviour' parameter.
+ * If size of 'src' string is higher than 'maxLgth' the behaviour is dependent from 'behaviour' parameter.
  * If 'behaviour' equals 0 an exception is thrown. If 'behaviour' equals 1 an attempt of zipping of string will be done
  * ( see zipString to have more details).
  */
-void MEDLoaderBase::safeStrCpy(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception)
+void MEDLoaderBase::safeStrCpy(const char *src, int maxLgth, char *dest, int behaviour)
 {
   if((int)strlen(src)>maxLgth)
     {
@@ -158,7 +159,7 @@ void MEDLoaderBase::safeStrCpy(const char *src, int maxLgth, char *dest, int beh
  * This method is equivalent to MEDLoaderBase::safeStrCpy except that here no '\0' car is put.
  * This method should be used for multi string in one string.
  */
-void MEDLoaderBase::safeStrCpy2(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception)
+void MEDLoaderBase::safeStrCpy2(const char *src, int maxLgth, char *dest, int behaviour)
 {
   if((int)strlen(src)>maxLgth)
     {
@@ -176,7 +177,8 @@ void MEDLoaderBase::safeStrCpy2(const char *src, int maxLgth, char *dest, int be
           return ;
         }
     }
-  int n=strlen(src);
+  std::size_t n(strlen(src));
+  std::fill(dest,dest+maxLgth,' ');
   strncpy(dest,src,n);
 }
 
@@ -198,7 +200,7 @@ std::string MEDLoaderBase::buildStringFromFortran(const char *expr, int lgth)
  * This method given the target size to respect 'sizeToRespect' tries to reduce size of 'src' string.
  * This method uses several soft methods to do its job. But if it fails a simple cut of string will be performed.
  */
-std::string MEDLoaderBase::zipString(const char *src, int sizeToRespect)
+std::string MEDLoaderBase::zipString(const std::string& src, int sizeToRespect)
 {
   std::string s(src);
   strip(s);