X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDSImpl%2FSALOMEDSImpl_Tool.cxx;h=a77876658c589c63644e4d3a3a28bcc0872abbc7;hb=c92c02d464cc393854d280971a4d5eb7e947e8c6;hp=7d817c96170ba116cf2c172ebbdb7d97aab27dee;hpb=f14439749926cca959747bb79fda10529520bd0b;p=modules%2Fkernel.git diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx index 7d817c961..a77876658 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx @@ -1,37 +1,39 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : SALOMEDSImpl_Tool.cxx // Created : Mon Oct 21 16:24:34 2002 // Author : Sergey RUIN - // Project : SALOME // Module : SALOMEDSImpl - -#include "SALOMEDSImpl_Tool.hxx" - +// #include #include #include +#include +#include +#include "SALOMEDSImpl_Tool.hxx" -#ifndef WNT +#ifndef WIN32 #include #include #include @@ -40,19 +42,19 @@ #else #include #include +//#include +#include #endif -#include - using namespace std; bool Exists(const string thePath) { -#ifdef WNT +#ifdef WIN32 if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { - if ( GetLastError () != ERROR_FILE_NOT_FOUND ) { + if ( GetLastError () == ERROR_FILE_NOT_FOUND ) { return false; } } @@ -118,7 +120,7 @@ string SALOMEDSImpl_Tool::GetTmpDir() #endif -#ifdef WNT +#ifdef WIN32 CreateDirectory(aDir.c_str(), NULL); #else mkdir(aDir.c_str(), 0x1ff); @@ -143,7 +145,7 @@ void SALOMEDSImpl_Tool::RemoveTemporaryFiles(const string& theDirectory, aFile += theFiles[i-1]; if(!Exists(aFile)) continue; -#ifdef WNT +#ifdef WIN32 DeleteFile(aFile.c_str()); #else unlink(aFile.c_str()); @@ -152,8 +154,8 @@ void SALOMEDSImpl_Tool::RemoveTemporaryFiles(const string& theDirectory, if(IsDirDeleted) { if(Exists(aDirName)) { -#ifdef WNT - RemoveDirectory(aDireName.c_str()); +#ifdef WIN32 + RemoveDirectory(aDirName.c_str()); #else rmdir(aDirName.c_str()); #endif @@ -182,31 +184,31 @@ string SALOMEDSImpl_Tool::GetNameFromPath(const string& thePath) { // purpose : Returns the dir by the path //============================================================================ string SALOMEDSImpl_Tool::GetDirFromPath(const string& thePath) { - if (thePath.empty()) return ""; +#ifdef WIN32 + string separator = "\\"; +#else + string separator = "/"; +#endif - int pos = thePath.rfind('/'); string path; - if(pos > 0) { - path = thePath.substr(0, pos+1); - } - if(path.empty()) { - pos = thePath.rfind('\\'); - if(pos > 0) path = thePath.substr(0, pos+1); - } - if(path.empty()) { - pos = thePath.rfind('|'); - if(pos > 0) path = thePath.substr(0, pos+1); - } - if(path.empty()) { - path = thePath+"/"; + if (!thePath.empty()) { + int pos = thePath.rfind('/'); + if (pos < 0) pos = thePath.rfind('\\'); + if (pos < 0) pos = thePath.rfind('|'); + + if (pos > 0) + path = thePath.substr(0, pos+1); + else + path = string(".") + separator; + +#ifdef WIN32 //Check if the only disk letter is given as path + if (path.size() == 2 && path[1] == ':') path += separator; +#endif + + while ( (pos=path.find('|')) >= 0 ) + path.replace(pos, 1, separator); } -#ifdef WNT //Check if the only disk letter is given as path - if(path.size() == 2 && path[1] == ":") path +='\\'; -#endif - - for(int i = 0, len = path.size(); i SALOMEDSImpl_Tool::splitString(const string& theValue, char separ return vs; } +//============================================================================ +// function : +// purpose : The functions returns a list of substring of initial string +// divided by given separator include empty strings +//============================================================================ +vector SALOMEDSImpl_Tool::splitStringWithEmpty(const string& theValue, char sep) +{ + vector aResult; + if(theValue[0] == sep ) aResult.push_back(string()); + int pos = theValue.find(sep); + if(pos < 0 ) { + aResult.push_back(theValue); + return aResult; + } + + string s = theValue; + if(s[0] == sep) s = s.substr(1, s.size()); + while((pos = s.find(sep)) >= 0) { + aResult.push_back(s.substr(0, pos)); + s = s.substr(pos+1, s.size()); + } + + if(!s.empty() && s[0] != sep) aResult.push_back(s); + if(theValue[theValue.size()-1] == sep) aResult.push_back(string()); + + return aResult; +} + +//============================================================================ +// function : +// purpose : The functions returns a list of lists of substrings of initial string +// divided by two given separators include empty strings +//============================================================================ +vector< vector > SALOMEDSImpl_Tool::splitStringWithEmpty(const string& theValue, char sep1, char sep2) +{ + vector< vector > aResult; + if(theValue.size() > 0) { + vector aSections = splitStringWithEmpty( theValue, sep1 ); + for( int i = 0, n = aSections.size(); i < n; i++ ) + aResult.push_back( splitStringWithEmpty( aSections[i], sep2 ) ); + } + return aResult; +} + void SALOMEDSImpl_Tool::GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds) { -#ifdef WNT +#ifdef WIN32 SYSTEMTIME st; GetLocalTime ( &st ); @@ -268,13 +314,17 @@ void SALOMEDSImpl_Tool::GetSystemDate(int& year, int& month, int& day, int& hour #endif } +//Warning undef of Ascii Winwows define +#ifdef WIN32 +# undef GetUserName +#endif string SALOMEDSImpl_Tool::GetUserName() { -#ifdef WNT +#ifdef WIN32 char* pBuff = new char[UNLEN + 1]; DWORD dwSize = UNLEN + 1; string retVal; - GetUserName ( pBuff, &dwSize ); + ::GetUserNameA( pBuff, &dwSize ); string theTmpUserName(pBuff,(int)dwSize -1 ); retVal = theTmpUserName; delete [] pBuff;