From: apo Date: Fri, 10 Feb 2006 08:12:55 +0000 (+0000) Subject: Fix for Bug GVIEW10647 X-Git-Tag: Tag_09032006~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17a2036a353c96297f0695753a3cd4519c2a621d;p=modules%2Fkernel.git Fix for Bug GVIEW10647 Crash saving the model (memory allocation optimized) --- diff --git a/src/SALOMEDS/Makefile.in b/src/SALOMEDS/Makefile.in index 96fb1ae2a..57c960664 100644 --- a/src/SALOMEDS/Makefile.in +++ b/src/SALOMEDS/Makefile.in @@ -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 diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index 2f4f085ca..d9995703f 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -20,6 +20,7 @@ #include "SALOMEDS_Driver_i.hxx" +#include #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; } //############################################################################################################### diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.hxx b/src/SALOMEDS/SALOMEDS_Driver_i.hxx index ae49cdba2..cf689687b 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.hxx @@ -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 index 000000000..363df92cc --- /dev/null +++ b/src/SALOMEDS/SALOMEDS_TMPFile_i.cxx @@ -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 +#include + +#include + + +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 index 000000000..124d08dbd --- /dev/null +++ b/src/SALOMEDS/SALOMEDS_TMPFile_i.hxx @@ -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 diff --git a/src/SALOMEDSImpl/Makefile.in b/src/SALOMEDSImpl/Makefile.in index fa73429a9..3e87ff32d 100644 --- a/src/SALOMEDSImpl/Makefile.in +++ b/src/SALOMEDSImpl/Makefile.in @@ -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 diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx index e3d53663a..4a59e0b7b 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx @@ -23,6 +23,7 @@ #include #include #include +#include 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 diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index b3452db04..00dd0b978 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -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; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index 728c277a4..099bae84e 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -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 index 000000000..64f677a01 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.cxx @@ -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 +#include + + +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 index 000000000..6ecd798b4 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_TMPFile.hxx @@ -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 +#include +#include + + +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