Salome HOME
projects
/
modules
/
kernel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Compilation under Windows: add missing header
[modules/kernel.git]
/
src
/
TOOLSDS
/
SALOMEDS_Tool.cxx
diff --git
a/src/TOOLSDS/SALOMEDS_Tool.cxx
b/src/TOOLSDS/SALOMEDS_Tool.cxx
index 86fec025bee22084ed330e5ef71b7fb0de6e064f..2b61d3fddcb726106b06b87a1c5049cdbd34e6a6 100644
(file)
--- a/
src/TOOLSDS/SALOMEDS_Tool.cxx
+++ b/
src/TOOLSDS/SALOMEDS_Tool.cxx
@@
-1,4
+1,4
@@
-// Copyright (C) 2007-20
13
CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-20
21
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
@@
-6,7
+6,7
@@
// 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
// 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
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-30,6
+30,7
@@
#include "utilities.h"
#include "Basics_DirUtils.hxx"
#include "utilities.h"
#include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
#ifndef WIN32
#include <sys/time.h>
#ifndef WIN32
#include <sys/time.h>
@@
-44,24
+45,13
@@
#include <iostream>
#include <fstream>
#include <iostream>
#include <fstream>
-#include <stdlib.h>
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
bool Exists(const std::string thePath)
{
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
bool Exists(const std::string thePath)
{
-#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
- if ( GetLastError () == ERROR_FILE_NOT_FOUND ) {
- return false;
- }
- }
-#else
- int status = access ( thePath.c_str() , F_OK );
- if (status != 0) return false;
-#endif
- return true;
+ return Kernel_Utils::IsExists(thePath);
}
}
@@
-132,19
+122,24
@@
std::string SALOMEDS_Tool::GetTmpDir()
// purpose : Removes files listed in theFileList
//============================================================================
void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
// purpose : Removes files listed in theFileList
//============================================================================
void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
- const
SALOMEDS::ListOfFileNam
es& theFiles,
+ const
ListOfFil
es& theFiles,
const bool IsDirDeleted)
{
std::string aDirName = theDirectory;
const bool IsDirDeleted)
{
std::string aDirName = theDirectory;
-
int i, aLength = theFiles.length
();
+
size_t i, aLength = theFiles.size
();
for(i=1; i<=aLength; i++) {
std::string aFile(aDirName);
aFile += theFiles[i-1];
if(!Exists(aFile)) continue;
#ifdef WIN32
for(i=1; i<=aLength; i++) {
std::string aFile(aDirName);
aFile += theFiles[i-1];
if(!Exists(aFile)) continue;
#ifdef WIN32
- DeleteFile(aFile.c_str());
+#if defined(UNICODE)
+ std::wstring aFileToDelete = Kernel_Utils::utf8_decode_s(aFile);
+#else
+ std::string aFileToDelete = aFile;
+#endif
+ DeleteFile(aFileToDelete.c_str());
#else
unlink(aFile.c_str());
#endif
#else
unlink(aFile.c_str());
#endif
@@
-153,7
+148,12
@@
void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
if(IsDirDeleted) {
if(Exists(aDirName)) {
#ifdef WIN32
if(IsDirDeleted) {
if(Exists(aDirName)) {
#ifdef WIN32
- RemoveDirectory(aDirName.c_str());
+#if defined(UNICODE)
+ std::wstring aDirToDelete = Kernel_Utils::utf8_decode_s(aDirName);
+#else
+ std::string aDirToDelete = aDirName;
+#endif
+ RemoveDirectory(aDirToDelete.c_str());
#else
rmdir(aDirName.c_str());
#endif
#else
rmdir(aDirName.c_str());
#endif
@@
-170,11
+170,11
@@
namespace
{
SALOMEDS::TMPFile*
PutFilesToStream(const std::string& theFromDirectory,
{
SALOMEDS::TMPFile*
PutFilesToStream(const std::string& theFromDirectory,
- const
SALOMEDS::ListOfFileNames
& theFiles,
- const
SALOMEDS::ListOfFileNames
& theFileNames,
+ const
std::vector<std::string>
& theFiles,
+ const
std::vector<std::string>
& theFileNames,
const int theNamesOnly)
{
const int theNamesOnly)
{
- int i, aLength =
theFiles.length();
+ int i, aLength =
(int)theFiles.size(); //!< TODO: conversion from size_t to int
if(aLength == 0)
return (new SALOMEDS::TMPFile);
if(aLength == 0)
return (new SALOMEDS::TMPFile);
@@
-195,18
+195,22
@@
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
//Check if the file exists
if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero
- std::string aFullPath = aTmpDir +
const_cast<char*>(theFiles[i].in());
+ std::string aFullPath = aTmpDir +
theFiles[i];
if(!Exists(aFullPath)) continue;
#ifdef WIN32
if(!Exists(aFullPath)) continue;
#ifdef WIN32
+#ifdef UNICODE
+ std::ifstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
std::ifstream aFile(aFullPath.c_str(), std::ios::binary);
std::ifstream aFile(aFullPath.c_str(), std::ios::binary);
+#endif
#else
std::ifstream aFile(aFullPath.c_str());
#endif
aFile.seekg(0, std::ios::end);
#else
std::ifstream aFile(aFullPath.c_str());
#endif
aFile.seekg(0, std::ios::end);
- aFileSize[i] =
aFile.tellg();
+ aFileSize[i] =
(long)aFile.tellg(); //!< TODO: conversion from std::streamoff to long
aBufferSize += aFileSize[i]; //Add a space to store the file
}
aBufferSize += aFileSize[i]; //Add a space to store the file
}
- aFileNameSize[i] =
strlen(theFileNames[i])+1;
+ aFileNameSize[i] =
(int)theFileNames[i].length()+1; //!< TODO: conversion from size_t to int
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
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
@@
-215,7
+219,8
@@
namespace
if ( aNbFiles == 0 ) return (new SALOMEDS::TMPFile);
aBufferSize += 4; //4 bytes for a number of the files that will be written to the stream;
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];
+ unsigned char* aBuffer = new unsigned char[aBufferSize];
+
if(aBuffer == NULL)
return (new SALOMEDS::TMPFile);
if(aBuffer == NULL)
return (new SALOMEDS::TMPFile);
@@
-228,12
+233,16
@@
namespace
aCurrentPos = 4;
for(i=0; i<aLength; i++) {
aCurrentPos = 4;
for(i=0; i<aLength; i++) {
- std::ifstream *aFile;
+
std::ifstream *aFile;
if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
- std::string aFullPath = aTmpDir +
const_cast<char*>(theFiles[i].in())
;
+ std::string aFullPath = aTmpDir +
theFiles[i]
;
if(!Exists(aFullPath)) continue;
#ifdef WIN32
if(!Exists(aFullPath)) continue;
#ifdef WIN32
+#ifdef UNICODE
+ aFile = new std::ifstream (Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
aFile = new std::ifstream(aFullPath.c_str(), std::ios::binary);
aFile = new std::ifstream(aFullPath.c_str(), std::ios::binary);
+#endif
#else
aFile = new std::ifstream(aFullPath.c_str());
#endif
#else
aFile = new std::ifstream(aFullPath.c_str());
#endif
@@
-245,7
+254,7
@@
namespace
aCurrentPos += 4;
//Copy the file name to the buffer
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
aCurrentPos += aFileNameSize[i];
if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly
@@
-256,7
+265,7
@@
namespace
aCurrentPos += 8;
aFile->seekg(0, std::ios::beg);
aCurrentPos += 8;
aFile->seekg(0, std::ios::beg);
- aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
+
aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
aFile->close();
delete(aFile);
aCurrentPos += aFileSize[i];
aFile->close();
delete(aFile);
aCurrentPos += aFileSize[i];
@@
-277,17
+286,17
@@
namespace
SALOMEDS::TMPFile*
SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory,
SALOMEDS::TMPFile*
SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory,
- const
SALOMEDS::ListOfFileNam
es& theFiles,
+ const
ListOfFil
es& theFiles,
const int theNamesOnly)
{
const int theNamesOnly)
{
-
SALOMEDS::ListOfFileNam
es aFileNames(theFiles);
+
ListOfFil
es aFileNames(theFiles);
return ::PutFilesToStream(theFromDirectory,theFiles,aFileNames,theNamesOnly);
}
SALOMEDS::TMPFile*
return ::PutFilesToStream(theFromDirectory,theFiles,aFileNames,theNamesOnly);
}
SALOMEDS::TMPFile*
-SALOMEDS_Tool::PutFilesToStream(const
SALOMEDS::ListOfFileNam
es& theFiles,
- const
SALOMEDS::ListOfFileNam
es& theFileNames)
+SALOMEDS_Tool::PutFilesToStream(const
ListOfFil
es& theFiles,
+ const
ListOfFil
es& theFileNames)
{
return ::PutFilesToStream("",theFiles,theFileNames,0);
}
{
return ::PutFilesToStream("",theFiles,theFileNames,0);
}
@@
-296,19
+305,18
@@
SALOMEDS_Tool::PutFilesToStream(const SALOMEDS::ListOfFileNames& theFiles,
// function : PutStreamToFile
// purpose : converts the stream "theStream" to the files
//============================================================================
// 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)
{
SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
const std::string& theToDirectory,
const int theNamesOnly)
{
-
SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNam
es;
+
ListOfFiles aFil
es;
if(theStream.length() == 0)
return aFiles;
//Get a temporary directory for saving a file
std::string aTmpDir = theToDirectory;
if(theStream.length() == 0)
return aFiles;
//Get a temporary directory for saving a file
std::string aTmpDir = theToDirectory;
-
unsigned char *aBuffer = (unsigned char*)theStream.NP_data();
if(aBuffer == NULL)
unsigned char *aBuffer = (unsigned char*)theStream.NP_data();
if(aBuffer == NULL)
@@
-320,7
+328,7
@@
SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
//Copy the number of files in the stream
memcpy(&aNbFiles, aBuffer, sizeof(int));
//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++) {
for(i=0; i<aNbFiles; i++) {
@@
-332,10
+340,10
@@
SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
//Put a file name to aFileName
memcpy(aFileName, (aBuffer + aCurrentPos), aFileNameSize);
#ifdef WIN32
//Put a file name to aFileName
memcpy(aFileName, (aBuffer + aCurrentPos), aFileNameSize);
#ifdef WIN32
- for (int
i = 0; i < strlen(aFileName); i
++)
+ for (int
j = 0; j < strlen(aFileName); j
++)
{
{
- if (aFileName[
i
] == ':')
-
aFileName[i
] = '_';
+ if (aFileName[
j
] == ':')
+
aFileName[j
] = '_';
}
#endif
aCurrentPos += aFileNameSize;
}
#endif
aCurrentPos += aFileNameSize;
@@
-347,15
+355,19
@@
SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
std::string aFullPath = aTmpDir + aFileName;
#ifdef WIN32
std::string aFullPath = aTmpDir + aFileName;
#ifdef WIN32
+#ifdef UNICODE
+ std::ofstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
+#endif
#else
std::ofstream aFile(aFullPath.c_str());
#endif
#else
std::ofstream aFile(aFullPath.c_str());
#endif
- aFile.write((char *)(aBuffer+aCurrentPos), aFileSize);
+ aFile.write((char *)(aBuffer + aCurrentPos), aFileSize);
aFile.close();
aCurrentPos += aFileSize;
}
aFile.close();
aCurrentPos += aFileSize;
}
- aFiles
[i] = CORBA::string_dup(aFileName
);
+ aFiles
.push_back(CORBA::string_dup(aFileName)
);
delete[] aFileName;
}
delete[] aFileName;
}
@@
-370,25
+382,25
@@
std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) {
if (thePath.empty()) return "";
std::string aPath = thePath;
bool isFound = false;
if (thePath.empty()) return "";
std::string aPath = thePath;
bool isFound = false;
-
in
t pos = aPath.rfind('/');
- if(pos
> 0
) {
+
size_
t pos = aPath.rfind('/');
+ if(pos
!= std::string::npos
) {
aPath = aPath.substr(pos+1, aPath.size());
isFound = true;
}
if(!isFound) {
pos = aPath.rfind('\\');
aPath = aPath.substr(pos+1, aPath.size());
isFound = true;
}
if(!isFound) {
pos = aPath.rfind('\\');
- if(pos
> 0
) {
+ if(pos
!= std::string::npos
) {
aPath = aPath.substr(pos+1, aPath.size());
isFound = true;
}
}
if(!isFound) {
pos = aPath.rfind('|');
aPath = aPath.substr(pos+1, aPath.size());
isFound = true;
}
}
if(!isFound) {
pos = aPath.rfind('|');
- if(pos
> 0) aPath =
aPath.substr(pos+1, aPath.size());
+ if(pos
!= std::string::npos) aPath =
aPath.substr(pos+1, aPath.size());
}
pos = aPath.rfind('.');
}
pos = aPath.rfind('.');
- if(pos
> 0
) aPath = aPath.substr(0, pos); //Remove extension
+ if(pos
!= std::string::npos
) aPath = aPath.substr(0, pos); //Remove extension
return aPath;
}
return aPath;
}
@@
-400,18
+412,18
@@
std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) {
std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) {
if (thePath.empty()) return "";
std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) {
if (thePath.empty()) return "";
-
in
t pos = thePath.rfind('/');
+
size_
t pos = thePath.rfind('/');
std::string path;
std::string path;
- if(pos
> 0
) {
+ if(pos
!= std::string::npos
) {
path = thePath.substr(0, pos+1);
}
if(path.empty()) {
pos = thePath.rfind('\\');
path = thePath.substr(0, pos+1);
}
if(path.empty()) {
pos = thePath.rfind('\\');
- if(pos
> 0
) path = thePath.substr(0, pos+1);
+ if(pos
!= std::string::npos
) path = thePath.substr(0, pos+1);
}
if(path.empty()) {
pos = thePath.rfind('|');
}
if(path.empty()) {
pos = thePath.rfind('|');
- if(pos
> 0
) path = thePath.substr(0, pos+1);
+ if(pos
!= std::string::npos
) path = thePath.substr(0, pos+1);
}
if(path.empty()) {
path = thePath+"/";
}
if(path.empty()) {
path = thePath+"/";
@@
-421,7
+433,7
@@
std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) {
if(path.size() == 2 && path[1] == ':') path +='\\';
#endif
if(path.size() == 2 && path[1] == ':') path +='\\';
#endif
- for(
in
t i = 0, len = path.size(); i<len; i++)
+ for(
size_
t i = 0, len = path.size(); i<len; i++)
if(path[i] == '|') path[i] = '/';
return path;
}
if(path[i] == '|') path[i] = '/';
return path;
}
@@
-431,7
+443,7
@@
std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) {
// Purpose : Retrieve specified flaf from "AttributeFlags" attribute
//=======================================================================
bool SALOMEDS_Tool::GetFlag( const int theFlag,
// Purpose : Retrieve specified flaf from "AttributeFlags" attribute
//=======================================================================
bool SALOMEDS_Tool::GetFlag( const int theFlag,
- SALOMEDS::Study_var
theStudy
,
+ SALOMEDS::Study_var
/*theStudy*/
,
SALOMEDS::SObject_var theObj )
{
SALOMEDS::GenericAttribute_var anAttr;
SALOMEDS::SObject_var theObj )
{
SALOMEDS::GenericAttribute_var anAttr;
@@
-515,4
+527,3
@@
void SALOMEDS_Tool::GetAllChildren( SALOMEDS::Study_var theStudy,
}
}
-