-// 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
#include <iostream>
#include <fstream>
-#include <stdlib.h>
#include <SALOMEconfig.h>
#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 ) {
// 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;
{
SALOMEDS::TMPFile*
PutFilesToStream(const std::string& theFromDirectory,
- const SALOMEDS::ListOfFileNames& theFiles,
- const SALOMEDS::ListOfFileNames& theFileNames,
- const int theNamesOnly)
+ const std::vector<std::string>& theFiles,
+ const std::vector<std::string>& 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;
//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<char*>(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)
aCurrentPos = 4;
for(i=0; i<aLength; i++) {
- ifstream *aFile;
+ std::ifstream *aFile;
if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
- string aFullPath = aTmpDir + const_cast<char*>(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
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];
}
}
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);
}
// 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();
//Copy the number of files in the stream
memcpy(&aNbFiles, aBuffer, sizeof(int));
- aFiles->length(aNbFiles);
+ aFiles.reserve(aNbFiles);
for(i=0; i<aNbFiles; i++) {
char *aFileName = new char[aFileNameSize];
//Put a file name to aFileName
memcpy(aFileName, (aBuffer + aCurrentPos), aFileNameSize);
+#ifdef WIN32
+ for (int i = 0; i < strlen(aFileName); i++)
+ {
+ if (aFileName[i] == ':')
+ aFileName[i] = '_';
+ }
+#endif
aCurrentPos += aFileNameSize;
//Put a length of the file to aFileSize
memcpy(&aFileSize, (aBuffer + aCurrentPos), ((sizeof(long) > 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;
}
//============================================================================
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) {
if (thePath.empty()) return "";
int pos = thePath.rfind('/');
- string path;
+ std::string path;
if(pos > 0) {
path = thePath.substr(0, pos+1);
}
}
-