X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FTOOLSDS%2FSALOMEDS_Tool.cxx;h=6c09e96b4aa6f41826505460c5867d72b3284cf1;hb=ed19d8bc0100ac6f91024fe88d22e3cbc0b2cc18;hp=6cbb46ca99c8f5e2eb661310e89b314f6865bddb;hpb=7d2fe213bdf5bf962ce11e253020c9d3e0bc1cce;p=modules%2Fkernel.git diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index 6cbb46ca9..6c09e96b4 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 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 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, 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 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// 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 +// 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_Tool.cxx // Created : Mon Oct 21 16:24:34 2002 // Author : Sergey RUIN @@ -43,14 +44,11 @@ #include #include -#include #include #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) -using namespace std; - -bool Exists(const string thePath) +bool Exists(const std::string thePath) { #ifdef WIN32 if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { @@ -133,14 +131,14 @@ std::string SALOMEDS_Tool::GetTmpDir() // purpose : Removes files listed in theFileList //============================================================================ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory, - const SALOMEDS::ListOfFileNames& theFiles, - const bool IsDirDeleted) + const ListOfFiles& theFiles, + const bool IsDirDeleted) { - string aDirName = theDirectory; + std::string aDirName = theDirectory; - int i, aLength = theFiles.length(); + int i, aLength = theFiles.size(); for(i=1; i<=aLength; i++) { - string aFile(aDirName); + std::string aFile(aDirName); aFile += theFiles[i-1]; if(!Exists(aFile)) continue; @@ -171,16 +169,16 @@ namespace { SALOMEDS::TMPFile* PutFilesToStream(const std::string& theFromDirectory, - const SALOMEDS::ListOfFileNames& theFiles, - const SALOMEDS::ListOfFileNames& theFileNames, - const int theNamesOnly) + const std::vector& theFiles, + const std::vector& theFileNames, + const int theNamesOnly) { - int i, aLength = theFiles.length(); + int i, aLength = theFiles.size(); if(aLength == 0) return (new SALOMEDS::TMPFile); //Get a temporary directory for saved a file - string aTmpDir = theFromDirectory; + std::string aTmpDir = theFromDirectory; long aBufferSize = 0; long aCurrentPos; @@ -196,24 +194,25 @@ namespace //Check if the file exists if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero - string aFullPath = aTmpDir + const_cast(theFiles[i].in()); - if(!Exists(aFullPath)) continue; + std::string aFullPath = aTmpDir + theFiles[i]; + if(!Exists(aFullPath)) continue; #ifdef WIN32 - ifstream aFile(aFullPath.c_str(), ios::binary); + std::ifstream aFile(aFullPath.c_str(), std::ios::binary); #else - ifstream aFile(aFullPath.c_str()); + std::ifstream aFile(aFullPath.c_str()); #endif - aFile.seekg(0, ios::end); - aFileSize[i] = aFile.tellg(); - aBufferSize += aFileSize[i]; //Add a space to store the file + aFile.seekg(0, std::ios::end); + aFileSize[i] = aFile.tellg(); + aBufferSize += aFileSize[i]; //Add a space to store the file } - aFileNameSize[i] = strlen(theFileNames[i])+1; + aFileNameSize[i] = theFileNames[i].length()+1; aBufferSize += aFileNameSize[i]; //Add a space to store the file name aBufferSize += (theNamesOnly)?4:12; //Add 4 bytes: a length of the file name, // 8 bytes: length of the file itself aNbFiles++; } + if ( aNbFiles == 0 ) return (new SALOMEDS::TMPFile); aBufferSize += 4; //4 bytes for a number of the files that will be written to the stream; unsigned char* aBuffer = new unsigned char[aBufferSize]; if(aBuffer == NULL) @@ -228,14 +227,14 @@ namespace aCurrentPos = 4; for(i=0; i(theFiles[i].in()); - if(!Exists(aFullPath)) continue; + std::string aFullPath = aTmpDir + theFiles[i]; + if(!Exists(aFullPath)) continue; #ifdef WIN32 - aFile = new ifstream(aFullPath.c_str(), ios::binary); + aFile = new std::ifstream(aFullPath.c_str(), std::ios::binary); #else - aFile = new ifstream(aFullPath.c_str()); + aFile = new std::ifstream(aFullPath.c_str()); #endif } //Initialize 4 bytes of the buffer by 0 @@ -245,21 +244,21 @@ namespace aCurrentPos += 4; //Copy the file name to the buffer - memcpy((aBuffer + aCurrentPos), theFileNames[i], aFileNameSize[i]); + memcpy((aBuffer + aCurrentPos), theFileNames[i].c_str(), aFileNameSize[i]); aCurrentPos += aFileNameSize[i]; if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly - //Initialize 8 bytes of the buffer by 0 - memset((aBuffer + aCurrentPos), 0, 8); - //Copy the length of the file to the buffer - memcpy((aBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long))); - aCurrentPos += 8; - - aFile->seekg(0, ios::beg); - aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]); - aFile->close(); - delete(aFile); - aCurrentPos += aFileSize[i]; + //Initialize 8 bytes of the buffer by 0 + memset((aBuffer + aCurrentPos), 0, 8); + //Copy the length of the file to the buffer + memcpy((aBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long))); + aCurrentPos += 8; + + aFile->seekg(0, std::ios::beg); + aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]); + aFile->close(); + delete(aFile); + aCurrentPos += aFileSize[i]; } } @@ -277,17 +276,17 @@ namespace SALOMEDS::TMPFile* SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory, - const SALOMEDS::ListOfFileNames& theFiles, - const int theNamesOnly) + const ListOfFiles& theFiles, + const int theNamesOnly) { - SALOMEDS::ListOfFileNames aFileNames(theFiles); + ListOfFiles aFileNames(theFiles); return ::PutFilesToStream(theFromDirectory,theFiles,aFileNames,theNamesOnly); } SALOMEDS::TMPFile* -SALOMEDS_Tool::PutFilesToStream(const SALOMEDS::ListOfFileNames& theFiles, - const SALOMEDS::ListOfFileNames& theFileNames) +SALOMEDS_Tool::PutFilesToStream(const ListOfFiles& theFiles, + const ListOfFiles& theFileNames) { return ::PutFilesToStream("",theFiles,theFileNames,0); } @@ -296,18 +295,18 @@ SALOMEDS_Tool::PutFilesToStream(const SALOMEDS::ListOfFileNames& theFiles, // function : PutStreamToFile // purpose : converts the stream "theStream" to the files //============================================================================ -SALOMEDS::ListOfFileNames_var +SALOMEDS_Tool::ListOfFiles SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, - const std::string& theToDirectory, - const int theNamesOnly) + const std::string& theToDirectory, + const int theNamesOnly) { - SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames; + ListOfFiles aFiles; if(theStream.length() == 0) return aFiles; //Get a temporary directory for saving a file - string aTmpDir = theToDirectory; + std::string aTmpDir = theToDirectory; unsigned char *aBuffer = (unsigned char*)theStream.NP_data(); @@ -320,7 +319,7 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, //Copy the number of files in the stream memcpy(&aNbFiles, aBuffer, sizeof(int)); - aFiles->length(aNbFiles); + aFiles.reserve(aNbFiles); for(i=0; i 8) ? 8 : sizeof(long))); aCurrentPos += 8; - string aFullPath = aTmpDir + aFileName; + std::string aFullPath = aTmpDir + aFileName; #ifdef WIN32 - ofstream aFile(aFullPath.c_str(), ios::binary); + std::ofstream aFile(aFullPath.c_str(), std::ios::binary); #else - ofstream aFile(aFullPath.c_str()); + std::ofstream aFile(aFullPath.c_str()); #endif aFile.write((char *)(aBuffer+aCurrentPos), aFileSize); aFile.close(); aCurrentPos += aFileSize; } - aFiles[i] = CORBA::string_dup(aFileName); + aFiles.push_back(CORBA::string_dup(aFileName)); delete[] aFileName; } @@ -361,7 +367,7 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, //============================================================================ std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) { if (thePath.empty()) return ""; - string aPath = thePath; + std::string aPath = thePath; bool isFound = false; int pos = aPath.rfind('/'); if(pos > 0) { @@ -394,7 +400,7 @@ std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) { if (thePath.empty()) return ""; int pos = thePath.rfind('/'); - string path; + std::string path; if(pos > 0) { path = thePath.substr(0, pos+1); } @@ -508,4 +514,3 @@ void SALOMEDS_Tool::GetAllChildren( SALOMEDS::Study_var theStudy, } -