]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix for Bug GVIEW10647
authorapo <apo@opencascade.com>
Fri, 10 Feb 2006 08:12:55 +0000 (08:12 +0000)
committerapo <apo@opencascade.com>
Fri, 10 Feb 2006 08:12:55 +0000 (08:12 +0000)
   Crash saving the model
(memory allocation optimized)

src/SALOMEDS/Makefile.in
src/SALOMEDS/SALOMEDS_Driver_i.cxx
src/SALOMEDS/SALOMEDS_Driver_i.hxx
src/SALOMEDS/SALOMEDS_TMPFile_i.cxx [new file with mode: 0644]
src/SALOMEDS/SALOMEDS_TMPFile_i.hxx [new file with mode: 0644]
src/SALOMEDSImpl/Makefile.in
src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx
src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.cxx [new file with mode: 0644]
src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.hxx [new file with mode: 0644]

index 96fb1ae2a1bae5409d50791dd31bc405f920032f..57c960664df22048360a7790aff1963be352d67f 100644 (file)
@@ -107,8 +107,8 @@ LIB_SRC =   \
                  SALOMEDS_AttributeTextColor.cxx \
                  SALOMEDS_AttributeTextHighlightColor.cxx \
                  SALOMEDS_AttributeTreeNode.cxx \
-                 SALOMEDS_AttributeUserID.cxx
-
+                 SALOMEDS_AttributeUserID.cxx \
+                  SALOMEDS_TMPFile_i.cxx
 
 # Executables targets
 BIN = SALOMEDS_Server SALOMEDS_Client
index 2f4f085cafd11e210ed674aaf88580ed690da481..d9995703fbda47517320b58c020d53dc06eb2bb7 100644 (file)
@@ -20,6 +20,7 @@
 
 
 #include "SALOMEDS_Driver_i.hxx"
+#include <SALOMEDS_TMPFile_i.hxx>
 #include "utilities.h"
 #include "SALOMEDS_SObject_i.hxx"
 #include "SALOMEDS_SComponent_i.hxx"
@@ -33,44 +34,38 @@ SALOMEDS_Driver_i::~SALOMEDS_Driver_i()
 {
 }
 
-unsigned char* SALOMEDS_Driver_i::Save(const Handle(SALOMEDSImpl_SComponent)& theComponent,
-                                      const TCollection_AsciiString& theURL,
-                                      long& theStreamLength,
-                                      bool isMultiFile)
+Handle(SALOMEDSImpl_TMPFile) SALOMEDS_Driver_i::Save(const Handle(SALOMEDSImpl_SComponent)& theComponent,
+                                                    const TCollection_AsciiString& theURL,
+                                                    long& theStreamLength,
+                                                    bool isMultiFile)
 {  
   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
-  SALOMEDS::TMPFile_var aStream;
   CORBA::String_var url = CORBA::string_dup(theURL.ToCString());
+
   SALOMEDS::unlock();
-  aStream = _driver->Save(sco.in(), url, isMultiFile);
+  SALOMEDS::TMPFile_var aStream = _driver->Save(sco.in(), url, isMultiFile);
+  Handle(SALOMEDSImpl_TMPFile) aTMPFile(new SALOMEDS_TMPFile_i(aStream._retn()));
+  theStreamLength = aTMPFile->Size();
   SALOMEDS::lock();
-  theStreamLength = aStream->length();
-  unsigned char* aRetStream = NULL;
-  if (theStreamLength > 0) {
-    aRetStream = new unsigned char[theStreamLength];
-    memcpy(aRetStream, aStream->NP_data(), theStreamLength);
-  }
-  return aRetStream;
+
+  return aTMPFile;
 }
 
-unsigned char* SALOMEDS_Driver_i::SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent,
-                                           const TCollection_AsciiString& theURL,
-                                           long& theStreamLength,
-                                           bool isMultiFile)
+Handle(SALOMEDSImpl_TMPFile) SALOMEDS_Driver_i::SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent,
+                                                         const TCollection_AsciiString& theURL,
+                                                         long& theStreamLength,
+                                                         bool isMultiFile)
 {
   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
-  SALOMEDS::TMPFile_var aStream;
   CORBA::String_var url = CORBA::string_dup(theURL.ToCString());
+
   SALOMEDS::unlock();
-  aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
+  SALOMEDS::TMPFile_var aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
+  Handle(SALOMEDSImpl_TMPFile) aTMPFile(new SALOMEDS_TMPFile_i(aStream._retn()));
+  theStreamLength = aTMPFile->Size();
   SALOMEDS::lock();
-  theStreamLength = aStream->length();
-  unsigned char* aRetStream = NULL;
-  if (theStreamLength > 0) {
-    aRetStream = new unsigned char[theStreamLength];
-    memcpy(aRetStream, aStream->NP_data(), theStreamLength);
-  }
-  return aRetStream; 
+
+  return aTMPFile;
 }
   
 bool SALOMEDS_Driver_i::Load(const Handle(SALOMEDSImpl_SComponent)& theComponent,
@@ -92,6 +87,7 @@ bool SALOMEDS_Driver_i::Load(const Handle(SALOMEDSImpl_SComponent)& theComponent
   SALOMEDS::unlock();
   bool isOk = _driver->Load(sco.in(), aStream.in(), url, isMultiFile);
   SALOMEDS::lock();
+
   return isOk;
 }
 
@@ -114,12 +110,14 @@ bool SALOMEDS_Driver_i::LoadASCII(const Handle(SALOMEDSImpl_SComponent)& theComp
   SALOMEDS::unlock();
   bool isOk = _driver->LoadASCII(sco.in(), aStream.in(), url, isMultiFile);
   SALOMEDS::lock();
+
   return isOk;
 }
 
 void SALOMEDS_Driver_i::Close(const Handle(SALOMEDSImpl_SComponent)& theComponent)
 {
   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
+
   SALOMEDS::unlock();
   _driver->Close(sco.in());
   SALOMEDS::lock();
@@ -134,9 +132,11 @@ TCollection_AsciiString SALOMEDS_Driver_i::IORToLocalPersistentID(const Handle(S
 {
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theSObject, _orb);
   CORBA::String_var ior = CORBA::string_dup(IORString.ToCString());
+
   SALOMEDS::unlock();
   CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), ior.in(), isMultiFile, isASCII);
   SALOMEDS::lock();
+
   return TCollection_AsciiString(pers_string);
 }
 
@@ -157,35 +157,30 @@ TCollection_AsciiString SALOMEDS_Driver_i::LocalPersistentIDToIOR(const Handle(S
 bool SALOMEDS_Driver_i::CanCopy(const Handle(SALOMEDSImpl_SObject)& theObject)
 {
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
+
   SALOMEDS::unlock();
   bool isOk = _driver->CanCopy(so.in());
   SALOMEDS::lock();
+
   return isOk;
 }
 
 
-unsigned char* SALOMEDS_Driver_i::CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, 
-                                          int& theObjectID,
-                                          long& theStreamLength)
+Handle(SALOMEDSImpl_TMPFile) SALOMEDS_Driver_i::CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, 
+                                                        int& theObjectID,
+                                                        long& theStreamLength)
 {
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
-  SALOMEDS::TMPFile_var aStream;
-  CORBA::Long anObjectID;
 
   SALOMEDS::unlock();
-  aStream = _driver->CopyFrom(so.in(), anObjectID);
-  SALOMEDS::lock();
-
+  CORBA::Long anObjectID;
+  SALOMEDS::TMPFile_var aStream = _driver->CopyFrom(so.in(), anObjectID);
+  Handle(SALOMEDSImpl_TMPFile) aTMPFile(new SALOMEDS_TMPFile_i(aStream._retn()));
+  theStreamLength = aTMPFile->Size();
   theObjectID = anObjectID;
-  theStreamLength = aStream->length();
-
-  unsigned char* aRetStream = NULL;
-  if(theStreamLength > 0) {
-    aRetStream = new unsigned char[theStreamLength];
-    memcpy(aRetStream, aStream->NP_data(), theStreamLength);
-  }
+  SALOMEDS::lock();
 
-  return aRetStream;
+  return aTMPFile;
 }
 
 bool SALOMEDS_Driver_i::CanPaste(const TCollection_AsciiString& theComponentName, int theObjectID)
@@ -217,30 +212,24 @@ TCollection_AsciiString SALOMEDS_Driver_i::PasteInto(const unsigned char* theStr
   return TCollection_AsciiString((char*)ret_so->GetID());
 }
 
-unsigned char* SALOMEDS_Driver_i::DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, 
-                                            bool isPublished, 
-                                            bool& isValidScript,
-                                            long& theStreamLength)
+Handle(SALOMEDSImpl_TMPFile) SALOMEDS_Driver_i::DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, 
+                                                          bool isPublished, 
+                                                          bool& isValidScript,
+                                                          long& theStreamLength)
 {
   SALOMEDS_Study_i *  st_servant = new SALOMEDS_Study_i (theStudy, _orb);
   SALOMEDS::Study_var st  = SALOMEDS::Study::_narrow(st_servant->_this());
-  Engines::TMPFile_var aStream;
-  CORBA::Boolean aValidScript, aPublished;
-  aPublished = isPublished;
   Engines::Component_ptr aComponent = Engines::Component::_narrow(_driver);
+
   SALOMEDS::unlock();
-  aStream = aComponent->DumpPython(st.in(), aPublished, aValidScript);
-  SALOMEDS::lock();
+  CORBA::Boolean aValidScript, aPublished = isPublished;
+  Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, aValidScript);
+  Handle(SALOMEDSImpl_TMPFile) aTMPFile(new Engines_TMPFile_i(aStream._retn()));
+  theStreamLength = aTMPFile->Size();
   isValidScript = aValidScript;
-  theStreamLength = aStream->length();
-  unsigned char* aRetStream = NULL;
-
-  if(theStreamLength > 0) {
-    aRetStream = new unsigned char[theStreamLength];
-    memcpy(aRetStream, aStream->NP_data(), theStreamLength);
-  }
+  SALOMEDS::lock();
 
-  return aRetStream;
+  return aTMPFile;
 }
 
 //###############################################################################################################
index ae49cdba2ebb6171b0d6fa67704f6101eaac1693..cf689687b282c0c0288c66b2abaae2768e77af12 100644 (file)
@@ -52,15 +52,15 @@ public:
       return TCollection_AsciiString(ior);
     }
 
-  virtual unsigned char* Save(const Handle(SALOMEDSImpl_SComponent)& theComponent,
-                             const TCollection_AsciiString& theURL,
-                             long& theStreamLength,
-                             bool isMultiFile);
-
-  virtual unsigned char* SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent,
-                                  const TCollection_AsciiString& theURL,
-                                  long& theStreamLength,
-                                  bool isMultiFile);
+  virtual Handle(SALOMEDSImpl_TMPFile) Save(const Handle(SALOMEDSImpl_SComponent)& theComponent,
+                                           const TCollection_AsciiString& theURL,
+                                           long& theStreamLength,
+                                           bool isMultiFile);
+
+  virtual Handle(SALOMEDSImpl_TMPFile) SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent,
+                                                const TCollection_AsciiString& theURL,
+                                                long& theStreamLength,
+                                                bool isMultiFile);
   
   virtual bool Load(const Handle(SALOMEDSImpl_SComponent)& theComponent,
                    const unsigned char* theStream,
@@ -95,10 +95,10 @@ public:
 
   virtual bool CanCopy(const Handle(SALOMEDSImpl_SObject)& theObject);
 
-  virtual unsigned char* CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, 
-                                 int& theObjectID,
-                                 long& theStreamLength);
-
+  virtual Handle(SALOMEDSImpl_TMPFile) CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, 
+                                               int& theObjectID,
+                                               long& theStreamLength);
+  
   virtual bool CanPaste(const TCollection_AsciiString& theComponentName, int theObjectID);
 
   virtual TCollection_AsciiString PasteInto(const unsigned char* theStream,
@@ -106,10 +106,10 @@ public:
                                            int theObjectID,
                                            const Handle(SALOMEDSImpl_SObject)& theObject);
 
-  virtual unsigned char* DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, 
-                                   bool isPublished, 
-                                   bool& isValidScript,
-                                   long& theStreamLength);
+  virtual Handle(SALOMEDSImpl_TMPFile) DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, 
+                                                 bool isPublished, 
+                                                 bool& isValidScript,
+                                                 long& theStreamLength);
 };
 
 #include "SALOME_NamingService.hxx"
diff --git a/src/SALOMEDS/SALOMEDS_TMPFile_i.cxx b/src/SALOMEDS/SALOMEDS_TMPFile_i.cxx
new file mode 100644 (file)
index 0000000..363df92
--- /dev/null
@@ -0,0 +1,96 @@
+// 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.
+//
+// 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/
+//
+//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
+//  File   : SALOMEDSImpl_SObject.cxx
+//  Author : Sergey RUIN
+//  Module : SALOME
+
+
+#include "SALOMEDS_TMPFile_i.hxx"
+
+#include <Handle_Standard_Type.hxx>
+#include <Standard_Transient.hxx>
+
+#include <stdexcept>
+
+
+IMPLEMENT_STANDARD_HANDLE( SALOMEDS_TMPFile_i, SALOMEDSImpl_TMPFile )
+IMPLEMENT_STANDARD_RTTIEXT( SALOMEDS_TMPFile_i, SALOMEDSImpl_TMPFile )
+
+SALOMEDS_TMPFile_i
+::SALOMEDS_TMPFile_i(SALOMEDS::TMPFile* theStream):
+  myStream(theStream)
+{}
+
+size_t
+SALOMEDS_TMPFile_i
+::Size()
+{
+  if(&myStream.in())
+    return 0;
+
+  return myStream->length();
+}
+
+SALOMEDSImpl_TMPFile::TOctet&
+SALOMEDS_TMPFile_i
+::Get(size_t theIndex)
+{
+  if(&myStream.in())
+    throw std::out_of_range("SALOMEDS_TMPFile_i::Get(size_t) const - &myStream.in()");
+
+  if(theIndex < 0 || theIndex >= myStream->length())
+    throw std::out_of_range("SALOMEDS_TMPFile_i::Get(size_t) const - theIndex < 0 || theIndex >= myStream->length()");
+
+  return myStream[theIndex];
+}
+
+
+//-----------------------------------------------------------------------------
+IMPLEMENT_STANDARD_HANDLE( Engines_TMPFile_i, SALOMEDSImpl_TMPFile )
+IMPLEMENT_STANDARD_RTTIEXT( Engines_TMPFile_i, SALOMEDSImpl_TMPFile )
+
+Engines_TMPFile_i
+::Engines_TMPFile_i(Engines::TMPFile* theStream):
+  myStream(theStream)
+{}
+
+size_t
+Engines_TMPFile_i
+::Size()
+{
+  if(&myStream.in())
+    return 0;
+
+  return myStream->length();
+}
+
+SALOMEDSImpl_TMPFile::TOctet&
+Engines_TMPFile_i
+::Get(size_t theIndex)
+{
+  if(&myStream.in())
+    throw std::out_of_range("Engines_TMPFile_i::Get(size_t) const - &myStream.in()");
+
+  if(theIndex < 0 || theIndex >= myStream->length())
+    throw std::out_of_range("Engines_TMPFile_i::Get(size_t) const - theIndex < 0 || theIndex >= myStream->length()");
+
+  return myStream[theIndex];
+}
diff --git a/src/SALOMEDS/SALOMEDS_TMPFile_i.hxx b/src/SALOMEDS/SALOMEDS_TMPFile_i.hxx
new file mode 100644 (file)
index 0000000..124d08d
--- /dev/null
@@ -0,0 +1,70 @@
+// 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.
+//
+// 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/
+//
+
+#ifndef __SALOMEDSIMPL_TMPFILE_I_H__
+#define __SALOMEDSIMPL_TMPFILE_I_H__
+
+// IDL headers
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOMEDS)
+#include CORBA_SERVER_HEADER(SALOME_Component)
+
+#include "SALOMEDSImpl_TMPFile.hxx"
+
+
+//-----------------------------------------------------------------------------
+DEFINE_STANDARD_HANDLE( SALOMEDS_TMPFile_i, SALOMEDSImpl_TMPFile );
+
+class SALOMEDS_TMPFile_i : public SALOMEDSImpl_TMPFile
+{
+public:
+  SALOMEDS_TMPFile_i(SALOMEDS::TMPFile* theStream);
+
+  virtual size_t Size();
+
+  virtual TOctet& Get(size_t);
+
+  DEFINE_STANDARD_RTTI( SALOMEDS_TMPFile_i );
+
+protected:
+  SALOMEDS::TMPFile_var myStream;
+};
+
+
+//-----------------------------------------------------------------------------
+DEFINE_STANDARD_HANDLE( Engines_TMPFile_i, SALOMEDSImpl_TMPFile );
+
+class Engines_TMPFile_i : public SALOMEDSImpl_TMPFile
+{
+public:
+  Engines_TMPFile_i(Engines::TMPFile* theStream);
+
+  virtual size_t Size();
+
+  virtual TOctet& Get(size_t);
+
+  DEFINE_STANDARD_RTTI( Engines_TMPFile_i );
+
+protected:
+  Engines::TMPFile_var myStream;
+};
+
+
+#endif
index fa73429a9d22e1fc0a70650fc1a0ee284cdfac02..3e87ff32dd69c4bee56bf475e4d05b1d10bb34eb 100644 (file)
@@ -55,6 +55,7 @@ EXPORT_HEADERS= \
        SALOMEDSImpl_StudyManager.hxx \
        SALOMEDSImpl_OCAFApplication.hxx \
        SALOMEDSImpl_ChildNodeIterator.hxx \
+       SALOMEDSImpl_TMPFile.hxx
 
 LIB_CLIENT_IDL =
 LIB_SERVER_IDL =
@@ -111,7 +112,8 @@ LIB_SRC =     SALOMEDSImpl_Tool.cxx \
                  SALOMEDSImpl_SComponentIterator.cxx \
                  SALOMEDSImpl_StudyBuilder.cxx \
                  SALOMEDSImpl_Study.cxx \
-                 SALOMEDSImpl_StudyManager.cxx
+                 SALOMEDSImpl_StudyManager.cxx \
+                  SALOMEDSImpl_TMPFile.cxx
 
 
 
index e3d53663a3eee5ca0d45a9218f2149767a63112b..4a59e0b7bf607af9527612ce044e435dc87067a9 100644 (file)
@@ -23,6 +23,7 @@
 #include <TCollection_AsciiString.hxx>
 #include <SALOMEDSImpl_SComponent.hxx>
 #include <SALOMEDSImpl_SObject.hxx>
+#include <SALOMEDSImpl_TMPFile.hxx>
 
 
 class SALOMEDSImpl_Driver
@@ -31,15 +32,15 @@ public:
 
   virtual TCollection_AsciiString GetIOR() = 0;
 
-  virtual unsigned char* Save(const Handle(SALOMEDSImpl_SComponent)& theComponent,
-                             const TCollection_AsciiString& theURL,
-                             long& theStreamLength,
-                             bool isMultiFile) = 0;
+  virtual Handle(SALOMEDSImpl_TMPFile) Save(const Handle(SALOMEDSImpl_SComponent)& theComponent,
+                                           const TCollection_AsciiString& theURL,
+                                           long& theStreamLength,
+                                           bool isMultiFile) = 0;
 
-  virtual unsigned char* SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent,
-                                  const TCollection_AsciiString& theURL,
-                                  long& theStreamLength,
-                                  bool isMultiFile) = 0;
+  virtual Handle(SALOMEDSImpl_TMPFile) SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent,
+                                                const TCollection_AsciiString& theURL,
+                                                long& theStreamLength,
+                                                bool isMultiFile) = 0;
   
   virtual bool Load(const Handle(SALOMEDSImpl_SComponent)& theComponent,
                    const unsigned char* theStream,
@@ -70,10 +71,10 @@ public:
 
   virtual bool CanCopy(const Handle(SALOMEDSImpl_SObject)& theObject) = 0;
 
-  virtual unsigned char* CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, 
-                                 int& theObjectID,
-                                 long& theStreamLength) = 0;
-
+  virtual Handle(SALOMEDSImpl_TMPFile) CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, 
+                                               int& theObjectID,
+                                               long& theStreamLength) = 0;
+  
   virtual bool CanPaste(const TCollection_AsciiString& theComponentName, int theObjectID) = 0;
 
   virtual TCollection_AsciiString PasteInto(const unsigned char* theStream,
@@ -81,10 +82,10 @@ public:
                                            int theObjectID,
                                            const Handle(SALOMEDSImpl_SObject)& theObject) = 0;
 
-  virtual unsigned char* DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, 
-                                    bool isPublished, 
-                                   bool& isValidScript,
-                                   long& theStreamLength) = 0;
+  virtual Handle(SALOMEDSImpl_TMPFile) DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, 
+                                                 bool isPublished, 
+                                                 bool& isValidScript,
+                                                 long& theStreamLength) = 0;
 };
 
 class SALOMEDSImpl_DriverFactory
index b3452db044d2ac1b670a243bff2e516fe9532312..00dd0b97832292da1e66d74e75c165bdf1647740 100644 (file)
@@ -1345,7 +1345,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath,
 
     bool isValidScript;
     long aStreamLength  = 0;
-    unsigned char* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
+    Handle(SALOMEDSImpl_TMPFile) aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
     if ( !isValidScript )
       isOk = false;
 
@@ -1379,11 +1379,9 @@ bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath,
     }
 
     //Output the Python script generated by the component in the newly created file.
-    fp2 << aStream;
+    fp2 << aStream->Data();
     fp2.close();
 
-    if (aStream != NULL) delete [] aStream;
-
     //Add to the main script a call to RebuildData of the generated by the component the Python script
     fp << "import " << aScriptName << endl;
     fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << endl;
index 728c277a4f4a2988f4b477c71e59b631f9241a50..099bae84ef714e25a756b5a63badb3f60a011714 100644 (file)
@@ -624,7 +624,7 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const TCollection_AsciiString& aUrl,
 
              if (Engine != NULL)
                {
-                 unsigned char* aStream;
+                 Handle(SALOMEDSImpl_TMPFile) aStream;
                  long length;
 
                   if (theASCII) aStream = Engine->SaveASCII(sco,
@@ -643,7 +643,7 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const TCollection_AsciiString& aUrl,
 
                    HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
                    hdf_dataset->CreateOnDisk();
-                   hdf_dataset->WriteOnDisk(aStream);  //Save the stream in the HDF file
+                   hdf_dataset->WriteOnDisk(aStream->Data());  //Save the stream in the HDF file
                    hdf_dataset->CloseOnDisk();
                  }
 
@@ -663,8 +663,6 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const TCollection_AsciiString& aUrl,
                  hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
                  // Creation of the persistance reference  attribute
                  Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
-
-                 if(aStream != NULL) delete [] aStream;
                }
            }
          hdf_sco_group->CloseOnDisk();
@@ -902,12 +900,11 @@ bool SALOMEDSImpl_StudyManager::CopyLabel(const Handle(SALOMEDSImpl_Study)& theS
       Handle(SALOMEDSImpl_SObject) aSO = theSourceStudy->FindObjectID(anEntry.ToCString());
       int anObjID;
       long aLen;
-      unsigned char* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
+      Handle(SALOMEDSImpl_TMPFile) aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
       TCollection_ExtendedString aResStr("");
       for(a = 0; a < aLen; a++) {
-       aResStr += TCollection_ExtendedString(ToExtCharacter((Standard_Character)aStream[a]));
+       aResStr += TCollection_ExtendedString(ToExtCharacter(Standard_Character(aStream->Get(a))));
       }
-      if(aStream != NULL) delete [] aStream;
       SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
       SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
       continue;
diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.cxx
new file mode 100644 (file)
index 0000000..64f677a
--- /dev/null
@@ -0,0 +1,40 @@
+// 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.
+//
+// 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/
+//
+//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
+//  File   : SALOMEDSImpl_SObject.cxx
+//  Author : Sergey RUIN
+//  Module : SALOME
+
+
+#include "SALOMEDSImpl_TMPFile.hxx"
+
+#include <Handle_Standard_Type.hxx>
+#include <Standard_Transient.hxx>
+
+
+IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_TMPFile, MMgt_TShared )
+IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_TMPFile, MMgt_TShared )
+
+SALOMEDSImpl_TMPFile::TOctet*
+SALOMEDSImpl_TMPFile
+::Data()
+{
+  return &Get(0);
+}
diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.hxx
new file mode 100644 (file)
index 0000000..6ecd798
--- /dev/null
@@ -0,0 +1,47 @@
+// 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.
+//
+// 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/
+//
+
+#ifndef __SALOMEDSIMPL_TMPFILE_H__
+#define __SALOMEDSIMPL_TMPFILE_H__
+
+//Handle definition
+#include <MMgt_TShared.hxx>
+#include <Handle_MMgt_TShared.hxx>
+#include <Standard_DefineHandle.hxx>
+
+
+DEFINE_STANDARD_HANDLE( SALOMEDSImpl_TMPFile, MMgt_TShared );
+
+
+struct SALOMEDSImpl_TMPFile : public MMgt_TShared
+{
+  typedef unsigned char TOctet;
+
+  virtual size_t Size() = 0;
+
+  virtual TOctet* Data();
+
+  virtual TOctet& Get(size_t) = 0;
+
+  DEFINE_STANDARD_RTTI( SALOMEDSImpl_TMPFile );
+};
+
+
+#endif