]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
first executable version
authorabd <abd@opencascade.com>
Fri, 4 Apr 2008 10:38:34 +0000 (10:38 +0000)
committerabd <abd@opencascade.com>
Fri, 4 Apr 2008 10:38:34 +0000 (10:38 +0000)
src/TOOLSDS/SALOMEDS_Tool.cxx

index fcf2be69dad1e7c513e116a140d4d0f43adde91d..e206c4374b4e3836b6d1d36d3d1fae1aa691e997 100644 (file)
@@ -32,8 +32,6 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <iostream.h> 
-#include <fstream.h>
 #include <pwd.h> 
 #include <unistd.h>
 #else
@@ -41,6 +39,8 @@
 #include <lmcons.h>
 #endif
 
+#include <iostream> 
+#include <fstream>
 #include <stdlib.h>
 
 #include <SALOMEconfig.h>
@@ -130,8 +130,8 @@ 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 SALOMEDS::ListOfFileNames& theFiles,
+                                         const bool IsDirDeleted)
 {
   string aDirName = theDirectory;
 
@@ -151,7 +151,7 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
   if(IsDirDeleted) {
     if(Exists(aDirName)) {
 #ifdef WNT
-      RemoveDirectory(aDireName.c_str());
+      RemoveDirectory(aDirName.c_str());
 #else
       rmdir(aDirName.c_str());
 #endif
@@ -167,42 +167,42 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
 namespace
 {
   SALOMEDS::TMPFile* 
-  PutFilesToStream(const std::string& theFromDirectory,
-                  const SALOMEDS::ListOfFileNames& theFiles,
-                  const SALOMEDS::ListOfFileNames& theFileNames,
-                  const int theNamesOnly)
+    PutFilesToStream(const std::string& theFromDirectory,
+    const SALOMEDS::ListOfFileNames& theFiles,
+    const SALOMEDS::ListOfFileNames& theFileNames,
+    const int theNamesOnly)
   {
     int i, aLength = theFiles.length();
     if(aLength == 0)
       return (new SALOMEDS::TMPFile);
-    
+
     //Get a temporary directory for saved a file
     string aTmpDir = theFromDirectory;
-    
+
     long aBufferSize = 0;
     long aCurrentPos;
-    
+
     int aNbFiles = 0;
     int* aFileNameSize= new int[aLength];
     long* aFileSize= new long[aLength];
-    
+
     //Determine the required size of the buffer
-    
+
     for(i=0; i<aLength; i++) {
-      
+
       //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;
+        string aFullPath = aTmpDir + const_cast<char*>(theFiles[i].in());   
+        if(!Exists(aFullPath)) continue;
 #ifdef WNT
-       ifstream aFile(aFullPath.c_str(), ios::binary);
+        ifstream aFile(aFullPath.c_str(), ios::binary);
 #else
-       ifstream aFile(aFullPath.c_str());
+        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, ios::end);
+        aFileSize[i] = aFile.tellg();
+        aBufferSize += aFileSize[i];              //Add a space to store the file
       }
       aFileNameSize[i] = strlen(theFileNames[i])+1;
       aBufferSize += aFileNameSize[i];          //Add a space to store the file name
@@ -210,29 +210,29 @@ namespace
       //    8 bytes: length of the file itself
       aNbFiles++;
     } 
-    
+
     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)
       return (new SALOMEDS::TMPFile);
-    
+
     //Initialize 4 bytes of the buffer by 0
     memset(aBuffer, 0, 4); 
     //Copy the number of files that will be written to the stream
     memcpy(aBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); 
-    
-    
+
+
     aCurrentPos = 4;
-    
+
     for(i=0; i<aLength; i++) {
       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;
+        string aFullPath = aTmpDir + const_cast<char*>(theFiles[i].in());
+        if(!Exists(aFullPath)) continue;
 #ifdef WNT
-       aFile = new ifstream(aFullPath.c_str(), ios::binary);
+        aFile = new ifstream(aFullPath.c_str(), ios::binary);
 #else
-       aFile = new ifstream(aFullPath.c_str());
+        aFile = new ifstream(aFullPath.c_str());
 #endif  
       }
       //Initialize 4 bytes of the buffer by 0
@@ -240,42 +240,42 @@ namespace
       //Copy the length of the file name to the buffer
       memcpy((aBuffer + aCurrentPos), (aFileNameSize + i), ((sizeof(int) > 4) ? 4 : sizeof(int))); 
       aCurrentPos += 4;
-      
+
       //Copy the file name to the buffer
       memcpy((aBuffer + aCurrentPos), theFileNames[i], 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, ios::beg);
+        aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
+        aFile->close();
+        delete(aFile);
+        aCurrentPos += aFileSize[i];
       }
     }
-    
+
     delete[] aFileNameSize;
     delete[] aFileSize;
-    
-    
+
+
     CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
-    
+
     return (new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1));
   }
-  
+
 }
 
 
 SALOMEDS::TMPFile* 
 SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory,
-                               const SALOMEDS::ListOfFileNames& theFiles,
-                               const int theNamesOnly)
+                                const SALOMEDS::ListOfFileNames& theFiles,
+                                const int theNamesOnly)
 {
   SALOMEDS::ListOfFileNames aFileNames(theFiles);
   return ::PutFilesToStream(theFromDirectory,theFiles,aFileNames,theNamesOnly);
@@ -284,7 +284,7 @@ SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory,
 
 SALOMEDS::TMPFile* 
 SALOMEDS_Tool::PutFilesToStream(const SALOMEDS::ListOfFileNames& theFiles,
-                               const SALOMEDS::ListOfFileNames& theFileNames)
+                                const SALOMEDS::ListOfFileNames& theFileNames)
 {
   return ::PutFilesToStream("",theFiles,theFileNames,0);
 }
@@ -295,8 +295,8 @@ SALOMEDS_Tool::PutFilesToStream(const SALOMEDS::ListOfFileNames& theFiles,
 //============================================================================
 SALOMEDS::ListOfFileNames_var 
 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;
 
@@ -329,12 +329,12 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
     //Put a file name to aFileName
     memcpy(aFileName, (aBuffer + aCurrentPos), aFileNameSize); 
     aCurrentPos += aFileNameSize;
+
     //Put a length of the file to aFileSize
     if (!theNamesOnly) {
       memcpy(&aFileSize, (aBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long)));
       aCurrentPos += 8;    
-      
+
       string aFullPath = aTmpDir + aFileName;
 #ifdef WNT
       ofstream aFile(aFullPath.c_str(), ios::binary);
@@ -379,7 +379,7 @@ std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) {
 
   pos = aPath.rfind('.'); 
   if(pos > 0)  aPath = aPath.substr(0, pos); //Remove extension
-    
+
   return aPath;
 }
 
@@ -406,9 +406,9 @@ std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) {
   if(path.empty()) {
     path = thePath+"/";
   }
-  
+
 #ifdef WNT  //Check if the only disk letter is given as path
-  if(path.size() == 2 && path[1] == ":") path +='\\';
+  if(path.size() == 2 && path[1] == ':') path +='\\';
 #endif
 
   for(int i = 0, len = path.size(); i<len; i++) 
@@ -421,8 +421,8 @@ std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) {
 // Purpose : Retrieve specified flaf from "AttributeFlags" attribute
 //=======================================================================
 bool SALOMEDS_Tool::GetFlag( const int             theFlag,
-                             SALOMEDS::Study_var   theStudy,
-                             SALOMEDS::SObject_var theObj )
+                            SALOMEDS::Study_var   theStudy,
+                            SALOMEDS::SObject_var theObj )
 {
   SALOMEDS::GenericAttribute_var anAttr;
   if ( !theObj->_is_nil() && theObj->FindAttribute( anAttr, "AttributeFlags" ) )
@@ -439,9 +439,9 @@ bool SALOMEDS_Tool::GetFlag( const int             theFlag,
 // Purpose : Set/Unset specified flaf from "AttributeFlags" attribute
 //=======================================================================
 bool SALOMEDS_Tool::SetFlag( const int           theFlag,
-                             SALOMEDS::Study_var theStudy,
-                             const std::string&  theEntry,
-                             const bool          theValue )
+                            SALOMEDS::Study_var theStudy,
+                            const std::string&  theEntry,
+                            const bool          theValue )
 {
   SALOMEDS::SObject_var anObj = theStudy->FindObjectID(theEntry.c_str());
 
@@ -472,8 +472,8 @@ bool SALOMEDS_Tool::SetFlag( const int           theFlag,
 //           If theObj is null all objects of study are returned
 //=======================================================================
 void SALOMEDS_Tool::GetAllChildren( SALOMEDS::Study_var               theStudy,
-                                    SALOMEDS::SObject_var             theObj,
-                                    std::list<SALOMEDS::SObject_var>& theList )
+                                   SALOMEDS::SObject_var             theObj,
+                                   std::list<SALOMEDS::SObject_var>& theList )
 {
   if ( theObj->_is_nil() )
   {